SAADQUAMER

Sum of natural number

Jun 8th, 2019
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.25 KB | None | 0 0
  1. // C Program to Calculate the Sum of Natural Numbers
  2. #include<stdio.h>
  3. int main(){
  4.  
  5. int sum=0,i,n;
  6.  printf("Enter Integer Value :");
  7.  scanf("%d",&n);
  8.  for(i=1;i<=n;i++){
  9.     sum+=i;
  10.  
  11.  }
  12. printf("Sum of first %d number is %d\n",n,sum);
  13. return 0;
  14. }
Advertisement
Add Comment
Please, Sign In to add comment