Write a Program in c++ to find sum of n natural no's using while loop.
//wap in c++ to find sum of n natural no's using while loop.
Coding:-
#include<iostream.h>
#include<conio.h>
void main()
{
clrscr();
int i=1,n,sum=0;
cout<<"enter the no";
cin>>n;
while(i<=n)
{
sum=sum+i;
i++;
}
cout<<"sum="<<sum;
getch();
}
Output:-
No comments:
Post a Comment