暑假作业
作者:互联网
1,
#include<stdio.h>
even(int n)
{
if(n%2)
return(1);
else
return(0);
}
main()
{
int n,sum=0;
scanf("%d",&n);
while(n)
{
if(even(n))
sum+=n;
scanf("%d",&n);
}
printf("%d",sum);
}
2.
#include<stdio.h>
#include<math.h>
double dist(double x1,double y1,double x2,double y2)
{
return(sqrt((x1-x2)(x1-x2)+(y1-y2)(y1-y2)));
}
main()
{
int x1,y1,x2,y2;
scanf("%d%d%d%%d",&x1,&y1,&x2,&y2);
printf("%.2f",dist(x1,y1,x2,y2));
}
3.
#include<stdio.h>
lsleap(int n)
{
int i,a=0;
for(i=0;i<=n;i++)
if(i*in)
a=1;
return(a);
}
main()
{
int n;
scanf("%d",&n);
if(lsleap(n))
printf(“yes”);
else
printf(“no”);
}
4.
#include<stdio.h>
lsleap(int n)
{
if(n%40&&n%100!=0||n%4000)
return(1);
else
return(0);
}
main()
{
int n;
scanf("%d",&n);
if(lsleap(n))
printf(“yes”);
else
printf(“no”);
}
5.想不明白如何比较两个数组中如何找到相同的并且排除他;扽想明白了再写;
6.#include<stdio.h>
char bi(char a,char b)
{
return(a>b?a:b);
}
main()
{
char a[10],b[10],c[10];
int i;
scanf("%s",&a);
scanf("%s",&b);
for(i=0;i<10;i++)
{
c[i]=bi(a[i],b[i]);
}
printf("%s",c);
}
7.
#include<stdio.h>
struct student
{
int num;
char name[10];
char xing;
struct birthday
{
int year;
int mouth;
int day;
}a;
int cheng[4];
};
main()
{
struct student stu[4]={{1,“wanggang”,‘m’,.a={1991,5,19},72,83,90,82},
{2,“liming”,‘m’,.a={1992,8,20},88,92,78,78},
{3,“wangli”,‘f’,.a={1991,9,19},98,72,89,66},
{4,“chenghong”,‘f’,.a={1992,3,22},87,95,78,90},
};
int i,j;
int avger[4],sum[4]={0};
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
sum[i]+=stu[i].cheng[j];
avger[i]=sum[i]/4;
}
int max=0;
for(i=0;i<4;i++)
if(max<avger[i])
max=avger[i];
for(i=0;i<4;i++)
{
if(maxavger[i])
{
printf("%d %s %c %d %d %d %d %d %d %d",stu[i].num,stu[i].name,stu[i].xing,stu[i].a.year,stu[i].a.mouth,stu[i].a.day,stu[i].cheng[0],stu[i].cheng[1],stu[i].cheng[2],stu[i].cheng[3]);
}
}
}
8.
#include<stdio.h>
#include<string.h>
struct man
{
char name[10];
int shu;
}m[3]={“zhang”,0,“li”,0,“wang”,0};
main()
{
int i,name[10],j;
for(i=0;i<10;i++)
{
scanf("%s",name);
for(j=0;j<3;j++)
{
if(strcmp(name,m[j].name)0)
m[j].shu+=1;
}
}
for(i=0;i<3;i++)
printf("%s %d\n",m[i].name,m[i].shu);
}
9.
#include<stdio.h>
he(int n,int m)
{
int sum=0;
if(nm)
return(n);
else
return(n+he(n+1,m));
}
main()
{
int n,m;
scanf("%d%d",&n,&m);
printf("%d",he(n,m));
}
10.
#include<stdio.h>
f(int n)
{
if(n0||n1)
return(1);
else
return(f(n-2)+f(n-1));
}
main()
{
int n;
scanf("%d",&n);
printf("%d",f(n));
}
标签:return,int,scanf,stu,printf,include,暑假作业 来源: https://blog.csdn.net/qq_54632230/article/details/118554873