#include
<stdio.h>
int main()
{
int i=1,sum=0;
while(i<=100)
{
sum=sum+i;
i++;
}
printf("sum=%d\n",sum);
return 0;
}
#include
int main()
{
int i=1,sum=0;
do
{
sum=sum+i;
i++;
}while(i<=100);
printf("sum=%d\n",sum);
return 0;
}
#include
int main()
{
int i,sum=0;
printf("please enter i, i=?");
scanf("%d",&i);
while(i<=10)
{
sum=sum+i;
i++;
}
printf("sum=%d\n",sum);
return 0;
}
#include
int main()
{
int i,sum=0;
printf("please enter i, i=?");
scanf("%d",&i);
do
{
sum=sum+i;
i++;
}while(i<=10);
printf("sum=%d\n",sum);
return 0;
}
#include
#define SUM 100000
int main()
{
float amount,aver,total;
int i;
for(i=1,total=0;i<=1000;i++);
{
printf("please enter amount:");
scanf("%f",&amount);
total= total+amount;
if (total>=SUM) break;
}
aver=total/i;
printf("num=%d\naver=%10.2f\n",i,aver);
return 0;
}
# include
int main()
{
int i,j,n=0 ;
for(i=1,i<=4;i<=1000;i++);
for (j=1;j<=5;j++,n++)
{ if (n%5==0) printf ("\n");
printf ("%d\t",i*j);
}
printf("\n");
return 0;
}
F1= 1 (n= 1) F2= 1 (n=2) Fn= Fn-1+Fn+1 (n≥3)
这是一个有趣的古典数学问题有一对兔子,从出生后第3个月起每个月都生一对免子.小兔子长到第3个月后每个月义生一对兔子。假设所有兔子都不死,问每个月的兔子总数为多少?
#include
int main()
{
int n,i;
printf("please enter a integer number,n=?");
scanf("%d",&n);
for(i=2;i<n;i++)
if(n%i==0)break;
if(i<n)
printf("%d is not a prime number.\n",n);
else printf("%d is a prime number.\n",n);
return 0;
}
#include
#include
int main()
{
int n,k,i,m=0;
for(n=101;n<=200;n=n+2)
{
k=sqrt(n);
for(i=2;i<=k;i++)
if(n%i == 0)break;
if(i>=k+1)
{
printf("%d ",n);
m=m+1;
}
if(m%10==0)
printf("\n");
}
printf("\n");
return 0;
}
#include
int main()
{
char a;
a=getchar();
while(a!='\n')
{
if((a>='A'&&a<='V')||(a>='a'&&a<='z'))
{
a=a+4;
printf("%c",a);
}
if((a>='W'&&a<='Z')||(a>='w'&&a<='z'))
{
a=a-22;
printf("%c",a);
}
a=getchar();
}
printf("\n");
return 0;
}