C Language Tutorials by Ghulam Murtaza Dahar - HTML preview

PLEASE NOTE: This is an HTML preview only and some elements such as links or page numbers may be incorrect.
Download the book in PDF, ePub, Kindle for a complete version.

numbers.

#include <stdio.h>

int main(){

int n, count, sum=0;

printf("Enter the value of n.\n");

scanf("%d",&n);

for(count=1;count<=n;++count) //for loop terminates if count>n

{

sum+=count; /* this statement is equivalent to sum=sum+count */

}

printf("Sum=%d",sum);

return 0;

}