Advertisement
atiqxp

Calculate the Sum up to nth term :

Jul 20th, 2013
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.34 KB | None | 0 0
  1. #include<stdio.h>
  2. int main(void)
  3. {
  4.     int sum=0,i,n,d,a_n,a_1;
  5.     a_1=1;
  6.     d=10;
  7.  
  8.     printf("Enter the nth number:");
  9.     scanf("  %d",&n);
  10.  
  11.     a_n=a_1+(n-1)*d;
  12.  
  13.     printf("The valude of a_n is:  %d\n",a_n);
  14.  
  15.     for(i=0; i<a_n; i=i+10)
  16.     {
  17.         sum=i+sum;
  18.     }
  19.  
  20.     printf("Sum is: %d\n",sum);
  21.  
  22.     return 0;
  23. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement