作业
22.
#include"stdio.h"
main()
{
int i;
for(i=10;;i++)
{
if(i%51&&i%64&%74&&i%1110)
{
printf(“总人数为:%d\n”,i);
break;
}
}
}
23.
#include"stdio.h"
main()
{
double a=2,t;
double b=1;
double sum=0;
int n=0,num=1;
printf(“请输入N:”);
scanf("%d",&n);
while(num<=n)
{
sum=sum+a/b;
t=b;
b=a;
a=t+b;
num++;
}
printf(“前%d项之和是:%.2f\n”,n,sum);
}
24.
#include <stdio.h>
void main()
{
int a,n,s=0;
printf(“Input a: “);
scanf(”%d”,&a);
printf(“Input n:”);
scanf("%d",&n);
while(n>=0)
{
s=an+s;
a=a10;
n–;
}
printf(“s= %d\n”,s);
}
25.
#include<stdlib.h>
#include<stdio.h>
main()
{
int i,count=0;
int all[141];
for(i=0;i<141;i++)
all[i]=0;
for(i=0;i<=520;i+=5)
{
all[i]++;
}
for(i=0;i<=620;i+=6)
{
all[i]++;
}
for(i=0;i<=7*20;i+=7)
{
all[i]++;
}
for(i=0;i<141;i++)
{
if(all[i]=0)
{
count++;
printf("%4d",i);}
}
printf(“count=%d”,count);
}
26.
#include<stdio.h>
int main()
{
int a[5][5]={1,42,3,45,5,6,7,78,9,10,11,12,34,77,19,22,15,36,28,40,99,66,2,100,38},b[5];
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%5d",a[i][j]);
printf("\n");
}
for(i=0;i<5;i++)
{
b[i]=a[i][0];
for(j=1;j<5;j++)
if(a[i][j]>b[i])
b[i]=a[i][j];
}
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
if(a[i][j]==b[i])
a[i][j]=0;
}
printf("\n");
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%5d",a[i][j]);
printf("\n");
}
}
27.
#include “stdio.h”
main()
{
int arr[10];
int i;
printf(“please input the numbers:\n”);
for(i=0;i<10;i++)
scanf("%d",&arr[i]);
for(i=0;i<10;i++)
if(arr[i]%10%2!=0&&arr[i]/10%2==0)
printf("%d\t",arr[i]);
}
28.
#include<stdio.h>
#include<math.h>
int main()
{
double a, b, x, y;
scanf("%lf%lf%lf%lf",&a,&b,&x,&y);//读入
printf("%.2f\n",sqrt((a - x) * (a - x) + (b - y) * (b - y)));
}
29.
#include <stdio.h>
main()
{
int m,n,sum=0,counter=0;
int i,j;
scanf("%d%d",&m,&n);
for(i=m;i<=n;i++)
{
for(j=2;j<i;j++)
if(i%j0)
break;
if(ji)
{
sum=sum+i;
counter++;
}
}
printf(“counter=%d,sum=%d\n”,counter,sum);
}
30.
#include “stdio.h”
void main()
{
int score[200];
int counter1=0,counter2=0,counter3=0,counter4=0,counter5=0;
for(i=0;i<200;i++)
{
scanf("%d",&score[i]);
if((score[i] == -1))
break;
else if(score[i]>=90)
counter1++;
else if(score[i]>=80)
counter2++;
else if(score[i]>=70)
counter3++;
else if(score[i]>=60)
counter4++;
else
counter5++;
}
printf(" <60 is %d\n 60-69 is %d\n 70-79 is %d\n 80-89 is %d\n 90-100 is %d\n ",counter5,counter4,counter3,counter2,counter1);
}