2004
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a,t,i=0;
printf("请输入一个不多于五位的正整数:");
scanf("%d",&a);
int b[5];
int count=0;
while(a)
{
t=a%10;
b[i++]=t;
a/=10;
}
printf("是%d位数\n",i--);
printf("顺序:");
count =i;
while(i>=0)
{
printf("%d",b[i--]);
}
printf("\n逆序:");
for(int k=0;k<=count;k++)
{
printf("%d",b[k]);
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
char a[5]={'g','e','y','f','p'};
int i,j,k;
char ch;
for(i=0;i<4;i++)
{
k=i;
for(j=i+1;j<5;j++)
{
if(((a[k]-a[j]))>0)k=j;
}
if(k!=i)
{
ch=a[i];
a[i]=a[k];
a[k]=ch;
}
}
for(i=0;i<5;i++)
{
printf("%c",a[i]);
}
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<time.h>
#include<math.h>
struct student
{
int num;
float score[6];
}stu[10],*p;
int main()
{
srand((unsigned int)time(NULL));
int i;int j;
for(i=0;i<10;i++)
{
p=&stu[i];
p->num=i+1;
for(j=0;j<5;j++)
{
p->score[j]=rand()%50+50;
}
p->score[5]=(p->score[0]+p->score[1]+p->score[2]+p->score[3]+p->score[4])/5;
}
p=&stu[0];
printf("学号 成绩1 成绩2 成绩3 成绩4 成绩5 平均成绩\n");
for(i=0;i<10;i++)
{
p=&stu[i];
printf("%2d%8.1f%8.1f%8.1f%8.1f%6.1f%6.1f\n",p->num,p->score[0],p->score[1],p->score[2],p->score[3],p->score[4],p->score[5]);
}
void func1();
func1();
void func2();
func2();
void func3();
func3();
return 0;
}
void func1()
{
int i,j;
float averge=0,sum=0;
for(j=0;j<5;j++)
{
sum=0,averge=0;
for(i=0;i<10;i++)
{
p=&stu[i];
sum+=p->score[j];
}
averge=sum/10;
printf("第%d门课平均分是:%8.2f\n",j+1,averge);
}
}
void func2()
{
int i,j,t=0,m,n;
for(i=0;i<10;i++)
{
p=&stu[i];
for(j=0;j<5;j++)
{
if(p->score[j]>t)
{
t=p->score[j];
m=i;n=j;
}
}
}
printf("最高分数是%d位学生%d门课%d分\n",m+1,n+1,t);
}
void func3()
{
int i,j;
float s,s1=0,s2=0,averge=0;
for(i=0;i<10;i++)
{
p=&stu[i];
s1+=p->score[5]*p->score[5];
s2+=p->score[5];
}
s1=s1/10;
s2=pow((s2/10),2);
s=s1+s2;
printf("方差是:%f\n",s);
}
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main()
{
FILE *fp;
if((fp=fopen("result.dat","w"))==NULL)
{
printf("error!");
exit(0);
}
printf("请输入一个数:");
int n;
scanf("%d",&n);
int prism(int n);
if(prism(n))
{
printf("%d是素数\n",n);
}
else
{
printf("%d不是素数\n",n);
}
int i;
if(n%2==0)
{
for(i=1;i<=n/2;i++)
{
if(prism(i)&&prism(n-i))
{
printf("%d+%d=%d\n",i,n-i,n);
fprintf(fp,"%d+%d=%d\n",i,n-i,n);
}
}
}
fclose(fp);
return 0;
}
int prism(int n)
{
int i,flag=1;
for(i=2;i<n;i++)
{
if(n%i==0)return flag=0;
}
return flag;
}
2005
#include<stdio.h>
#include<math.h>
#include<string.h>
int main()
{
int a,b,c;
float x1,x2,t;
printf("请输入a,b,c:");
scanf("%d,%d,%d",&a,&b,&c);
if(a==0)
{
if(b==0)
{
if(c==0)
{
printf("no answer!");
}
else
{
printf("no answer!");
}
}
else if(c==0)
{
x1=0;x2=-c/a;
printf("x1=%f,%2=%f\n",x1,x2);
}
else
{
printf("no answer!");
}
}
else if(b==0)
{
if(c=0)
{
x1=x2=0;
printf("x1=%f,%2=%f\n",x1,x2);
}
else if(c<0)
{
printf("no answer!");
}
else if(c>=0)
{
x1=sqrt(-c/a);
x2=sqrt(c/a);
printf("x1=%f,%2=%f\n",x1,x2);
}
}
else if(c==0)
{
x1=0;x2=-b/a;
printf("x1=%f,%2=%f\n",x1,x2);
}
else
{
t=(b*b-4*a*c);
if(t<0)
{
printf("no answer!");
}
else
{
x1=((-b-sqrt(b*b-4*a*c))/2*a);
x2=((-b+sqrt(b*b-4*a*c))/2*a);
printf("x1=%f,%2=%f\n",x1,x2);
}
}
return 0;
}
#include "stdio.h"
#include "stdlib.h"
#include<string.h>
#include<math.h>
int main()
{
int a[3][3]={2,6,4,6,0,8,4,3,9};
int i,j,k,m,flag,h,l;;
for(i=0;i<3;i++)
{
k=a[i][0];flag=1;
for(j=0;j<3;j++)
{
if(a[i][j]>k)
{
k=a[i][j];
h=i;l=j;
}
}
for(m=0;m<3;m++)
{
if(a[m][l]>k)flag=0;
}
if(flag){
printf("第%d行%d列%d是鞍点\n",h+1,l+1,k);
}
}
return 0;
}
#include "stdio.h"
#include "stdlib.h"
#include<string.h>
#include<math.h>
int main()
{
float a[21], b[20];
a[0]=1;a[1]=2;
float s=0;
int i;
for(i=2;i<=20;i++)
{
a[i]=a[i-1]+a[i-2];
}
for(i=0;i<20;i++)
{
b[i]=a[i+1];
}
for(i=0;i<20;i++)
{
s+=b[i]/a[i];
}
printf("s=%.2f\n",s);
return 0;
}
#include<stdio.h>
#include<time.h>
#include<stdlib.h>
struct student
{
int num;
float score[6];
}stu[30],*p;
int main()
{
srand((unsigned int)time(NULL));
int i;int j;
for(i=0;i<30;i++)
{
p=&stu[i];
p->num=i+1;
for(j=0;j<5;j++)
{
p->score[j]=rand()%50+50;
}
p->score[5]=(p->score[0]+p->score[1]+p->score[2]+p->score[3]+p->score[4])/5;
}
p=&stu[0];
printf("学号 成绩1 成绩2 成绩3 成绩4 成绩5 平均成绩\n");
for(i=0;i<30;i++)
{
p=&stu[i];
printf("%2d%6.1f%6.1f%6.1f%6.1f%6.1f%6.1f\n",p->num,p->score[0],p->score[1],p->score[2],p->score[3],p->score[4],p->score[5]);
}
void func1();
func1();
void func3();
func3();
void fun2();
fun2();
return 0;
}
void func1()
{
int i,j;
float averge=0,sum=0;
for(i=1;i<30;i++)
{
p=&stu[i];
sum+=p->score[0];
}
averge=sum/30;
printf("第一门课平均分是:%8.2f\n",averge);
}
void func3()
{
printf("2门及以上不及格的学生:\n");
int i,j,t;
for(i=0;i<30;i++)
{
t=0;
p=&stu[i];
for(j=0;j<5;j++)
{
if(p->score[j]<60)t++;
}
if(t>=2)printf("%2d%6.1f%6.1f%6.1f%6.1f%6.1f%6.1f\n",p->num,p->score[0],p->score[1],p->score[2],p->score[3],p->score[4],p->score[5]);
}
}
void fun2()
{
printf("平均成绩90以上或者全部成绩85以上学生:\n");
int i,j,t;
float s,ave;
for(i=0;i<30;i++)
{
s=0;ave=0;t=0;
p=&stu[i];
for(j=0;j<5;j++)
{
s+=p->score[j];
if((p->score[j])>85)t++;
}
ave=s/5;
if(t==5||ave>90)printf("%2d%6.1f%6.1f%6.1f%6.1f%6.1f%6.1f\n",p->num,p->score[0],p->score[1],p->score[2],p->score[3],p->score[4],p->score[5]);
}
}
2006
#include<stdio.h>
int main()
{
float jia(float x,float y);
float pf(float x,float y);
float chu(float x,float y);
float x=1,y=100;
float s;
s=jia(x,100)+pf(1,100)+chu(1,100);
printf("%.2f",s);
return 0;
}
float jia(float x,float y)
{
float s=0;
int i;
for(i=x;i<=y;i++)
{
s+=i;
}
return s;
}
float pf(float x,float y)
{
float s=0;
int i;
for(i=x;i<=y;i++)
{
s+=i*i;
}
return s;
}
float chu(float x,float y)
{
float s=0;
int i;
for(i=x;i<=y;i++)
{
s+=1/i;
}
return s;
}
2
#include<stdio.h>
int main()
{
int i;
int g,s,b;
for(i=100;i<1000;i++)
{
g=i%10;
s=i/10%10;
b=i/100;
if((g*g*g+s*s*s+b*b*b)==i)
{
printf("%d是水仙花数\n");
}
}
return 0;
}
3
#include<stdio.h>
int main()
{
int a[4]={0};
int i,count=0;
scanf("%d",&i);
while(i!=-1)
{
if(i==1)
{
a[0]++;
count++;
}
else if(i==2)
{
a[1]++;count++;
}
else if(i==3)
{
a[2]++;count++;
}
else if(i==4)
{
a[3]++;count++;
}
scanf("%d",&i);
}
for(i=0;i<4;i++)
{
printf("%d:%d\n",i+1,a[i]);
if(a[i]>count/2)
{
printf("%d当选\n",i+1);
}
}
return 0;
}
4
#include<stdio.h>
#include<string.h>
int main()
{
int i,j,k;
char ch;
printf("请输入一个大写字母:");
ch=getchar();
k=ch-64;
for(i=1;i<=k;i++)
{
for(j=k-i;j>0;j--)
{
printf(" ");
}
for(j=1;j<=2*i-1;j++)
{
printf("%c",64+i);
}
printf("\n");
}
for(i=1;i<k;i++)
{
for(j=1;j<=i;j++)
{
printf(" ");
}
for(j=1;j<2*(k-i);j++)
{
printf("%c",ch-i);
}
printf("\n");
}
return 0;
}
2007
#include "stdio.h"
#include "stdlib.h"
int main()
{
char ch;
printf("请输入一个小写字母:");
scanf("%c",&ch);
ch=ch-32;
printf("相应的大写字母是:%c\n",ch);
return 0;
}
2
#include "stdio.h"
#include "stdlib.h"
int main()
{
int n;
float x,s;
scanf("%d,%f",&n,&x);
float pnx(int n,float x);
printf("%f\n",pnx(n,x));
return 0;
}
float pnx(int n,float x)
{
float s;
if(n==0)s=1;
else if(n==1)s=x;
else s=((2*n-1)*x*pnx(n-1,x)-(n-1)*pnx(n-2,x))/n;
return s;
}
3
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i,j,k;
for(i=1;i<=1000;i++)
{
k=0;
for(j=1;j<i;j++)
{
if((i%j)==0)
{
k+=j;
}
}
if(i==k)
{
printf("%d是完数\n",i);
}
}
return 0;
}
4
#include<math.h>
#include<stdio.h>
int main()
{
float h=100,s=100;
for(int i=1;i<10;i++)
{
h=h/2;
s+=h*2;
}
printf("%f %f",s,h);
return 0;
}
5
#include "stdio.h"
#include "stdlib.h"
#include<string.h>
int main()
{
char s[50]={"A123x456$%/1789>3560tab587"},*p=s;
printf("statistic:");
void statistic(char *p);
statistic(p);
return 0;
}
void statistic(char *p)
{
int a[10];
int i=0,j=0,b=0;
for(i=0;*(p+i)!='\0';i++)
{
if(*(p+i)>='0'&&*(p+i)<='9')
{
b=*(p+i)-'0'+b*10;
if(*(p+i+1)>'9'||*(p+i+1)<'0')
{
a[j]=b;
j++;
b=0;
}
}
}
printf("The sum is:");
for(int k=0;k<j;k++)
{
printf("%-6d",a[k]);
}
}
2008
#include "stdio.h"
#include "stdlib.h"
int main()
{
int num,k=0,a[5];
do
{
printf("the original num is:");
scanf("%d",&num);
}while(num<0||num>99999);
printf("逆序:");
while(num)
{
a[k++]=num%10;
printf("%-2d",num%10);
num/=10;
}
printf("正序:");
k--;
while(k>=0)
{
printf("%-2d",a[k--]);
}
return 0;
}
2
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i;
int g, s, b;
for(i=100;i<1000;i++)
{
g = i%10;
s = i/10%10;
b = i/100;
if(i==(g*g*g+s*s*s+b*b*b))
{
printf("%d is 水仙花数\n",i);
}
}
return 0;
}
省事儿就写了两个学生三门课程
#include "stdio.h"
#include "stdlib.h"
int main()
{
void pjf(float a[2][3]);
void kepjf(float a[2][3]);
void zgfs(float a[2][3]);
void pjfc(float a[2][3]);
float a[2][3] = {90.6, 70, 80, 60.4, 99, 98};
pjf(a);
kepjf(a);
zgfs(a);
pjfc(a);
return 0;
}
void pjf(float a[2][3])
{
int i, j;
float s = 0;
for(i = 0; i < 2; i++)
{
s = 0;
for(j = 0; j < 3; j++)
{
s += a[i][j];
}
printf("第%d平均分是:%f\n", i + 1, s/3);
}
}
void kepjf(float a[2][3])
{
int i, j;
float s = 0;
for(i = 0; i < 3; i++)
{
s = 0;
for(j = 0; j < 2; j++)
{
s = s + a[j][i];
}
printf("第%d每门课的平均分是:%f\n", i + 1, s/2);
}
}
void zgfs(float a[2][3])
{
int i, j, m, n;
float s = 0;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 2; j++)
{
if(a[i][j] > s)
{
s = a[i][j];
m = i + 1;
n = j + 1;
}
}
}
printf("第%d个课最高分是第%d个学生%.2f分\n", m, n, s);
}
void pjfc(float a[2][3])
{
float p = 0;
int i, j;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 2; j++)
{
p += a[i][j];
}
}
p/= 3;
float s = 0;
for(i = 0; i < 3; i++)
{
for(j = 0; j < 2; j++)
{
s += (a[i][j] - p) *(a[i][j] - p);
}
}
s = s/(i*j);
printf("方差是%f\n", s);
}
4
#include "stdio.h"
#include "stdlib.h"
int main()
{
int a[3][3] = {1, 12, 3, 4, 5, 2, 7, 18, 6 };
int flag = 1;
int i, j, d[3] = {0}, m[3] = {0}, n[3] = {0};
for(i=0;i<3;i++)
{
for(j=0;j<3;j++)
{
printf("%3d",a[i][j]);
}
printf("\n");
}
printf("*************************************\n");
for(i = 0; i < 3; i++)
{
for(j = 0; j < 3; j++)
{
if(a[i][j] > d[i])
{
d[i] = a[i][j];
m[i] = i;
n[i] = i;
}
}
}
for(i = 0; i < 3; i++)
{
flag = 1;
for(j = 0; j < 3; j++)
{
if(a[j][i] > d[i]) flag = 1;
else flag = 0;
}
if(flag)
{
printf("第 %d 行 %d 列 数字 %d 是鞍点\n", m[i]+1,n[i]+1,d[i]);
}
}
return 0;
}
2009
#include<stdio.h>
#include<math.h>
int main()
{
float p;
float pn(int n,float x);
printf("%.2f\n",pn(5,2.4));
return 0;
}
float pn(int n,float x)
{
float s;
if(n==0)s=1;
else if(n==1)s=x;
else s=((2*n-1)*x*pn(n-1,x)-(n-1)*pn(n-2,x))/n;
return s;
}
2
#include<math.h>
#include<stdio.h>
int main()
{
float i=1;
float k=-1;
float s=1;
float m=1;
while(fabs(m)>1e-6)
{
i=i + 2;
m=1/i;
s=s+(k*m);
k=-k;
}
printf("派的值为:%f\n",4*s);
return 0;
}
3
#include<math.h>
#include<stdio.h>
int main()
{
float h=100,s=100;
for(int i=1;i<10;i++)
{
h=h/2;
s+=h*2;
}
printf("%f %f",s,h);
return 0;
}
4
#include<math.h>
#include<stdio.h>
#define N 20
int main()
{
int i=N-1,j=0,k=1;
int a[N][N];
a[N-1][0]=k++;
while(k<=N*N)
{
if(i==0)j++;
else i--;
for(;i<N&&j<N;i++,j++)
{
a[i][j]=k++;
}
i--;j--;
if(j==N-1)i--;
else j++;
for(;i>=0&&j>=0;i--,j--)
{
a[i][j]=k++;
}
i++;j++;
}
for(i=0;i<=N-1;i++)
{
for(j=0;j<N;j++)
{
printf("%5d",a[i][j]);
}
printf("\n");
}
return 0;
}
2014
#include "stdio.h"
#include "stdlib.h"
int main()
{
float hermite(int n,float x);
int n; float x;
scanf("%d,%f", &n, &x);
printf("%.2f\n", hermite(n, x));
return 0;
}
float hermite(int n,float x)
{
float h;
if(n==0) h=1;
else if(n==1) h=2*x;
else if(n>1) h= 2*x*hermite(n-1,x)-2*(n-1)*hermite(n-2,x);
return h;
}
2
#include "stdio.h"
#include "stdlib.h"
#include<math.h>
int main()
{
float n=1;
float x=0, y=1;
while(fabs(y-x)>=1e-6)
{
x = y;
y = pow((1+1/n),n);
n += 1;
}
printf("e:%.6fn:%.1f\n",y,n);
return 0;
}
3
#include "stdio.h"
#include "stdlib.h"
#include<math.h>
#define N 3
struct student
{
int id;
char name[10];
float grade[4];
}stu[N],*p,temp;
int main()
{
int i=0;
FILE *fp;
if((fp=fopen("student.dat","w"))==NULL)
{
printf("error");
exit(0);
}
do
{
p=&stu[i];
p->id=i+1;
printf("输入第%d个学生的姓名:",i+1);
scanf("%s",&p->name);
printf("输入第%d个学生的语数英成绩:",i+1);
scanf("%f,%f,%f",&p->grade[0],&p->grade[1],&p->grade[2]);
p->grade[3]=p->grade[0]+p->grade[1]+p->grade[2];
i++;
printf("*********************************\n");
}while(i<N);
for(int i=0;i<N-1;i++)
{
int k=i;
for(int j=i+1;j<N;j++)
{
if(stu[j].grade[3]>stu[k].grade[3])
{
k=j;
}
if(i!=k)
{
temp=stu[k];
stu[k]=stu[i];
stu[i]=temp;
}
}
}
i=0;
do
{
p=&stu[i];
fwrite(p,sizeof(struct student),1,fp);
printf("%-6d%-15s%-6.1f%-6.1f%-6.1f%-6.1f",p->id,p->name,p->grade[0],p->grade[1],p->grade[2],p->grade[3]);
for(int j=0;j<=i;j++)
{
if(stu[j].grade[3]==stu[i].grade[3])
{
fprintf(fp,"%6d\n",j+1);
printf("%6d\n",j+1);
break;
}
else
{
fprintf(fp,"%6d\n",i+1);
printf("%6d\n",i+1);
break;
}
}
i++;
} while(i<N);
fclose(fp);
return 0;
}
2015
#include "stdio.h"
#include "stdlib.h"
int main()
{
int n;
int fbqn(int n);
int i, j, sum = 0,s=0;
FILE *fp;
if((fp=fopen("fab.txt", "w")) == NULL)
{
printf("file open error!\n");
exit(0);
}
for(i = 1; i <= 20; i++)
{
sum = fbqn(i);
printf("f(%d)=%d\n",i,sum);
fprintf(fp,"%d\n",sum);
s+=sum;
}
printf("f(%d)=%d\n",i,s);
fclose(fp);
return 0;
}
int fbqn(int n)
{
int f=0;
if(n==1||n==2) f=1;
else if(n>2) f=fbqn(n-1)+fbqn(n-2);
return f;
}
2
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i;
int g, s, b, w,q, n;
for(i = 30; ; i++)
{
n = i*i;
if(n >= 1000&&n < 10000)
{
g = n % 10;
q = n/1000;
b = n/100 % 10;
s = n % 100/10;
if((b ==q) &&(s ==g))
{
printf("车牌号是:%d\n", n);
}
}
}
return 0;
}
3.不会了 书上有
2016
1.感觉有点啰嗦但是很完整滴
#include "stdio.h"
#include "stdlib.h"
#include<string.h>
#include<math.h>
int main()
{
FILE *fp;
if((fp=fopen("Coefficient.txt","r"))==NULL)
{
printf("error");
exit(0);
}
int arr[10][3];
static int i=0;
char ch=fgetc(fp);
while(!feof(fp))
{
static int j=0;
if(ch>='0'&&ch<='9')
{
arr[i][j]=ch-'0';
j++;
}
if(ch=='\r'||ch=='\n')
{
i++;j++;
}
ch=fgetc(fp);
}
printf("系数矩阵是:");
putchar(10);
for(int i1=0;i1<=i;i1++)
{
for(int j=0;j<3;j++)
{
printf("%-3d",arr[i][j]);
}
putchar(10);
}
int a,b,c;
float x1,x2,t;
for(int m=0;m<=i;m++)
{
a=arr[m][0];b=arr[m][1];c=arr[m][2];
if(a==0)
{
if(b==0)
{
if(c==0)
{
printf("no answer!");
fprintf(fp,"%s\n","no answer!");
continue;
}
else
{
printf("no answer!");
fprintf(fp,"%s\n","no answer!");
continue;
}
}
else if(c==0)
{
x1=0;x2=-c/a;
fprintf(fp,"%f %f\n",x1,x2);
continue;
}
else
{
printf("no answer!");
fprintf(fp,"%s\n","no answer!");
continue;
}
}
else if(b==0)
{
if(c=0)
{
x1=x2=0;
fprintf(fp,"%f %f\n",x1,x2);
continue;
}
else if(c<0)
{
printf("no answer!");
fprintf(fp,"%s\n","no answer!");
continue;
}
else if(c>=0)
{
x1=sqrt(-c/a);
x2=sqrt(c/a);
fprintf(fp,"%f %f\n",x1,x2);
continue;
}
}
else if(c==0)
{
x1=0;x2=-b/a;
fprintf(fp,"%f %f\n",x1,x2);
continue;
}
else
{
t=(b*b-4*a*c);
if(t<0)
{
printf("no answer!");
fprintf(fp,"%s\n","no answer!");
continue;
}
else
{
x1=((-b-sqrt(b*b-4*a*c))/2*a);
x2=((-b+sqrt(b*b-4*a*c))/2*a);
fprintf(fp,"%f %f\n",x1,x2);
continue;
}
}
}
loop:fclose(fp);
return 0;
}
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
struct student
{
int num;
float score[6];
}stu[30]={0},*p;
int main()
{
srand((unsigned)int(NULL));
int i,j,k;
for(i=0;i<30;i++)
{
k=i;
p=&stu[i];
p->num=++k;
for(j=0;j<5;j++)
{
p->score[j]=rand()%50+50;
p->score[5]+=p->score[j];
}
}
printf("学号 成绩1 成绩2 成绩3 成绩4 成绩5 总分\n");
for(i=0;i<30;i++)
{
p=&stu[i];
printf("%2d ",p->num);
for(j=0;j<6;j++)
{
printf("%8.2f",p->score[j]);
}
printf("\n");
}
struct student temp;
for(i=0;i<29;i++)
{
k=i;
for(j=i+1;j<30;j++)
{
if(stu[k].score[5]<stu[j].score[5])
{
k=j;
}
}
if(k!=i)
{
temp=stu[i];
stu[i]=stu[k];
stu[k]=temp;
}
}
printf("前十名的成绩是:\n");
for(i=0;i<10;i++)
{
p=&stu[i];
printf("%2d ",p->num);
for(j=0;j<6;j++)
{
printf("%8.2f",p->score[j]);
}
printf("\n");
}
if(stu[9].score[5]==stu[10].score[5])
{
printf("10 ");
for(j=0;j<6;j++)
{
printf("%8.2f",stu[10].score[j]);
}
printf("\n");
}
for(i=0;i<30;i++)
{
p=&stu[i];
for(j=0;j<5;j++)
{
if(p->score[j]<80)
{
printf("学号为%d的同学第%d门功课为%.2f低于80分\n",p->num,j+1,p->score[j]);
}
}
}
return 0;
}
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<time.h>
int main()
{
int n,k;
int cnk(int n,int k);
printf("请输入n,k:");
scanf("%d,%d",&n,&k);
printf("%d\n",cnk(n,k));
return 0;
}
int cnk(int n,int k)
{
int s;
if(n==k||k==0)
{
s=1;
}
else
{
s=cnk(n-1,k-1)+cnk(n-1,k);
}
return s;
}
2017
1
#include "stdio.h"
#include "stdlib.h"
int main()
{
float qb(int n, float x);
int n, i;
float x,sum;
printf("请输入n,x:");
scanf("%d,%f", &n,&x);
FILE *fp;
if((fp = fopen("tdat.txt","w")) == NULL)
{
printf("error");
exit(0);
}
for(i = 0; i <= n; i++)
{
sum = qb(i, x);
printf("T%d(%.2f)=%.2f\n",i,x,sum);
fprintf(fp,"T%d(%.2f)=%.2f\n",i,x,sum);
}
fclose(fp);
return 0;
}
float qb(int n,float x)
{
float s;
if(n == 0) s = 1;
else if(n==1) s = x;
else if(n>=2) s = (2*x*qb(n-1,x)- qb(n-2,x));
return s;
}
2
#include "stdio.h"
#include "stdlib.h"
int main()
{
int a,b,t;
char c;
printf("输入算式:");
scanf("%d%c%d",&a,&c,&b);
printf("%d%c%d=",a,c,b);
switch(c)
{
case'+':t=a+b;break;
case'-':t=a-b;break;
case'*':t=a*b;break;
case'/':
if(b==0)
{
printf("\n0不能为分母! "); return 0;
}
t=a/b;break;
case '%':t=a%b; break;
default:
printf("请输入合法的双目算术运算符!");return 0;
}
printf("%d",t);
return 0;
}
3
#include "stdio.h"
#include "stdlib.h"
int main()
{
int a[5][5]={{11,4,2,7,8},{5,9,23,1,25},{3,22,21,18,15},{17,16,24,12,6},{13,10,19,20,14}};
int i, j;
int k;
int m, n,flag=1;
for(i = 0; i < 5; i++)
{
flag=1;
k = a[i][0]; m = i; n = 0;
for(j = 1; j < 5; j++)
{
if(a[i][j] < k)
{
k = a[i][j];
m = i; n = j;
}
}
for(j = 0; j < 5; j++)
{
if(a[j][n] < k)
{
flag=0;
}
}
if(flag)printf("%d(%d,%d) ", k, m+1, n+1);
}
return 0;
}
2018
#include "stdio.h"
#include "stdlib.h"
#include"math.h"
int main()
{
int a, b, c;
int i;
float t;
FILE *fp;
if((fp = fopen("data.txt", "w")) == NULL)
{
printf("error");
exit(0);
}
for(i=0;i<10;i++)
{
printf("请输入第%d组a, b, c:", i);
scanf("%d,%d,%d", &a,&b,&c);
float hs(int a,int b,int c);
t = hs(a, b, c);
printf("T%d:%f\n",i,t);
fprintf(fp,"%d,%d,%d,%f\n",a,b,c,t);
}
fclose(fp);
return 0;
}
float hs(int a,int b,int c)
{
float t;
t = ((4.25*(a+b)+log(a+b+sqrt(a+b)+1/(a+b)))/(4.25*c + log(c + sqrt(c) + 1/c)));
return t;
}
#include "stdio.h"
#include "stdlib.h"
int main()
{
int n;
printf("请输入一个自然数:");
scanf("%d", &n);
int m[10], i = 0, j, flag = 1, k;
while(n!= 0)
{
m[i++] = n % 10;
for(j = 0; j < i-2; j++)
{
for(k = 1; k < i-1; k++)
{
if(m[j] > m[k])
{
flag = 0;
if(flag==0)
{
printf("不是降序数");
return 0;
}
}
}
}
n = n/10;
}
if(flag == 1) printf("是降序数");
return 0;
}
3
#include "stdio.h"
#include "stdlib.h"
#include"math.h"
int main()
{
float fx(float x);
float f2x(float x);
float x = - 1, y = 0;
while(fabs(x - y) > 1e - 6)
{
y = x;
x = x - fx(x) /f2x(x);
}
printf("%f\n", x);
return 0;
}
float fx(float x)
{
float f;
f = pow(x, 41) + pow(x, 3) + 1;
return f;
}
float f2x(float x)
{
float f;
f = 41*pow(x, 40) + 2*pow(x, 2);
return f;
}
2019
1
#include "stdio.h"
#include "stdlib.h"
int main()
{
int x, n;
printf("请输入x,n的值:");
scanf("%d,%d", &x, &n);
int xn(int x, int n);
int s;
s = xn(x, n);
printf("%d的%d次方是%d\n", x, n, s);
return 0;
}
int xn(int x,int n)
{
int s;
if(n == 1)
{
s = x;
}
else if(n > 1)
{
s = x*xn(x, n - 1);
}
return s;
}
2
#include "stdio.h"
#include "stdlib.h"
int main()
{
int i,j,k,a[52],count=0;
for(i=0;i<52;i++)
{
a[i]=(i+4)/4;
}
for(i=1;i<52;i++)
{
k=i+1;
for(j=i;j<52&&a[j]!=-1;j++)
{
if(a[j]%k==0)
{
a[j]=-1;
}
}
}
for(j=0;j<52&&a[j]!=-1;j++)
{
count++;
}
printf("%d\n",count);
return 0;
}
#include "stdio.h"
#include "stdlib.h"
int main()
{
FILE *fp;
if((fp=fopen("a1","w"))==NULL)
{
printf("error");
exit(0);
}
int ss(int n);
for(int i=2;i<=298;i++)
{
if(ss(i)&&ss(i+2))
{
fprintf(fp,"%d %d\n",i,i+2);
printf("%d %d\n",i,i+2);
}
}
fclose(fp);
return 0;
}
int ss(int n)
{
int i;
int flag=1;
for(i=2;i<n;i++)
{
if(n%i==0)
{
return flag=0;
}
}
return flag=1;
}
|