Friday, July 31, 2009

C Programming percentage?

Can someone give me a simple C program that will display the percentage of two numbers.

C Programming percentage?
just change the 400 to 400.00 and the 800 to 800.00.


Other than that, your program is correct
Reply:i can help for sure. but you have to make the problem more clear. i mean you wanna find out the average number or percentage ( like number one from another). the percentage formula is n1 / n2*100.
Reply:#include %26lt;stdio.h%26gt;





int main(void)


{


float myVar = 3.24;


float myOtherVar = 1.618;


printf("myVar = %f and myOtherVar = %f", myVar, myOtherVar);


getchar(); // So the program doesn't close immediately


return 0;


}
Reply:for integers:





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


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





int main (int argc, char **argv) {


int numerator, denominator;





if (argc != 3) {


fprintf(stderr, "%s num denom \n", argv[0]);


return 1;


}





numerator = atoi(argv[1]);


denominator = atoi(argv[2]);


printf ("%d/%d = %3.2f%%\n", numerator, denominator, 100 * ( ((float)numerator)/denominator));


No comments:

Post a Comment