Advertisement
Mahmud33

sum of all natural numbers between 1 to n

Jun 30th, 2019
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.21 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int main()
  4. {
  5.     int i, j, sum=0;
  6.  
  7.     printf("n= ");
  8.     scanf("%d", &j);
  9.  
  10.     for(i=1; i<=j; i++)
  11.     {
  12.         sum += i;
  13.     }
  14.  
  15.     printf("Sum =%d", sum);
  16.  
  17.     return 0;
  18. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement