C++ Programs
| Program to find the sum of n natural numbers using while loop. |
#include<iostream.h>
#include<conio.h>
void main()
{
int n,sum=0,i;
clrscr();
cout<<"Enter the number";
cin>>n;
i=1;
while(i<=n)
{
sum=sum+i;
i++;
}
cout<<"Sum is:"<<sum;
getch();
}
| Output: |
Enter the number10
Sum is:55
If any of you want to submit your programs and
contribute to site please mail us at:
citysuvidha@gmail.com
Click here to have a look at List of programs
You can download all the programs in a zip file also. For this you have to do one thing. Just register at the citysuvidha forum and start any thread of any topic. Once you start the thread and put your request, admin will automatically send you the desired zip file.