Sunday, August 2, 2009

Password problem in c langauge?

#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;string.h%26gt;


int main(void)


{


int i;


char pw[7],pass[]="helloa ";


for(i=0;i%26lt;6;i++)


{


pw[i]=getch();


printf("*");


}


pw[6]='/0';





if((strcmp(pw,pass))==0)


printf("yes");


else


printf("no");


return 0;


}





i am entering helloa as the password still it prints no instead of yes...


can somebody debug the program plzzzzzzzzzzzz.

Password problem in c langauge?
When debugging problems in programs, it's often a good idea to occasionally output the values of what you think may be wrong.





In this case, before your if((strcmp..., you could do:





printf("pw = %s.\npass = %s.\n", pw, pass);





When doing so, you should see that the two strings are not the same due to your additional space.
Reply:With the debugging steps, With the input not having a proper null character, you would have seen that there was a lot of garbage following the 6th byte of the string, which should have pointed you to the null byte problem.





Glad you got it working, and thanks for the best answer score. :) Report It

Reply:remove the extra space after character 'a' in "helloa "...
Reply:remove space at the end in "helloa "


for better understanding print the string pw[ ] and pass[ ]


before comparing then you come to know the mistake
Reply:there is a facility of pre-defined function called getpass() in conio.h, you can refer to that ,if not ,send e-mail to pavan.kumar10@yahoo.com


I typed this C code into Dev and how do i get it to run?

#include %26lt;stdio.h%26gt;





main()


{


int integer1, integer2, sum;





printf("Enter first interger\n");


scanf("%d", %26amp;integer1);


printf("Enter secong interger\n");


scanf("%d",%26amp;integer2);





sum = integer1 + integer2;





printf("Sum is %d\n", sum);





return 0;





}





thats the code ^





did i do something wrong





i saved it and went to compile and run and nothing pops up

I typed this C code into Dev and how do i get it to run?
Your code is right but since it runs so quick that you won't see it produces something helpful.. Right before you notice it prints something, it has already ended its task. Meaning, after it runs the program, it closes immediately. So to prevent it from closing immediately, use getch() function before the statement "return 0;" And don't forget to include the library "conio.h". This is where the function getch() is.. (^^,) If you need to ask for more, then visit my blog and just leave a comment at http://ronaldborla.blogsome.com/ or http://ronaldborla.wordpress.com/


Also http://ronaldborla.blogsome.com/2008/02/... for my biggest announcement in my blog... (^^,) Thanks!
Reply:Hi,


By reading the code nothing seems incorrect but one deficiency which is the solution of ur problem.


write getch(); before return 0; statement.





The programme runs but it does not give u time to see the output.


After writing getch(); it will wait for a key press then exit. then u can see output of ur programm.
Reply:Well, how did you run your program? Did you use command prompt or Run windows, the later may run so fast that you did not have chance to see it.

bouquet

Why does this C function not work every time?

//Function to allow user to read text at own speed before continuing


int CONTINUE (void) {


fflush(NULL);


char Cont[2]={0};


printf("\n\n\n(Press \'return\' to continue.)\n");


fgets(Cont, 2, stdin);


if (Cont[0] == '\n') {


printf("\n\n\n\n...");


return 0;


}








else {


printf("\nInput error.\nNext time enter \'return\'. On its own. Allow us to bitchslap you for your insolence!\n*You lost 100 HP.*\nOn with the game then...");


Main.HP=Main.HP-100;


return Main.HP;


}


}

Why does this C function not work every time?
I think the fflush needs to be done on stdin not NULL. In addition you might look at





http://www.kbalertz.com/kb_41159.aspx





it suggests using rewind(stdin).
Reply:sign into xpforum and you will get help there , it's like here q %26amp; a , they all seem to know about a p.c
Reply:ok try to clear Cont[0] = '_'; before the get


and verify if its stay at _ then tell me





good luck


I just want to ask whats the function of the "textattr" in C program.?

i am just curios what does the textattr used for?


thankz





case '2':


printf("\n\n Enter ID Number to browse: ");


gets(search);


for(s=0;s%26lt;10;s++)


{


if(!strcmp(search,whois[s].id_no))


{


printf("\n\n Entry %d:",s+1);


printf("\n Name : %s",whois[s].name);


textattr(14);


printf("\n ID No.: %s",whois[s].id_no);


textattr(15);


printf("\n Course: %s",whois[s].course);


printf("\n Year : %s",whois[s].year);


hits=hits++;


}

I just want to ask whats the function of the "textattr" in C program.?
textattr : stores currently selected text attributes.


The TextAttr variable controls the attributes with which characters are written to screen.


Help me please?! prime number in c++?

is it possible to write the same program wit same commands without flag and also please describe flag





#include %26lt;stdio.h%26gt;








int main(void){


int j,n,i,flag;


printf("Please enter a number : ");


scanf("%d",%26amp;n);


if(n%26lt;2) {


printf("\nNo prime numbers available");


return 1;}


printf("Thank you : 2");


for(i=2;i%26lt;=n;i++){


for(j=2;j%26lt;=i-1;j++){


if(i%j==0){


flag=0;


break;}


flag=1;


}


if(flag==1)


printf("%5d",i);


}





return 0;


}

Help me please?! prime number in c++?
u need atleast one flag variable. I have reduced ur code. wat i have given is very simple code.





please correct the syntax. but the logic is correct.





flag=1;





for(i=2;i%26lt;n-1;i++){


if(n%i==0){


flag=0;


break;


}


}


if(flag==1){


printf("prime");


}


else


printf("not a prime");








//Note:-


/*


n is the number for which it has to be checked for prime.


flag=1 (initially assuming that the given number is prime and reinitializing to 0 after checking the condition in if loop.


*/
Reply:Yes. Instead of for loops you should be using while loops. The flafg here is only used for breaking the loop. You will not need it if you use while loop.





i =2;


while(i%26lt;=n)


{


j=2;


while (j%26lt;=i-1)


{


if (I%j++ == 0)


{


break; // this will break the loop for j


}


}// end of while for j





if (j == i) printf("%d ",i);


i++;


} //end of while for i


}
Reply://try this


#include%26lt;stdio.h%26gt;


void main()


{


int n,i,flag;


flag=0;


printf("Enter the Number:\t\t");


scanf("%d",%26amp;n);


if(n%26lt;2)


printf("\n%d is not prime",n);


else


{


for(i=0;i%26lt;n/2;++i)


{


if(n%i)


flag=1;


}





if(flag)


printf("%d is not prime",n);


else


printf("%d is prime",n);


}


getch();


}


Microsoft visual c++?

Hi, I was assigned a project using Microsoft visual, and its my first time using it so I need some help. I was asked to write a program that converts kilometers to miles, while displaying it.


Heres what I have so far..I think its right, but when I try to run the program it exits right after i type in the Km value and hit enter, it doesnt show the results in miles.. anybody know why?





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;


int main()


{


/* Declare and initialize variables. */


double km, miles;


/* get the km and mi values from the keyboard*/


printf("Enter distance in kilometers:");


scanf("%lf",%26amp;km);


/* Compute Kilometers to Miles */


miles=km/1.6093340;


/*print Miles */


printf("Kilometers = %f \n", km);


printf("Miles = %f \n", miles);


}

Microsoft visual c++?
/* Declare and initialize variables. */


double km, miles;


here:


/* get the km and mi values from the keyboard*/


printf("Enter distance in kilometers:");


scanf("%lf",%26amp;km);


if km==0 THEN goto here


/* Compute Kilometers to Miles */


miles=km/1.6093340;


/*print Miles */


printf("Kilometers = %f \n", km);


printf("Miles = %f \n", miles);
Reply:#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;


int main()


{


/* Declare and initialize variables. */


double km, miles;


/* get the km and mi values from the keyboard*/


printf("Enter distance in kilometers:");


scanf("%lf",%26amp;km);


/* Compute Kilometers to Miles */


miles=km/1.6093340;


/*print Miles */


printf("Kilometers = %f \n", km);


printf("Miles = %f \n", miles);








/*pauses for user to press a button. reason is so that the program doesn't immediately end and still displays the results*/


getch();


}

yu gi oh cards

Formula in C?

// Hrricane_2.cpp : Defines the entry point for the console application.


//





#include "stdafx.h"


#include%26lt;cmath%26gt;








int main()


{int hlat, hlong, hspd; /*initialize vvariables for hurricane's */


int d; /*Assigns values*/


int FLLat = 26;


int FLLong = 80;


printf("Enter Hurricane's Latitude.\n");


scanf("%f",%26amp;hlat);


printf("Enter Hurricane's Longitude.\n");


scanf("%f",%26amp;hlong);


printf("Enter Huricane's speed.\n");


scanf("%f",%26amp;hspd);


d = sqrt((%d FLLat-%d hlat)*(%d FLLat-%d hlat) + (%d FLong-%d hlong)*(%d FLong-%d hlong));





return 0;


}





THE COMPILER DOES NOT LIKE THE d= LINE PLEASE HELP? HOW SHOULS IT BE WRITTEN

Formula in C?
There are so many errors in this program, I don't know where to begin. You need to go back and revise the basics of C. There are even errors that some compilers would miss.





1. When you use scanf with "%f", you must pass it a pointer to a variable of type float. Otherwise, it will still read in a floating point number but then generate instructions that interpret it as a value of type int.





2. If you want to do floating point calculations, you should generally stick to double precision. Don't even think of single precision--it's pretty useless.





3. Arithmetic expressions involve operators and operands. You seem to handle operators OK. Operands can be variables or numbers (there are other possibilities, but don't worry for now).


%d FFLat


is not a valid operand. What on earth are you thinking here?





4. The value you calculate for d is floating point. Why on earth are you assigning it to an integer?





5. You are calculating a value for d and then discarding it. Do you mean to print it out or what?
Reply:you should clear "%d"s from the line!


What will output of this c program and how???

#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


void main()


{


int i,k;


for(i=0;i%26lt;10;i++) {


switch(i % 5)


{ case 0: k=0;


case 1:k++;


printf("k1=%d\n",k);


case 2:k+=2;


printf("\nk2=%d\t\t",k);


case 3:k+=3;


printf("\nk3=%d\t\t");


case 4:k+=4;


default :k+=10;





}


}


printf("%d",k);


}

What will output of this c program and how???
output is


k1=1 %26lt;-- i = 0





k2=3 %26lt;-- this get output cause of no break statement


k3=6(tab)(tab)k1=21 %26lt;-- i =1





k2=23


k3=26(tab)(tab) %26lt;-- i = 2


k2=42


k3=45


k3=62(tab)(tab) %26lt;-- i = 3


k1=1 %26lt;-- i = 5





k2=3


k3=6(tab)(tab)k1=21 %26lt;-- i =6





k2=23


k3=26(tab)(tab) %26lt;-- i = 7


k2=42


k3=45


k3=62(tab)(tab)90 %26lt;-- i = 8


If you added break statements before the next case statement or default: statement, you will get different result.


and less confusing output.
Reply:Are you sure guys? O_o I think that's a modulo operation over there at switch(i % 5) statement, not a division..





My guess is this:


At the first loop it will encounter the "case 0" statement and set the "k" value to 0. But since there is no break in the statement, it will "roll over" to the each of the continuing statements. In the end, it will also satisfy the "default" statement, causing the value of "k" to be incremented to 10.





Second loop, it would satisfy the statement "case1" and print out "k1=11". But at the end it would be incremented yet again by 10 (to 21).





Third loop, "case 2", print out "k2=23", k=33 at the end.





Fourth loop, "case 3", print out "k3=36", k=46 at the end.





Fifth loop, "case 4", k=50, k=60 at the end.





Sixth loop, back to "case 1"... And so on until the tenth loop is the same with the fifth loop.





So, at the end it would print out 60. As the previous answerer had pointed out, you might want to include a "break" at every end of the "case" statement. In addition, there is some confusion at your output formatting, making the print out rather ugly.





In summary, the program would output:


k1=11





k2=23


k3=36 k1=11





k2=23


k3=36 60





==============


EDIT: Four people with four different answers, I bet you're confused right now which one is the right one. ;) So I decide to run the code through the compiler and found out that the right dude is Dasher Dude. Congrats dude, you're a dasher. ^_^





Ok, enough with wordplays. =p There is just one small mistake from the code that I just realized after reading the compiler's output:


printf("\nk3=%d\t\t"); is supposed to be printf("\nk3=%d\t\t", k); right?
Reply:The output will be


k1=1


k1=2


k1=3


k1=4


k1=5


k=5





Because first 4 values of i are less than 5 so answer of division will be 0 which will go to case 0. It is not having print statement


After this for numbers (i=5 to 9) the division will be 1, hence causes to execute case statement 1.which print 'k' value.


everytime value of k is incremented at every iteration.





But there must have "Break;" statement at end of every case.
Reply:k1=1





k2=3(tab)(tab) /*these tab characters will be invisible*/


k3=6(tab)(tab)14


/*k4 will not be printed*/





/* and you forgot to put the "break" statement, as the previous answerer said*/


Explain the output of the c prog?

main()


{


int i=257;


float a=3.14;


char *ii,*aa;


ii=(char*)%26amp;i; //what (char*) is doing here


aa=(char*)%26amp;a;


printf("address in ii=%u",ii);


printf("address in aa=%u",aa);


printf("vallue of i=%d",*ii);


printf("vallue of a=%f",*aa);


}

Explain the output of the c prog?
What is (char*) doing there? Simple! It converts int to char for ii and float to char for aa. The compiler doesn't automatically convert int to char or float! (because int is larger then char, and by converting it you loose data, same for float..).


And now refering to the output... It depends on what system this source is compiled, and nevertheless on the compiler you are using! The problem consists in converting an int to a char, and it depends on the compiler how many bytes are allocated when declaring an int! (same for converting float to char)
Reply:(char*) will convert integer variable into character. So value assigned to ii and aa will be behaved as a character variable for rest of the programme.


Please help! I write the C program and try to run ,but how can i keep the program display on the monitor?

/*this is my code, please someone help me to keep this program display on window.*/





#include %26lt;stdio.h%26gt;


#define MAX_SIZE 10














int main ()


{





int i, ary[10];


/*int* pWalk;


int* pEnd; */





/*for (i = 0; i %26lt; 10; i++)*/





printf ("Enter your numbers: \n");


for ( i = 0; i %26lt; 10; i++)


scanf( "%d", %26amp;ary[i]);





printf ("Your reversed numbers are: \n");


for ( i = 10 -1; i %26gt;=0; i--)


{





printf ("%d\n ", %26amp;ary[i]);


if ( i %26lt; 9)


i++;


else


{


printf("\n");


i = 0;


}


}


return 0;





}

Please help! I write the C program and try to run ,but how can i keep the program display on the monitor?
If you are using Visual C++, you click "Start Without Debugging" like this:





http://xoax.net/comp/cpp/console/Lesson1...
Reply:I way I solved that problem is to wait for a user input:





This is C++ code. You can figure out how to do it in C:





cout%26lt;%26lt; " Press any key and %26lt;enter%26gt; to quit: ";


char key;


cin%26gt;%26gt; key;





So, you end up waiting for user input.

thank you cards

Microsoft visual c++?

whenever I type in a code and debug it, as soon as I hit enter the black screen disappears instantly, without me seeing the final solution. for example:





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;


int main()


{


/* Part A) Declare and initialize variables. */


double b, h, area;


/* get the height and base values from the keyboard*/


printf("Enter the base length of the triangle :");


scanf("%lf",%26amp;b);


printf("Enter the height of the triangle :");


scanf("%lf",%26amp;h);


/*calculate the area of the triangle */


area = .5*b*h;


printf("Area = %lf \n", area);


}





when i type in the values, the screen disappears, is there anyway I can keep the black screen up until I want to close it, instead of it closing automatically?

Microsoft visual c++?
quick answer, add a line at the end of the program asking for input. Such as:





cin%26gt; x;





This will force the screen to stay open until it receices a response from you.





-Greg
Reply:the way i do it for my console based programs is to use system("PAUSE");





so in your code it will be:


#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;


#include %26lt;math.h%26gt;


int main()


{


/* Part A) Declare and initialize variables. */


double b, h, area;


/* get the height and base values from the keyboard*/


printf("Enter the base length of the triangle :");


scanf("%lf",%26amp;b);


printf("Enter the height of the triangle :");


scanf("%lf",%26amp;h);


/*calculate the area of the triangle */


area = .5*b*h;


printf("Area = %lf \n", area);





system("PAUSE"); //creates a system pause


}





What this does is output the "Press any key to continue" prompt (to which you press enter to continue). You don't need to include anything (although why not put "using namespace std;" after your #include directives?).





NOTE: This command ("system("PAUSE")") will make your console proggy only work on Windows machines!
Reply:You say you are trying to debug it, but are you using the debugger?





Instead of running the program, select Debug-%26gt;Start Debug (or you can just push F5).





Once your application starts, click in the left margin to set a breakpoint. When your code execution gets to the breakpoint, the code will stop executing, and you can examine all of your variables.





You will see that your application works, it is just completing before you can see the results. Therefore, you probably want to do what Greg et al recommend about adding another scanf().





Sorry if this sounds overly simple. I'm not meaning to be condescending, especially if you already ran through the debugger. The problem is that most students never learn to use the debugger and only use printf statements. I've just spent an awful lot of time retraining young programmers to use debuggers and other productivity tools. The sooner you learn, the easier it will be for you.
Reply:You should make the project type as Cmd line type project. Then you can run it from command line and see the output.
Reply:I dumped Windoze a long time ago but I seem to remember that system("pause"); works. System is a--cstlib I believe -- routine which calls an outside program. Pause is an MS-DOS program which prints "Press Any Key" on the screen and waits till you do to exit.


What is missing from this c program. please help me.... thanks?

The simple interest on a loan is calculated by the formula


interest = principal * rate * days / 365;


The preceding formula assumes that rate is the annual interest rate, and therefore includes the division by 365 (days). Develop a program that will input principal, rate and days for several loans, and will calculate and display the simple interest for each loan, using the preceding formula.








#include%26lt;iostream.h%26gt;


#include %26lt;stdio.h%26gt;


int main(void)





{


int principal, rate, days, interest;


printf("enter principal\n");


scanf("%d", %26amp;principal);


printf(" enter rate\n");


scanf("%d", %26amp;rate);


printf(" enter days ");


scanf("%d", days);


interest = principal * rate * days / 365;


printf(" the interest is %d");





system("pause");


return 0;





}

What is missing from this c program. please help me.... thanks?
No %26amp; in front of days in scanf





interest should probably not be integer in real life because of div by 365.
Reply:The corrected version.





#include %26lt;stdio.h%26gt;


int main(void)


{


double principal, rate, interest;


int days;


printf("enter principal $");


scanf("%lf", %26amp;principal);


printf(" enter rate :");


scanf("%lf", %26amp;rate);


printf(" enter days ");


scanf("%d", %26amp;days);


interest = principal * rate * days / 365.0;


printf(" the interest is %f", interest);


printf("Press Enter%26gt;");


fflush(stdin);


getchar();


return 0;


}


Explain the output of the c prog?

main()


{


int i=257;


float a=3.14;


char *ii,*aa;


ii=(char*)%26amp;i; //what (char*) is doing here


aa=(char*)%26amp;a;


printf("address in ii=%u",ii);


printf("address in aa=%u",aa);


printf("vallue of i=%d",*ii);


printf("vallue of a=%f",*aa);


}

Explain the output of the c prog?
ii is a pointer to a character and the line


ii=(char*)%26amp;i;


is pointing that pointer to the address of the integer in i. i is probably a 4 byte quantitiy (but could be 2 bytes depending on the platform). the (char*) is converting the pointer to an integer %26amp;i (read as address of i) into a pointer to a character. This is called casting as you are converting from an integer pointer type to a character pointer type. This helps the compiler decide how to proceed and make your code 'more' readable. This type of conversion is one of the strong and weak points of c programming. On one hand you may have good reason to treat the integer as characters or bytes, but on the other, the code becomes confusing and it is easy to step on your foot as you might cast what you think is an int into a float pointer and things start to quickly unravel.





aa=(char*)%26amp;a;


is very similar except you are pointing the character pointer as to the address of the floating point number a.





The next several lines print out the various combinations.





printf("address in ii=%u",ii);


This will print the actual address ii points to. It will not have much meaning beyond a possible debug session when everything is behaving strangly because your pointers seem to be causing problems.





printf("address in aa=%u",aa);


This will print the actual address aa points to.





printf("vallue of i=%d",*ii);


This prints out the value at the memory location that ii points to. The * dereferences the pointer and returns the pointers location. This could be different on different platforms.





printf("vallue of a=%f",*aa);


This prints out the value at the memory location that aa points to.
Reply:Hi!





First this is the main() function. Each program in C is required to declare and implement a main() function. When this program runs, it will run whatever is in the main() function first, which is why it is necessary to have one.





The first line says "int i=257;". This is declaring a variable. In C, variables are places in the computers memory that can hold values. Here we are declaring a variable named "i" that has a type of int. "int" stands for integer, and means any whole number, from approximately -32765 to 32767. Then we assign the value of 257 to the variable i. Later, we can refer to i to see what value it has.





The next line declares another variable, a float named "a" with a value of 3.14. The type "float" means floating point number, a number that is rational and not a whole number. This is why we can assign the value 3.14 to a float but not to an int.





Then we declare two more variables. You can define multiple variables of the same type by separating them with commas, like is done on this line. These variables are special, however, as they have an asterisk (*) preceding them. This means they are pointers. Pointers are a complex topic, but basically they are variables that point to another variable. These variables "ii" and "aa" have the type char, which is a character (any alpha-number character, 0-9, a-z, A-Z, etc.) but since they are pointer they won't hold a value, they will just point to another variable that has a value.





Then it assigns a value to ii. It assigns the %26amp;i, this means the address of i. The %26amp; means "address of". Every variable in C programming has a value, but it also has an address - a place in memory where it can store it's value. The %26amp; sign just says "tell me the place this variable has in memory". So ii, being a pointer, is now assigned the address of i. So ii now points to i. This is the main function of a pointer. As I said, this can be very confusing at first. The (char *) part is called a typecast. The address of a variable (%26amp;i) is not any defined type, it is just a location in memory. Since ii was defined as a char * (character pointer), you must typecast it to tell the computer that you want the location to be the right type that ii can store.





The next line is the same as the previous, just with aa and a. So now aa points to a.





Now we have a series of printf() statements. printf stands for print formatted. This is used for displaying text and variable's values to the screen. printf first takes a string of text and formatting characters, then a list of variables to output. In the first printf, it has the string "address in ii=%u". This is the string it will print to the screen, however, %u is a formatting symbol. The % sign tells the computer that you want to show the value of a variable and the u means that the variable is an unsigned type (unsigned means positive number). The next part of the printf statement has ii, so the %u will be replaced by the value of ii. This will effectively print the value of ii, which is the location of i in memory. (Which we defined earlier)





The next printf statement is the exact same, just a different variable.





The last two printf statements print the value of i and a respectively, however you will notice different formatting symbols. %d means decimal (a whole number) and %f means float (a floating point number). The only other difference here is that instead of just giving the variable ii, the variable is preceded by an asterisk (*). Without it, "ii" would give the address of the variable ii is pointing to, since it is a pointer. The asterisk says, "don't tell me the address ii is pointing to, tell me the value AT that address". Since ii points to i, instead of showing the address of i, it will print the value of i.





I hope this explanation sheds some light on the program's output and how it works. The output will not be the same on every computer because the address of variables in memory changes based on many things. However, the value of i will be shown as 257 and the value of a will be 3.14.





Pointers are a complex concept to grasp in C and many people struggle with it at first. If you would like some more tutorials to explain any of the concepts in C programming you can find some at www.cprogramming.com.


Question in C programming answer fast please i will give points?

#include %26lt;stdio.h%26gt;





#include "genlib.h"





#include "simpio.h"





main(){





int num1, num2, temp;





printf (“Enter a positive integer: \n”);





num1=GetInteger();





printf (“Enter a positive integer: \n”);





num2=GetInteger();





while (TRUE){





temp=num1%num2;





if (temp==0) break;





num1=num2;





num2=temp;





}





printf (“The result is: %d “, num2);





}





1. What does the program do ?


2. What will the output be ? (if the user enters the following input: 120 for num1 and 24 for num2).


3. How many cycles will be executed for this input ?

Question in C programming answer fast please i will give points?
1.This program finds the GCD (greatest common divisor)


2. 24 is the result for the provided params (120, 24). Notice that 24 divides 120 and 24.


3. I don't know, it depends on the numbers, but they are O(num1)
Reply:did your teacher give you this program. it doesn't show what


GetInteger() does????





The program reads two numbers in. Then finds the remainder into Temp and checks if this is 0 if it is 0 then it breaks and quits the program.





Then it just takes Num2 and puts it into num1 (so you loose 120)


then puts temp into num2 which I'm guessing is 0.


cycles? one
Reply:It calculates the remainders of the division num1/num2. If there are no remainders it prints number 2. If there are remainders, it will set num1 equal to num2, then num2 equal to the amount of remainders then start to process all over again until there are no remainders left.





Run it.





As many as it takes until there are no remainders.
Reply:1. It is impossible to say without the definition of GetInteger() and the contents of genlib.h and simpio.h. On the surface it doesn't appear to do anything useful.





2. If you enter 120 and 24 the output is 24.





3. If by "cycles" you mean times through the loop, the answer is either 0 or 1 depending on how you count. If by "cycles" you mean "machine cycles" the answer depends on too many factors to be described here.





In short it's a bad question.
Reply:1. it devides the positive integers


2. the output will be 5.


3. 4 cycle will be exicuted

potential breakup song

What is this Variable, in C programming?

I'm leaning how to calculate a triangular number and using the "for" statement to do so. Now heres the program:





/* program to generate a table of triangular numbers */





main ()


{


Int n, triangular_number;





Printf ("TABLE OF TRIANGULAR NUMBERS\n\n");


Printf (" n sum from 1 to n\n");


Printf ("--- ---------------\n");





triangular_number = 0;





for ( n = 1; n %26lt;= 10 ++n );


{


triangular_number = triangular_numbers _ n;


Printf (" %d %d\n, n, triangular_number);


}


}





My problem is that I don't exactly know what the variable "n" stands for, in the FOR statement. Can anyone just explain to me what it is, and does?? Thanks a lot.

What is this Variable, in C programming?
A for loop is C's implementation of a so-called "counting loop". The loop is controlled by three semi-colon (;) delimited sections, defined as followed:





-------------


for ( initial_counter ; continue_condition ; counter_increment )


{


loop_statements;


}


-------------





The initial_counter is an assignment statement that initializes the counter for the first iteration of the loop.





The continue_condition is a boolean (true/false) condition (ideally based on the counter) that determines if the loop will continue.





The counter_increment is an assignment or auto-increment expression that changes the value of the counter at the end of a loop iteration.





So the following for loop:


-------------


for ( n = 1 ; n %26lt;= 10 ; ++n )


{


triangular_number = triangular_numbers + n;


printf (" %d %d\n, n, triangular_number);


}


-------------


is a loop that has n assigned to 1 before the first iteration.





At the start of each iteration the loop checks to see if n is less than or equal to 10; if so then the loop continues iterating; if not it ends (control goes to the next statement after the loop). After a successful check, the loop runs the actual iteration, the two statements in the body of the loop. At the end of each iteration, the loop increments the value of n (++n) and goes back to the top of the loop (start of this paragraph).





You can think of this for loop as being equivalent to the following while loop:





-------------


n = 1;


while ( n %26lt;= 10 )


{


/* for loop iteration statements */


triangular_number = triangular_numbers + n;


printf (" %d %d\n, n, triangular_number);


/* end of for loop iteration statements */





++n;


}


-------------
Reply:n is just an incremetor which starts at 1 and will increment to 10. Your code is a bit off and should be the following





for ( n = 1; n %26lt;= 10; n++ )


{


triangular_number = triangular_number + n;


Printf (" %d %d\n, n, triangular_number);


}
Reply:n is nothing but just a default value 1 from where ur loop must begin...........
Reply:It's the counter for the loop. Every time the program goes through the loop n will increment by 1. The loop program will continue to loop until n%26lt;=10, the it will jump out of the loop.





Hope this helps.
Reply:in for loop - "n" is a variable, as the name indicates it "varies" throught the program- means the value it holds changes.





using can use anyalphabet in place of "n" and assign values to it.





like for(a=1; a%26lt;=10; a++)





a=1 is assignment


a%26lt;=10 comparison


a++ means a=a+1 incrementing by 1
Reply:n is the loop variable that makes the loop run 10 times.





It appears that you have the wrong character between the triangular_numbers variable and n inside the for loop, since the underscore character is not an operator.





Check the link below for the definition of the triangular number, and you should be able to figure out what character goes in its place (which is the real reason you asked this homework question, right?)


How to declare and use 2d dynamic array in c language?

/*code functions in static case but got to use dynamic array*/


#include%26lt;stdio.h%26gt;


#include%26lt;math.h%26gt;


#include%26lt;conio.h%26gt;


void main(int argc, char *argv[])





{


FILE *fp;


int i,j=0;


float n,x1,y1,x2,y2,cross,result,area=0,p[5][5...


clrscr();


fp=fopen(argv[1],"r");


if(fp==NULL)


{


printf("Cannot open file");


exit(0);


}








while(!feof(fp)) {


/* fread(%26amp;p[j][0],sizeof(p[j][0]),1,fp); */





fscanf(fp, "%f %f", %26amp;p[j][0],%26amp;p[j][1]);


printf("%f\n,%f\n",p[j][0],p[j][1]);


j++;





}





j=j-1;


for( i = 1; i+1%26lt;=j; i++)


{


x1 = p[i][0] - p[0][0];


y1 = p[i][1] - p[0][1];


x2 = p[i+1][0] - p[0][0];


y2 = p[i+1][1] - p[0][1];


printf("x1 is %f\ny1 is %f\nx2 is %f\ny2 is %f\n",x1,y1,x2,y2);


cross = x1*y2 - x2*y1;


printf("cross is %f\n",cross);


area += cross;





}


result = fabs(area/2.0);





printf("The area is %f",result);





}

How to declare and use 2d dynamic array in c language?
You do not actually declare a two dimentional dynamic array in C.


What you do is declare some storage. You reference this storage using a 1 dimention array, but you control the subscript in such a way that it acts like a 2, 3 etc. dimension array.





A little bit mind blowing but if you check out the three links you should be able to get it to work.
Reply:Hey mind one simple thing array means static only you cannot declare it dynamic okay


In basic c programming, what does " 1%13d\n" mean???

Ok so the notes online has an example where it says





/*display results in tabular format*/


printf(" 1%13d\n" , "Face", "Frequency");


printf(" 1%13d\n" , "Frequency");


printf(" .....





I know that it should be in a table and that face and frequency are like the categories for the table but what does the thing in the quotes mean???





I know \n is space %s and is the character string but what about the rest???

In basic c programming, what does " 1%13d\n" mean???
it will print some garbage


as face is a string not an integer
Reply:1%13d,


the number before d means that the width of that given number, and also you miss the control string for the remaining two strings that you have passed. So It wont display. another mistake you give only d and give string for that d, so it will display starting address of that string.
Reply:1) \n is actually a line feed, not a space.


2) printf() takes a format string and a variable number of arguments whose values get swapped into the format string when printf() is executed. In other words, sequences in the format string like "%s" and "%d" are swapped with the values of variables. %d means that the variable that's going to get swapped in is a numeric type. %13d specifies some formatting about how the number should look when printed (in this case it should always be 13 characters long with padding added if necessary). Format strings can vary somewhat depending on the libc implementation, so your best bet to getting a full description of how they work is to hit up the documentation that came with your compiler.
Reply:the first printf() has too many arguments. The second should print a '1' followed by the integer representation of the pointer to the string "Frequency".
Reply:Are you sure you reproduced the code correctly? Even if this compiles it is a string printed as number and I am sure some strange garbage output will happen.





\n is newline; not space, there is a world difference between the two in programming. %d is number, integer if I remember right although I used %i, usually a format code can occur between % and d (or s i f whatever other codified character) in this case 13 within %d dictates to have the number output formatted within 13 digits, or padded with spaces to form 13 cells for output.
Reply:" 1 %13d \n"





The first three characters ( space, one, space) would print as they are. Then the %13d says to print an integer with a width of 13 spaces.





The first printf is invalid in that two variables are passed but only one is expected.


Can you translate this C code into english?I have problems on understanding it?

#include %26lt;stdio.h%26gt;


#include %26lt;math.h%26gt;


/*------------------------------------...


/* DEFINITIONS DES FONCTIONS UTILISÉES LORS DU PROGRAMME */


/*------------------------------------...


/*------------------------------------...


/* Fonction saisie : saisie d'un nombre flottant */


/* parametres : var une chaine de caractères */


/* Resultat : x un flottant */


/* Effet de bord : demande une entree a l'utilisateur*/


/*------------------------------------...


float saisie (char var[])


{


float x;


printf ("Entrez la valeur de %s : ",var);


scanf ("%f",%26amp;x);


return x;


}


/*------------------------------------...


/* Fonction sinus : calcul du sinus d'un */


/* flottant x a epsilon pres */


/* parametres : x un flottant, epsilon */


/* un flottant representant une précision donnee */


/* Resultat : y un flottant tel que y */


/* = x - x^3/3! + x^5/5! - x^7/7! + */


/* Effet de bord : affichage de : Le nombre */


/* de terme calcule est : ? */


/*------------------------------------...


float sinus (float x, float epsilon)


{


float sinusx; /* variable contenant le n ième terme de la serie */


float somme=0; /* contient la valeur du sinus calculé */


double exposant=x; /* contient la valeur de x^(2*nbterme-1) du n ième terme */


int nbterme=0,i; /* compteur */


double factoriel=1; /* contient la factoriel du n ièeme terme */


do


{


nbterme++;


if (nbterme==1);


else


{


exposant=x;


factoriel=1;


/* calcul du x exposant (2*nbterme-1) du n ième terme */


for (i=1;i%26lt;(2*nbterme-1);i++)


{exposant = exposant*x;}


/* calcul de la factoriel du n ième terme */


for (i=(2*nbterme-1);i%26gt;1;i--)


{factoriel = factoriel*i;}


}


/* affecter le n ième terme pair de la série par moins pour alterner la série */


if (nbterme%2==0)


{exposant = -exposant;}


sinusx = exposant/factoriel;


somme += sinusx;


}


while (((sinusx%26lt;0) ? -sinusx : sinusx) %26gt; epsilon);


printf("\n\nLe nombre de terme calcule est : %d\n",nbterme);


return somme;


}


/*------------------------------------...


/* Fonction affiche : affiche le resultat y = sin(x) */


/* parametres : x un flottant, y un */


/* flottant et epsilon un flottant */


/* Résultat : aucun */


/* Effet de bord : affichage de: Le sinus de */


/* x est y a epsilon pres. */


/*------------------------------------...


void affiche (float x, float y, float epsilon)


{


printf("Le sinus de x = %f est %f avec une precision de %f.\n",x,y,epsilon);


}


/*------------------------------------...


/* Fonction affichemath: affichage et calcul */


/* de la valeur de sin d'un flottant x en utilisant la */


/* fonction sin de la librairie math.h */


/* parametres : x, un flottant */


/* Resultat : aucun */


/* Effet de bord : affichage de Avec la */


/* fonction sin de math.h, on a sin(x) = ?.??????. */


/*------------------------------------...


void affichemath (float x)


{


printf("Le sinus de x par la fonction sin de math.h est %f\n",sin(x));


}


/*------------------------------------...


/* LE PROGRAMME PRINCIPALE */


/*------------------------------------...


int main (void)


{


float x, precision, solution;





/* lire x */


x = saisie("x");


/* lire precision */


precision = saisie("precision");


/* calcul de sinus x */


solution = sinus (x, precision);


/* affchage des resultats */


affiche (x, solution, precision);


affichemath (x);


return 0;


}

Can you translate this C code into english?I have problems on understanding it?
What do you want us to tranlate? The C code or the French comments? The comments in French just explain the code below them, how thet build the functions. They specify the name of the function, what it does, the parameters and their datatypes....


Flottant = floating point


Sinus = sine


Effect du bord = side effect


Saisie = take
Reply:go to where you found it and see if there is an english version---i SPEAK FRENCH BUT NOT COMPUTER GIBBERISH.

love song

Turbo C help?

This program is not running , there is an error:





/* gmtime example */


#include %26lt;stdio.h%26gt;


#include %26lt;time.h%26gt;





#define MST (-7)


#define UTC (0)


#define CCT (+8)





int main ()


{


time_t rawtime;


tm * ptm;





time ( %26amp;rawtime );





ptm = gmtime ( %26amp;rawtime );





puts ("Current time around the World:");


printf ("Phoenix, AZ (U.S.) : %2d:%02d\n", (ptm-%26gt;tm_hour+MST)%24, ptm-%26gt;tm_min);


printf ("Reykjavik (Iceland) : %2d:%02d\n", (ptm-%26gt;tm_hour+UTC)%24, ptm-%26gt;tm_min);


printf ("Beijing (China) : %2d:%02d\n", (ptm-%26gt;tm_hour+CCT)%24, ptm-%26gt;tm_min);





return 0;


}





it says undefined symbol 'tm'


and undefined symbol 'ptm'

Turbo C help?
just use time_t or time in place of tm in second line in main function
Reply:You need to declare the variables in your program inside the main() function.


Factorial Program using c++?

Need a program using loop (not if and else)





Need this badly...





Option ! (Factorial)


1. Prompt the user to enter an integer


2. Accept the integer value n


3. Let the integer value a = 1


4. Let a = a * n


5. Let n = n - 1


6. Repeat 4 - 5 while n %26gt; 0


7 display a





I am really not that good in programming so please help with the formula and conditions for the code....please include scanf and printf...

Factorial Program using c++?
void main()


{


int n,a,fact=1 ;





printf("Enter the value of number ");


scanf("%d",%26amp;n);





while(n!=0)


{


fact=fact*n;


n=n-1;


}


printf("Factorial of %d is %d",n,fact);


getch();


}








use cout and cin in place of printf and scanf ,,,,,,,if u want then i can also do that
Reply:The description is recursive; if/else is implied, what are you asking? How to use :? or while loop or what?
Reply:try this one:





http://www.cprogramming.com/


Please check my code - something is wrong - C programming?

I have spent a good 6 hours on this , yet it still doesn't work properly. When I compile it keeps spitting out 0 for both shutter and exposure values, plus it always gives me incorrect value for shutter speed. Please help !


[code]


#include %26lt;stdio.h%26gt;


int main(void)


{


int exposure=0;


float aperture=0;


int choice = 0;





printf("\nEnter Exposure Time: ");


scanf("%f",%26amp;exposure);





printf("The selected Exposure time is %f\n", exposure);





{


while (choice%26lt;1)


{


printf ("Please enter the aperture size ");


scanf("%d",%26amp;aperture);





if ((aperture==1.2) ||(aperture==1.4) ||(aperture==1.8) ||(aperture==2.0) ||(aperture==2.8) ||(aperture==2.8) ||(aperture==4.0) ||(aperture==5.6) ||





(aperture==8.0) ||(aperture==11)||(aperture==16)||(apert...


{


printf("You have entered a correct value ");


choice=2;


}


else


{


printf("Invalid aperture=%d\nPlease Try Again\n", aperture);


choice=1;


}


}


}


}


[/code]

Please check my code - something is wrong - C programming?
scanf("%f",%26amp;exposure) should use "%d" because you are dealing with an integer.





printf("The selected Exposure time is %f\n", exposure) should also use "%d" because exposure is an int.





printf("Invalid aperture=%d\nPlease Try Again\n", aperture) should be printf("Invalid aperture=%f\nPlease Try Again\n", aperture) because you are printing a float.





Also, when I ran your program and inspected the values of aperture (I entered 1.4 for example), the debugger showed me that aperture was actually 1.40000. That's why you aren't getting a match. You should either truncate the values or do something like aperture %26gt;=1.4 %26amp;%26amp; aperture %26lt;=1.5.





Using floating precision numbers in tests of equality makes things very difficult. Maybe you could make aperture an int and multiple your decimal values by 10.





For example, you are looking for 1.4 or 1.8. Accept 14 or 18 instead, then divide the result by 10 into a float to use in your actual calculations.





Example:





/*aperture is an int, not a float*/


scanf("%d",%26amp;aperture);





if ((aperture==12) ||(aperture==14) ||(aperture==18) ||(aperture==20) ||(aperture==28) ||(aperture==28) ||(aperture==40) ||(aperture==56) ||





(aperture==80) )


{


printf("You have entered a correct value ");


choice=2;





float ap=(float)aperture/10.0;





/*do calculations with ap*/


}
Reply:Erm.. I'm a noob at programming but this line





scanf("%f",%26amp;exposure);





doesn't look right to me. Your exposure variable is declared as an integer but the format descriptor %f is for a floating number. =\
Reply:YOU HAVE DECLARED EXPOSURE OF INT TYPE AND ACCEPTING THE VALUE AS %F AS FLOAT IN SCAN F





AND





YOU HAVE DECLARED APERTURE OF FLOAT TYPE AND ACCEPTING THE VALUE AS %D AS INT IN SCAN F


One c ques. is here?

if(r=5!=4)


printf("inside");


else


printf("outside");


printf("%d",r);





pls give the output, there is no error in progm, pls explain it also.

One c ques. is here?
"Overconfidence sinks empires"





There *are* mistakes.....


( r=5!=4) does not make any sense.For comparing two quantities we use ==


= is assignment operator.


and what do u wanna do?


if you want to print "inside" when r==4 then write this-


if(r==4)


------


-----





Better places to post such questions:


http://www.dev-spot.com/forums/


http://www.cprogramming.com/board.html
Reply:in a nutshell





if r = 5 print("inside") else if r = 4 print("outside"), etc.

garden flowers

Can anyone of you run and check my c program need to know whats the error?

my program should open a file with a bunch of words and see if its palindrome or not.


example


ada palindrome


back not palindrome


#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;


int main(int argc, char* argv[])


{


FILE *myfileptr;


char * fgets ( char * sc, int num, FILE * words );


char buffer[BUFSIZ];


const char* sc = argv[1];





myfileptr=fopen("words","r");





// gets() should be fgets. Please read the link posted for the function


while(fgets( buffer, sizeof buffer, myfileptr)) {


if(sc)


printf("%s",sc);


printf("EOF\n");


if(strlen(sc)%2==0) printf("Word not palindrom");


else


{


int i;


for(i = 0; i %26lt; strlen(sc); i += 1)


if(sc[i] != sc[strlen(sc) - 1 - i])


{


printf("Word not palindrom");


break;


}





if(i==strlen(sc)) printf("The word is palindrom");


}


}


}


i keep getting


EOF


Bus error

Can anyone of you run and check my c program need to know whats the error?
well...It compiles perfectly here on my window pc.. but when i try to run it. it dose nothing but crash similarly to mines..hum...strange try running this program





#include %26lt;stdio.h%26gt;


#include %26lt;string.h%26gt;


#define EOS '\0'


int main(int argc, char* argv[])


{


FILE *myfileptr;


char * fgets ( char * sc, int num, FILE * words );


char buffer[BUFSIZ];


const char* sc = argv[1];





myfileptr=fopen("words","r");





// gets() should be fgets. Please read the link posted for the function


while(fgets( buffer, sizeof buffer, myfileptr))


{


if(sc)


printf("%s",sc);


printf("EOS\n");


if(strlen(sc)%2==0) printf("Word not palindrom");


else


{


int i;


for(i = 0; i %26lt; strlen(sc); i += 1)


if(sc[i] != sc[strlen(sc) - 1 - i])


{


printf("Word not palindrom");


break;


}





if(i==strlen(sc)) printf("The word is palindrom");


}


}


}





that should do it...good luck bro!!


Whats wrong with this C++ program?

#include %26lt;stdio.h%26gt;





int main()


{


char start, end, dummy;


int cnt, line;





printf("Enter Start Character");


start = getchar();


dummy = getchar();





printf("Enter End Character");


end = getchar();





for(line = 0;cnt = start; cnt%26lt;=end; cnt++; line++);


{


printf("%3d%3x%2c", cnt, cnt, cnt);


if(line%3==0 line!=0)%26amp;%26amp;


{printf("\n")


}





return 0;


}














this is just the start but it says i have errors on line 15 and 18 and i dont know what they are...








a little help would be greatly appreciated.

Whats wrong with this C++ program?
List of problems:





Your for statement is wrong. You can only have 3 separate statements. It should be like this to correct the syntax (commas are okay as dividers):


for ( line=0 , cnt = start; cnt%26lt;=end; cnt++, line++)





You are missing a '}' after your if statement, you close the for loop but not the if statement.





The if statement doesn't have the %26amp;%26amp; (and) sign at the correct spot. It should be : if ( line%3 == 0 %26amp;%26amp; line != 0 )





You are missing the ';' after the printf statement. This will work below:














int main()


{


char start, end, dummy;


int cnt, line;





printf("Enter Start Character");


start = getchar();


dummy = getchar();





printf("Enter End Character");


end = getchar();





for(line = 0, cnt = start; cnt%26lt;=end; cnt++, line++);


{


printf("%3d%3x%2c", cnt, cnt, cnt);





if(line%3==0 %26amp;%26amp; line!=0)


printf("\n");


}





return 0;


}
Reply:Well, first of all you only got a C++. Next time try shooting for at least a B-...
Reply:on line 15 {printf("\n") it should be printf("\n");


Check your block code openers and closers, you got more { than you do }.

calling cards

.... need help with my c code please?

#include %26lt;stdio.h%26gt;





typedef enum {FALSE, TRUE} BOOL;





void main(void)


{


// Mainline Variable Declarations


// FILE * output = stdout;


// FILE * input = stdin;





char name[20]; //length limited upto 20 chars only


printf("Enter name:");


scanf("%s",name);








// type int needed for 400,800,1600,3200


int ISO=0;


// type float needed for 2 2.8 4 5.6 8 11 16 22


float aperture=0;





BOOL ReadSpeed = FALSE;


BOOL ReadAperture = FALSE;





while ((ReadSpeed == FALSE) || (ReadAperture == FALSE))


{


if (ReadSpeed == FALSE)


{








printf("Hello %s Enter ISO setting: ");


scanf("%d",%26amp;ISO);


// flush the input stream in case of bad input


fflush(stdin);


printf("\n");


............


The line printf outputs like this when I compile it :


Hello %26lt;null%26gt; Enter ISO setting . Anyone know what I'm doing wrong ?

.... need help with my c code please?
Change that printf statement to:





printf("Hello %s Enter ISO setting: ", name);
Reply:I think you meant to print "Hello (name) Enter ISO settings: ", so you need to write printf like this:





printf("Hello %s Enter ISO settings: ", name);
Reply:Get rid of the %s placeholder. C is expecting a string argument and you aren't passing one, hence the NULL. You're lucky, this would crash on some systems.


How can i convert while loop statement of the Turbo C program below in "for loop statement"?

this is the program i need to convert while loop statement into for loop statement. I already tried my best, but it does not work. Please help me. Thanks





#include %26lt;stdio.h%26gt;


#include %26lt;conio.h%26gt;


#define true 1


#define false 0





main()


{


clrscr();


int arr[5],a;


int location=0;


int const max=5;





printf("\nEnter 5 Numbers:\n");


for(a=0;a%26lt;max;a++)


{


printf("\nArray[%d]\t",a);


scanf("%d",%26amp;arr[a]);


}


int key=0,low=0,high=0,mid=0;


printf("\nEnter the value we need to look for:\n");


scanf("\n%d",%26amp;key);


low=0,high=max,mid=(low+high)/2;


int found=false;





while((low%26lt;=high)%26amp;%26amp;(!found))


{


if(key%26gt;arr[mid])


low=mid+1;


else


if(key%26lt;arr[mid])


high=mid+1;


else


{


found=true;


location=mid;


}


mid=(low+high)/2;


}


if(found)


{


printf("\nThe value was found in \n");


printf("\nArray[%d]\t",location);


}


else


{


printf("\nThe value was not found\n");


}


getch();


return(0);


}

How can i convert while loop statement of the Turbo C program below in "for loop statement"?
just change foll lines to








while((low%26lt;=high)%26amp;%26amp;(!found))


{





//**********************************


this -----


//*****************************


for(;low %26lt;=high;)


if(found) break;


{
Reply:Well, that doesn't look like it's well suited for a for loop, but here's what I would do:





Change:





while((low%26lt;=high)%26amp;%26amp;(!found))


{


if(key%26gt;arr[mid])


low=mid+1;


else


if(key%26lt;arr[mid])


high=mid+1;


else


{


found=true;


location=mid;


}


mid=(low+high)/2;


}





To:





for (


low=0;


(low%26lt;=high)%26amp;%26amp;(!found);


(key%26gt;arr[mid])?


low=mid+1:high=mid+1)


{


if(key==arr[mid])


{


found=true;


location=mid;


}


mid=(low+high)/2;


}





(Sorry about the random line breaks, Yahoo puts in stupid elipsis.)





Or maybe just to:





for (;(low%26lt;=high)%26amp;%26amp;(!found);)


{


if(key%26gt;arr[mid])


low=mid+1;


else


if(key%26lt;arr[mid])


high=mid+1;


else


{


found=true;


location=mid;


}


mid=(low+high)/2;


}





But that last one is sort of just cheating. :P Like I said, this doesn't seem like something that could benefit from a for loop...


C programming pls help me..... i need an answer ASAP =)?

the program should read user input. the output would be like this:





Enter String: the quick brown fox //then press enter


hetay uickqay rownbay oxfay


/****the 1st letter of the word is transferred to the last and will be added a suffix AY.I have a program here but i don't know how to transfer the 1st letter to the last.i can only delete the 1st letter.I don't know what to do.pls i need i help!****////





#include%26lt;stdio.h%26gt;


#include%26lt;conio.h%26gt;


#include%26lt;string.h%26gt;





void main()


{


clrscr();


char *str1;


char *str2={"ay"};


char *p;


int i;


int len;


printf("Enter String: ");


gets(str1);





p=strtok(str1," ");





if(p)


{


len=strlen(p);


for(i=0;i%26lt;len;i++)


{


p[i]=p[i+1];


}


len--;





printf("%s%s ",p,str2);


}


while(p=strtok(NULL," "))


{





len=strlen(p);


for(i=0;i%26lt;len;i++)


{


p[i]=p[i+1];


}


len--;





printf("%s%s ",p,str2);


}


getch();


}

C programming pls help me..... i need an answer ASAP =)?
You get the index of the last letter first, and then assign


the 1st letter (index 0) to the last index in your char array.


Can you answer this problem in C language?

implement this fucntion


void InsertAfterPrime(int a[ ],int n,int *count,int item)


/* This function will implement after a number is considered as a prime.It means that it will insert a number after prime.Here you can see a program that will identify if a number is a prime


int IsPrime(int x)


{


if(x==1 || x==2 || x==3 || x=5 || x=7)


printf("\n prime");


else


if(x%2%26lt;1)


printf("\n not prime");


else


if(x%5%26lt;1)


printf("\n not prime");


else


if(x%7%26lt;1)


printf("\n not prime");


else


printf("\nprime") */








int Delete(int a[ ],int *count,int item)


/*This will delete a number in any item you want remove*/





And please can you a main for me to call this function....thank you

Can you answer this problem in C language?
Yes I can answer it.
Reply:u have to remove duplicates i guess so
Reply:Yes.

pokemon cards

HELP with a C PROGRAM?

int isamicable(int nNum)


{


int a, j, nSum=0, nSum2=0;


int nMax=nNum/2;


for( j=1; j%26lt;=nMax ; j++) {


if(nNum%j==0)


nSum+=j; }


for( a=1; a%26lt;=(nSum/2) ; a++) {


if(nSum%a==0)


nSum2+=a; }


if(nSum2==nSum){


printf("\n%d is perfect", nNum); }


else if(nSum2==nNum)


printf("\n%d is amicable with %d", nNum, nSum);


else


return 0;


}





int isprime(int nNum)


{


int nMax=nNum/2;


int j,a=0;


for(j=1; j%26lt;=nMax ;j++){


if(nNum%j==0)


{ a+=1; } }


if((a==2)||(a==1))


printf("\n%d number is prime", nNum);


else


return 0;


}





int isperfect(int nNum)


{


int nSum=0;


int nMax=nNum/2;


int j=2;


do {


if(nNum%j==0)


nSum+=j;


j++;


}while(j%26lt;=nMax);


if(nSum==nNum)


printf("\n%d is perfect", nNum);


else


return 0;


}


The main function asks input from the user and calls the three function. The problem is that when the program runs and I type '6' it displays" is perfect" two times instead of one.The same thing happens when i enter amicable number and prime number. PLS HELP

HELP with a C PROGRAM?
That's because you print it in two different functions: isamicable() and isperfect() at the lines:





if(nSum2==nSum){


printf("\n%d is perfect", nNum); }





and





if(nSum==nNum)


printf("\n%d is perfect", nNum);


C Programming?

I try to generate non reoccuring number and it wont work





#include %26lt;stdio.h%26gt;


#include %26lt;stdlib.h%26gt;





int gen( int letter )


{


int x = rand()% 14 + 1 + 15* letter;


return x;


}


int main()


{


int i;


int j;


int A[5][5];


int letter;


int unique;


int cur;


int num;


FILE *card;


srand(time(0));


card = fopen("card", "w");


for (i = 0; i %26lt; 5; ++i)


{


for(j = 0; j %26lt; 5; ++j)


{


A[i][j] = gen(i);


}


}





A[2][2] = 0;





printf("B\tI\tN\tG\tO\t\n");





fprintf(card,"B\tI\tN\tG\tO\t\n");





for (i = 0; i %26lt; 5; ++i)


{ printf("%d\t%d\t%d\t%d\t%d\n", A[0][i], A[1][i], A[2][i], A[3][i], A[4][i]);


fprintf(card, "%d\t%d\t%d\t%d\t%d\n", A[0][i], A[1][i], A[2][i], A[3][i], A[4][i]);


}





cur = 0;


while ( cur %26lt; 5)


{


unique = 1;


for ( i = 0; i %26lt; cur; ++i)


{


if (A[i][j] == num )


unique = 0;


}


if (unique == 1)


{


A[i][j] = num;


cur++;


}


else


num = rand()%5+1;


}


for ( i=0; i %26lt; 5; ++i)


printf("%d: %d\n", i, j, A[i][j]);





fclose(card);


return 0;

C Programming?
Halfway down, you have the statement set





for ( i = 0; i %26lt; cur; ++i)


{


if (A[i][j] == num )


unique = 0;


}


if (unique == 1)


{


A[i][j] = num;


cur++;


}





What's j at this point?





Also, a point of style that could prevent strange bugs: If you're using i for the first subscript and j for the second, NEVER use i for the second, even if the first is a constant (as in the print loop). It's confusing, and the computer couldn't care less if you're using j without using i.





Hope that helps.


Anyone know about C programming?

I've decided to drop the class but I'm still trying to learn.





I'm trying to do some exercises from the book. One asks





"Define a structure student_record which has following members: first name, last name, idNum. Write a program to allow user to input all information of 3 students. Save them in an array and print them out accordingly"





I just did a test code to see if I could save just one....





#include %26lt;stdio.h%26gt;


int main()


{


struct student_record


{


int firstn;


int lastn;


int id;


};





struct student_record student1, student2, student3;








printf("Entry 1\n");


printf("First name\n");


scanf("%i", %26amp;student1.firstn);


printf("Last name?\n");


scanf("%i", %26amp;student1.lastn);


printf("ID?\n");


scanf("%i", %26amp;student1.id);





return 0;


}





When I compile and execute the code though it asks, for the first name, when I enter that it goes straight thru "last name and ID" without even asking for input...Also how would you put that in an array? I trued doing a students[3] structure but it didn't work.

Anyone know about C programming?
First of all, move the struct definition outside of the main function so it will be available to other functions you make. I'm surprised the compiler even accepts it the way it is now.





Next, you're trying to store the names (which should be strings) in integers. declare them as character arrays (or pointers and dynamically allocate them later, but fixed-length arrays are easier) and use "%s" in scanf to read the strings.





To use an array, declare it like:





struct student_record students[3];





and reference the individual elements like:





%26amp;students[i].id


C programming?

i got a problem here. do you have another temperature?


i cant type yes or not here and the program directly show me " pls enter to exit "


i,m using quincy 2005





#include %26lt;stdio.h%26gt;





int main (void)


{


int temp;


float celsius;


char repeat;


do


{


printf("Input a temperature:");


scanf("%d", %26amp;temp);


celsius=(5.0/9.0)*(temp-32);


printf("%d degrees F is %6.2f degrees celsius\n",temp, celsius);


printf("do you have another temperature?");


repeat=getchar();


putchar('\n');


}


while(repeat=='Y'|| repeat=='y');


}

C programming?
c:%26gt;


c:%26gt;dos


C:%26gt;dos run

plum

C++ help, ten points?

#define size 7


void sortArray (int numbers[]);


int indexMin (int numbers[], int low, int high);


void swap (int numbers[], int loc1, int loc2);


void getArray (int numbers[]);


void displayArray (int numbers[]);


int main()


{


int numbers[size];


getArray(numbers);


sortArray(numbers);


displayArray(numbers);


}


void getArray (int numbers[])


{


int i;


for (i=0; i%26lt;size; i++)


{


printf("\Enter next integer? ");


numbers[i]=GetInteger();


}


}


void displayArray (int numbers[])


{


int i;


printf("\n The sorted list is \n");


for (i=0; i%26lt;size; i++)


{


printf(" %d ", numbers[i]);


}


}


void sortArray (int numbers[])


{


int i, minInd;


for (i=0; i%26lt;size; i++)


{


minInd = indexMin (numbers, i, size-1);


swap (numbers, i, minInd);


}


}


int indexMin (int numbers[], int low, int high)


{


int i, minInd;


minInd=low;


for (i=low;i%26lt;=high;i++)


{


if (numbers[i] %26gt; numbers[minInd]) minInd=i;


}


return (minInd);


}


void swap (int numbers[], int loc1, int loc2)


{


int temp;


temp = numbers[loc1];


numbers[loc1]=numbers[loc2];


numbers[loc

C++ help, ten points?
Just don't print the duplicates at the end. This is easy, since the list is sorted.





Here's a modification of your code. The modified lines are indicated with comments.





void displayArray (int numbers[])


{


int i;


int last; // ***** The last number printed.


printf("\n The sorted list is \n");


for (i=0; i%26lt;size; i++)


{


if (i == 0 || numbers[i] != last) { // ***** Suppress duplicates.


printf(" %d ", numbers[i]);


last = numbers[i]; // ***** Save last number printed.


} // ***** End of if.


}


}





Hope this helps!
Reply:i'll get u the algorithm 4 selection sort .. hope u convert it into the program....


step 1: i=0;


step 2 : repeat steps 3-9 while(i%26lt;n-1)


step 3 : small=a[i];


step 4: loc=i; j=i+1;


step 5 : repeat steps 6,7 while(j%26lt;n)


step 6: if(small%26gt;a[j]) do steps 6.1 and 6.2;


step 6.1 : small=a[j];


step 6.2 : loc=j;


step 7 J++


step 8 interchange a[i] and a[loc]


step 9 j++


step 10 stop
Reply:In the function displayArray (int [ ]), try replacing what's inside the for loop with the following:


for (i=0; i%26lt;size; i++)


{


if ((numbers[i] != numbers[i+1]) || (i == (size - 1)))


printf(" %d ", numbers[i]);


else


continue;


}





I hope this helps you.


C programming?

I am trying to simply fractions and I can not get it to work. Can anyone help???





//simplify


simpnum1 = addnum;


simpdem1 = adddem;


if(simpnum1%26gt;simpdem1)


big = simpnum1;


else


big = simpdem1;


printf("%d\n", big);


for(i=0; i%26lt;=big; i++)


{


if(simpnum1%i==0 %26amp;%26amp; simpdem1%i==0)


{


simpnum1 = simpnum1/i;


simpdem1 = simpdem1/i;


if(simpnum1%26gt;simpdem1)


big = simpnum1;


else


big = simpdem1;


}


}





printf("%d", big);





simpnum2 = multnum;


simpdem2 = multdem;


if(simpnum2%26gt;simpdem2)


big = simpnum2;


else


big = simpdem2;


printf("%d\n", big);


for(i=0; i%26lt;=big; i++)


{


if(simpnum2%i==0 %26amp;%26amp; simpdem2%i==0)


{


simpnum2 = simpnum2/i;


simpdem2 = simpdem2/i;


if(simpnum2%26gt;simpdem2)


big = simpnum2;


else


big = simpdem2;


}


}

C programming?
Two problems here... first, you don't wanna search to the bigger of the numerator and denominator, you wanna search to the smaller of the two. Second, you don't wanna start at i=0. You're gonna wanna start at i=2.





And then all of the requisite fixing and checkings this will require. Cheers!


C-prog 2 chk if a given string is a palindrome using strrev?

actually the logic which i used was


char *s,*t ;


int x ;


printf("enter the string");


gets(s);


t=strrev(s);


x=strcmp(s,t);


if(x==0)


printf("palindrome");


else


printf("not palindrome");


getch();





the problem is that what ever string i enter the ouput says tht its a palindrome!!


friends ... plz help me out !!!???

C-prog 2 chk if a given string is a palindrome using strrev?
#include%26lt;stdio.h%26gt;


#include%26lt;string.h%26gt;





void main()


{


char s[20],t[20] ;


int x ;


printf("Enter the string : ");


gets(s);


strcpy(t,s);


strrev(s);


x=strcmp(s,t);


if(x==0)


printf("\nPalindrome");


else


printf("\nNot palindrome");


}





Actually strrev() reverses the original string,so in your program s %26amp; t were getting the same value irrespective of whatever you entered.Here I've copied the original value to t before reversing s.That solves your problem :)


also I would advise you not to use the gets() function as it is dangerous to use ,it may create problem in the memory structure,use scanf instead.
Reply:One major problem is in your program is you are using single character for s, and t; To declare string use





char s[10], t[10];


and modify your program accordingly














use strcmp() as follows


x=strcmp(*s, *t);
Reply:you r having x as integer and strcmp return %26lt;1or%26gt;1 if strings are not same so int converts a no like 0.something to zero,and string is always palindrome.just use statement


if(strcmp(s,t)) instead of putting value in x,it also decrease a variable in your program.
Reply:declare the char *s,*t as array


int s[10],t[10]


there u will get the perfect result.


C progrmaming?

/*store the information in arrays*/


for (i=0; i %26lt; num_deals; i++)


{





printf("enter pizza name please do not use spaces between names: \n");


scanf("%s",pizzaDeals[i].PizzaCompanyNam...











printf("enter size: \n");


scanf("%f", %26amp;pizzaDeals[i].pizzaSize);











printf("enter price: \n");


scanf("%f", %26amp;pizzaDeals[i].price);





count++;


}





/*decipher which pizza is the cheapest*/


/*use for loop*/


for( i = 0; i %26lt; count; i++)


{


if( pizzaDeals[i].price/pizzaDeals[i].pizzaS... %26lt; bestPrice)


{


bestPrice = pizzaDeals[i].price/pizzaDeals[i].pizzaS...


bestIndex = i;


}


}


how does the above code spit out the smallest value

C progrmaming?
The loop that is checking for the cheapest pizza is acting in a fashion like a 'bubble sort', where the highest (or smallest in this case) will 'bubble' to the top. In this case, the best price is evaluated on price/slice over the complete set of pizza parlors. The first pizza parlot (i == 0) will have the inital low price, but as you work through the arry, other pizza places may be cheaper. They in turn will become the most economical pizza. Of course, just because they are cheap doesnt mean they are any good... ;)

parts of a flower