This simple C program shows simple arithmetic calculations.
// main() function…
int main( )
// variables declaration
int x, y, z;
// variables initialization, assign 20 to variable x…
// or put the value of 20 in memory location labeled by x
x = 20;
y = 2;
printf("Given x = 20, y = 2\n");
printf("\nx / y = %d", x / y);
// do some basic calculations
x = x * y;
y = y + y;
printf("\nx = x * y");
printf("\ny = y + y");
printf("\nNew value for x / y = %d", x / y);
z = 20 * y / x;
printf("\nz = 20 * (y / x) = %d\n", z);
|1. ||View Comment|
Dear Gurus, I have arrived at your site lloking for an understanding of scanf and printf. To my horror at first sight the assosciated characters d i o u x c s e,f,g % are used with the assumption that to discuss them and how to use them is so basic that they are not discussed.
In embedded applications e.g. pic uCs I program quite well in integer arithmetic. This of course has a big problem when you want decimals. Eg. 355/113 is a good approximation to PI. There are work arounds to preserve the decimals, but C as used in uC would seem to be a better way.
Which brings me back to the C language and scanf, printf....
where do I find an article which step by step shows the usage of the formaters , hopefully with examples?
Bye and thanks
View Tutorial By: Fred Mah at 2012-09-22 07:40:27
|2. ||View Comment|
Hi Fred, I found this link which has more explanation on it. http://www.cdf.toronto.edu/~ajr/209/notes/printf.html
View Tutorial By: Boulvat at 2012-09-25 08:36:48