#include<iostream.h>
#include<conio.h>
void main()
{
int i,n,sum;
clrscr();
cout<<"Enter the limit ";
cin>>n;
sum=0;
i=1;
while(i<n)
{
sum=sum+i;
++i;
}
cout<<"sum of first "<<n<<" natural number is "<<sum;
getch();
}
#include<conio.h>
void main()
{
int i,n,sum;
clrscr();
cout<<"Enter the limit ";
cin>>n;
sum=0;
i=1;
while(i<n)
{
sum=sum+i;
++i;
}
cout<<"sum of first "<<n<<" natural number is "<<sum;
getch();
}
No comments:
Post a Comment