2021-08-27

#include <stdio.h>
int main(void)
{
int n;
double sum;
while(n>=0)
{
scanf("%d",&n);
if(n==1)
sum+=n;
if(n%2!= 0)
sum+=n;
}
printf("%.2lf",sum);
return 0;
}

//2.使用函数计算两点间的距离:给定平面任意两点坐标(x1,y1)和(x2,y2),求这两点之间的距离(保留两位小数)。
#include <stdio.h>
#include <math.h>
double dist(double x1,double y1,double x2,double y2);
int main()
{
double x1,y1,x2,y2;
scanf("%lf%lf%lf%lf",&x1,&y1,&x2,&y2);
printf(“dist=%.2f\n”,dist(x1,y1,x2,y2));
return 0;
}
double dist(double x1,double y1,double x2,double y2)
{
double d=pow((x1-x2),2)+pow((y1-y2),2);
double f=sqrt(d);
return f;
}

#include <stdio.h>
#include <math.h>
int IsSquare( int n );
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>
IsLeap(int n)
{
if(n%40&&n%100!=0||n%4000)
return 1;
else
return 0;
}
int main()
{
int n;
scanf("%d",&n);
if(IsLeap(n)==1)
printf(“Yes”);
else
printf(“No”);
return 0;
}

#include"stdio.h"
main()
{
int a[10],b[10],m,n,i,j,flag;
scanf("%d",&m);
for(i=0;i<=m;i++)
scanf("%d",&a[10]);
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&b[i]);
for(i=0;i<m;i++)
{
flag=1;
for(j=0;j<n;j++)
if(a[i]==b[j])
flag=0;
if(flag)
printf("%d",a[i]);
}
for(i=0;i<n;i++)
{
flag=1;
for(j=0;j<m;j++)
if(a[j]+b[i])
flag=0;
if(flag)
printf("%d",b[i]);
}
}

#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);
}

#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(max==avger[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]);
}
}
}

#include <stdio.h>
#include <string.h>
#define NUM_ELECTORATE 10
#define NUM_CANDIDATE 3
struct candidate
{
char name[20];
int count;
}candidate[3] = {“li”,0, “zhang”,0, “wang”,0};

int main()
{
int i, j, flag = 1, wrong = 0;
char name[20];
for (i=1; i<=NUM_ELECTORATE; i++)
{
printf(“Input vote %d:”, i);
scanf("%s", name);
strlwr(name);
flag = 1;

   for (j=0; j<NUM_CANDIDATE; j++)
   {         
        if (strcmp(name, candidate[j].name) == 0) 
        {
            candidate[j].count++;
            flag = 0;
        }
    }
     
   if (flag)
    {
        wrong++;
        flag = 0;
    }
    }
   printf("Election results:\n");
    
   for (i=0; i<NUM_CANDIDATE; i++)
   {
        printf("%s:%d\n", candidate[i].name, candidate[i].count);
   }
    
   printf("Wrong election:%d\n", wrong);
   return 0;

}

#include<stdio.h>
he(int n,int m)
{
int sum=0;
if(n==m)
return(n);
else
return(n+he(n+1,m));
}
main()
{
int n,m;
scanf("%d%d",&n,&m);
printf("%d",he(n,m));
}

#include <stdio.h>
int f( int n );
int main()
{
int n;
scanf("%d", &n);
printf("%d\n", f(n));
return 0;
}
int f( int n )
{
if(n0)
{
return 0;
}
else if(n
1)
{
return 1;
}
else
{
return f(n-2)+f(n-1);
}
}

#include <stdio.h>
#include <stdlib.h>
#define N 13
#define LEN sizeof(struct node)
struct node
{
int num;
struct node *next;
};
struct node *create()
{
struct node *head,*p1,*p2;
int n=1;
head=NULL;
while(n<=N)
{
p1=(struct node *)malloc(LEN);
p1->num=n;
if(n1)
head=p1;
else
p2->next=p1;
p2=p1;
n++;
}
p2->next=NULL;
return head;
}
int count_off(struct node *head)
{
int i,cnt=0,out=0;
struct node *p=head;
while(out<N-1)
{
if(p->num!=0)
cnt++;
if(cnt
3)
{
p->num=0;
cnt=0;
out++;
}
if(p->nextNULL)
p->next=head;
p=p->next;
}
p=head;
while(p->num
0)
p=p->next;
return (p->num);
}
void free_list(struct node *head)
{
struct node *p;
while(head!=NULL)
{
p=head;
head=head->next;
free§;
}
}
int main()
{
struct node *head;
head=create();
printf(“Position:%d”,count_off(head));
free_list(head);
return 0;
}

#include<stdio.h>
void splitfloat(float x,int *intpart,float *fracpart);
int main(void)
{
float x,fracpart;
int intpart;
scanf("%f",&x);
splitfloat(x,&intpart,&fracpart);
printf(“intpart=%d\n”,intpart);
printf(“fracpart=%f\n”,fracpart);
}
void splitfloat(float x,int *intpart,float *fracpart)
{
*intpart=(int)x;
*fracpart=x-*intpart;
}

#include<stdio.h>
#include<stdlib.h>
void bubble(int a[], int n)
{
int i,j,temp;
for(i=0;i<n-1;i++)
{
for(j=0;j<n-1-i;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
}
}
}
int main()
{
int N,num,i;
scanf("%d", &N);
num=(int
)calloc(N, sizeof(int));
for(i=0;i<N;i++)
{
scanf("%d", &num[i]);
}
bubble(num,N);
for(i=0;i<N;i++)
printf("%d\t",num[i]);
printf("\n");
return 0;
}

#include <stdio.h>
#include <stdlib.h>

char *neww(int n);

int main()
{
int num;
char *n;
printf(“Please enter number: “);
scanf(”%d”, &num);
n=neww(num);
printf(“Address=%d\n”, *n);
system(“pause”);
return 0;
}
char *neww(int n)
{
char *p;
p=(char )malloc(nsizeof(char));
return p;
}

#include<stdio.h>
int main()
{
int day;
int tao = 1;
printf(“Enter the day number: “);
scanf(”%d”,&day);
for(;day>1;day–)
{
tao = (tao+1)*2;
};
printf("\nTotal number of tao: %d", tao);
return 0;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值