(1)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,sum;
for(i=1;i<=101;i+=2)
{
sum+=i;
}
printf("sum=%d\n",sum);
return 0;
}
(2)
#include <stdio.h>
#include <stdlib.h>
int main()
{
long i;
long term,sum=0;
for(i=1;i<=99;i+=2)
{
term=i*(i+1)*(i+2);
sum=sum+term;
}
printf("sum=%ld\n",sum);
return 0;
}
(3)
#include <stdio.h>
#include <stdlib.h>
int main()
{
long term=1,sum=0;
int a,i,n;
printf("Input a,n:");
scanf("%d%d",&a,&n);
for(i=1;i<=n;i++)
{
term=pow(a,i);
sum=sum+term;
}
printf("sum=%ld\n",sum);
return 0;
}
(4)
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n=1;
float term=1.0,sigh=1,sum=0;
while(n<10000)
{
term=sigh*(1.0/n);
sum=sum+term;
sigh=-sigh;
n++;
}
printf("sum=%f\n",sum);
return 0;
}