A very simple program written in c which calculates the square, the sum and the product of numbers from 1 to 10. A good functions introduction in c.
#include <stdio.h> int main(void) { int x,y=0,g=1; for (x = 1;x <= 10;x++){ printf("The %1d^2 is=%d \n",x,squ(x)); y = sum(x,y); g = tot(x,g); } printf("The sum of numbers is %d\n",y); printf("The product of numbers is %d\n",g); system("PAUSE"); return 0; } tot(x,g) int x,g; { int total; total = x * g; return(total); } sum(x,y) int x,y; { int sum; sum = y + x; return(sum); } squ(in) int in; { int square; square = in * in; return(square); }
Feed for this Entry Trackback Address The permalink
Be the first to comment this entry.


Recent Comments