write a program to sum the to print the sum of odd number from one to hundred
Answers
Answered by
2
For printing sum of 1st 100 odd no's in C, you can write the following code
#include<stdio.h>
int main()
{
int i,sum=0;
for(i=1;i<200;i=i+2)
{
Sum=Sum+i;//It will add first 100 odd no’s.
}
Printf(“%d”,Sum);//will display sum of first 100 odd no’s.
}
Here 1 is the 1st odd no and 201 is the 100th.
you can perform it in other ways also
#include<stdio.h>
int main()
{
int sum=0,i,count=0;
while(count<100)
{
for(i=1;;i=i+2)
{
sum=sum+i;
count++;
}
}
}
Hope it helps.
#include<stdio.h>
int main()
{
int i,sum=0;
for(i=1;i<200;i=i+2)
{
Sum=Sum+i;//It will add first 100 odd no’s.
}
Printf(“%d”,Sum);//will display sum of first 100 odd no’s.
}
Here 1 is the 1st odd no and 201 is the 100th.
you can perform it in other ways also
#include<stdio.h>
int main()
{
int sum=0,i,count=0;
while(count<100)
{
for(i=1;;i=i+2)
{
sum=sum+i;
count++;
}
}
}
Hope it helps.
Similar questions