Calculate Sum Of Natural Numbers
/* This program is solved using while loop. */ #includeint main() { int n, count, sum=0; printf("Enter an integer: "); scanf("%d",&n); count=1; while(count<=n) /* while loop terminates if count>n */ { sum+=count; /* sum=sum+count */ ++count; } printf("Sum = %d",sum); return 0; } Output Enter an integer: 100 Sum = 5050
EmoticonEmoticon