13. Write a Algorithm and Program to calculate and print the sum of even
integers of the first n natural numbers
Input:
1) n
Output:
1) sum of even
Methd:
1.start
2.Read n
3.Prit n
4.//logic for sum
sum_e=0;
for(i=0;i<n;i++)
{
sum_e = sum_e + i;
i=i+1;
}
5. print sum_e
6.stop
#include<iostream.h>
void main()
{
int n,i,sum_e;
cout<<"Enter n value";
cin>>n;
cout<<"\n n="<<n;
//logic for sum
sum_e=0;
for(i=0;i<n;i++)
{
sum_e = sum_e + i;
i=i+1;
}
cout<<"\n sum of n natural even numbers ="<<sum_e;
}
integers of the first n natural numbers
Input:
1) n
Output:
1) sum of even
Methd:
1.start
2.Read n
3.Prit n
4.//logic for sum
sum_e=0;
for(i=0;i<n;i++)
{
sum_e = sum_e + i;
i=i+1;
}
5. print sum_e
6.stop
#include<iostream.h>
void main()
{
int n,i,sum_e;
cout<<"Enter n value";
cin>>n;
cout<<"\n n="<<n;
//logic for sum
sum_e=0;
for(i=0;i<n;i++)
{
sum_e = sum_e + i;
i=i+1;
}
cout<<"\n sum of n natural even numbers ="<<sum_e;
}
No comments:
Post a Comment