by Dinesh Thakur Category: C Programming (Pratical)

This program segment calculates the sum of integer numbers from 1 to n. Initially, the value of n is read from the keyboard and variable sum is initialized to zero. Then a for loop is set up in which the loop variable j assumes values from 1 to n. For each value of j, the assignment statement included in the for loop is executed and the value of j is added to the previous value of sum.

Thus, when the execution of the for loop is over, variable sum will contain the sum of numbers from 1 to n. Finally, the value of sum is printed on the screen. The program output is shown below: 

void main()
       int n,j,sum=0;
       printf("Enter the Number : ");
              printf("%d ",j);
              printf("\nSum of  %d is : %d ",n,sum);

Program to Sum of N Number

About Dinesh Thakur

Dinesh ThakurDinesh Thakur holds an B.C.A, MCSE, MCDBA, CCNA, CCNP, A+, SCJP certifications. Dinesh authors the hugely popular blog. Where he writes how-to guides around Computer fundamental , computer software, Computer programming, and web apps. For any type of query or something that you think is missing, please feel free to Contact us.