Write
a program to find the sum of 1 to 100.
#include<iostream.h>
void main()
{
int
i,s=0;
for(i=1;i<=100;i++)
s+=i;
cout
<< "Sum of 1 to 100 is " << s;
}
Write
a program to find the sum of even numbers 2 to 100.
#include<iostream.h>
void main()
{
int
i,s=0;
for(i=2;i<=100;i+=2)
s+=i;
cout
<< "Sum of even numbers 2 to 100 is " << s;
}
Write
a program to find the sum of odd numbers 1 to 99.
#include<iostream.h>
void main()
{
int
i,s=0;
for(i=1;i<=99;i+=2)
s+=i;
cout
<< "Sum of even numbers 1 to 99 is " << s;
}
Write
a program to find the sum of following sequence.
3,
10, 17, 24, 31, 38, 45, 52, 58, 65
#include<iostream.h>
void main()
{
int
i,s=0;
for(i=3;i<=65;i+=7)
s+=i;
cout
<< "Sum of the sequence is " << s;
}
Write
a program to find the sum of following sequence.
1,
4, 9, 16, 25, 36, 49, 64, 81, 100
#include<iostream.h>
void main()
{
int
i,s=0;
for(i=1;i<=10;i++)
s+=(i*i);
cout
<< "Sum of the sequence is " << s;
}
No comments:
Post a Comment