暑假作业c语音1-10题
作者:互联网
暑假作业1-10
1.
#include<stdio.h>
int even(int n);
int main()
{
int n;
int sum=0;
while(1)
{
scanf("%d",&n);
if(n<=0)
break;
if(even(n)==0)
{
sum+=n;
}
}
printf("The sum of the odd numbers is %d\n",sum);
return 0;
}
int even(int n)
{
int ret;
if(n%2)
ret=0;
else
ret=1;
return ret;
}
#include<stdio.h>
#include<math.h>
void dist(int x1,int y1,int x2,int y2)
{
float sum;
sum=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
printf("%.2f",sum);
}
void main()
{
int x1,y1,x2,y2;
scanf("%d%d%d%d",&x1,&x2,&y1,&y2);
dist(x1,y1,x2,y2);
}
#include <stdio.h>
#include <math.h>
int IsSquare( int n );
int main()
{
int n;
scanf("%d", &n);
if ( IsSquare(n) )
printf("YES\n");
else
printf("NO\n");
return 0;
}
int IsSquare(int n)
{
if(sqrt(n)==(int)sqrt(n))
return 1;
else
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int IsLeap(int year)
{
if (year%4==0&&year%100!=0||year%400==0)
return 1;
else
return 0;
}
int main()
{
int num=0;
scanf("%d",&num);
int ret=IsLeap(num);
if (ret==1)
{
printf("%d年是闰年\n", num);
}
else
{
printf("%d年不是闰年\n", num);
}
return 0;
}
#include<stdio.h>
int main()
{
int n;
scanf("%d",&n);
int i,a[n];
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
int b[n-1],count=0;
for(i=0;i<n-1;i++)
{
b[i]=a[i+1]-a[i];
printf("%d",b[i]);
count++;
if(count%3==0)
printf("\n");
}
return 0;
}
#include<stdio.h>
#include<string.h>
void fun(char*a,char*b,char*c)
{
int i=0;
while(*a||*b)
{
if(*a<*b)
c[i]=*b;
else
c[i]=*a;
if(*a)
a++;
if(*b)
b++;
i++;
}
}
main()
{
char x[10]="AbceDEfG",y[10]="ABdefgC",c[80]={'\0'};
fun(x,y,c);
printf("The string x:");
puts(x);
printf("The string y:");
puts(y);
printf("The result:");
puts(c);
}
#include<stdio.h>
main()
{
int i,j,k,m=0,f=0;
int sum=0,max=0,min=0;
struct student
{
int num;
char name[20];
char gender;
int birthday[3];
int score[4];
int ave;
}stu[4]={{10031,"wanggang",'M',{1991,5,19},{72,83,90,82},0},
{10032,"liming",'M',{1992,8,20},{88,92,78,78},0},
{10033,"wangli",'F',{1991,9,19},{98,72,89,66},0},
{10034,"chenhong",'F',{1992,3,22},{87,95,78,90},0}
};
printf("输出五位同学的信息\n");
for(i=0;i<5;i++)
{
printf(" 学号:%d,姓名:%s,性别:%c,总分:%d,平均分:%d,\n",stu[i].num,stu[i].name,stu[i].gender,stu[i].ave);
printf("出生日期:");
for(j=0;j<3;j++)
{
printf("%d ",stu[i].birthday[j]);
}
printf("成绩:");
for(k=0;k<4;k++)
{
printf("%d ",stu[i].score[k]);
}
printf("\n");
}
printf("\n");
printf("平均成绩最高");
for(i=0;i<5;i++)
{
for(k=0;k<4;k++)
{
sum+=stu[i].score[k];
stu[i].ave=sum/k;
}
if(max<stu[i].ave)
max=stu[i].ave;
}
printf("平均成绩最高是%d",max);
}
#include<stdio.h>
#include<string.h>
struct Candidate
{
char name[10];
int count;
};
int main()
{
struct Candidate arr[3]=
{
"li",0,"zhang",0,"wang",0
};
int i=0,j=0;
char s[10];
int wrong=0;
int flag=0;
for(i=0;i<10;i++)
{
flag=0;
printf("Input vote %d:",i+1);
scanf("%s",s);
for(j=0;j<3;j++)
{
if (strcasecmp(arr[j].name,s)==0)
{
arr[j].count++;
flag=1;
}
}
if (flag==0)
{
wrong++;
}
}
printf("Election results:\n");
for (i=0;i<3;i++)
{
printf("%8s:%d\n",arr[i].name,arr[i].count);
}
printf("Wrong election:%d\n",wrong);
}
#include<stdio.h>
void main()
{
int n1,n2,i,sum=0;
scanf("%d%d",&n1,&n2);
for(i=n1;i<=n2;i++)
{
sum+=i;
}
printf("%d",sum);
}
#include<stdio.h>
#include<stdlib.h>
#define N 20
int main(void)
{
int Fib[N]={0};
int i;
Fib[0]=0;
Fib[1]=1;
for(i=2;i<N;i++)
Fib[i]=Fib[i-1]+Fib[i-2];
for(i=0;i<N;i++)
printf("%d",Fib[i]);
printf("\n");
return 0;
}
标签:10,main,return,int,sum,语音,printf,include,暑假作业 来源: https://blog.csdn.net/m0_54632847/article/details/118460766