Thursday, January 31, 2013

C Language Example # 14 For Loop Example : Display Sum of 1 to N Terms.


C Language Example # 14 For Loop Example : Display Sum of 1 to N Terms.


Lets now starts with Looping Structure of C Programming Language.

C Language Code:

//Written by Latest Technology Guide    
//Title : Example  14 For Loop Example : Display Sum of 1 to N Terms.
  
#include <stdio.h>
#include <conio.h>



void main()
{
clrscr();

int n,i,sum=0;

printf("Enter Number : ");
scanf("%d",&n);

for(i=1;i<=n;i++)
sum=sum+i;

printf("Sum of Up To %d Number is : %d",n,sum);

getch();
}



Output:
We think there is no need of Output for this program.

--------------------------------------------------------------------------------
Explanation of C Language Example  # 14 For Loop Example : Display Sum of 1 to N Terms..

* Enter value for Number of Terms as N.
* This C Program will display sum of 1 to N Terms.

Still having doubts you can post comment, will explain in details.

Note: All programs are developed and tested using Turbo C++ 3.0 under Windows XP. We just want to provide guidelines to the users. If you are using any other Compiler or other operating system they you need to modify this program as per your requirements. 

No comments:

Post a Comment