Tuesday 14th October 2008
 
 
 
 
 
 


 
 
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

[C] Square, Sum, Product

November 16, 2006 Author: Chris T Posted in: Code Tutorials
 

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);
}
 
 
Views: 2,227
 

Feed for this Entry Trackback Address The permalink
 

 

Be the first to comment this entry.

 

 

Leave a Comment