Tuesday 29 March 2016

Program to calculate sum of n nos using for loops in c++ language.

//WAP to calculate sum of n nos using for loops in c++ language.
 

#include<iostream.h>
#include<conio.h>

void main()
{
clrscr();

int i,n,sum=0;
cout<<"enter the value of n:"<<endl;
cin>>n;

for(i=1;i<=n;i++)
{
sum=sum+i;
}
cout<<"the sum of n nos is:"<<sum;

getch();
}

Output:-
                          

No comments:

Post a Comment