Advertisement
fahim-ahmed2019

sum of 1-100 numbers by using for loop

Oct 19th, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.30 KB | None | 0 0
  1. #include <stdio.h>
  2. int main()
  3. {
  4. int i,n,sum=0;
  5. printf("enter 1 to 100 : ");
  6. scanf("%d",&n);
  7. printf("\nThe first %d natural numbers are:\n",n);
  8. for(i=1;i<=n;i++)
  9. {
  10. printf("%d ",i);
  11. sum+=i;
  12. }
  13. printf("\nThe Sum of natural numbers upto %d terms : %d \n",n,sum);
  14.  
  15. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement