姓名:李荣洽
学号:2018510441
#include
int main()
{
printf("This is a C program.\n");
return 0;
}
#include
int main()
{
int a,b,sum;
a=123;
b=456;
sum=a+b;
printf("sum is %d\n",sum);
return 0;
}
#include
int main()
{
int max(int x,int y);
int a,b,c;
scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max=%d\n",c);
return 0;
}
int max(int x,int y)
{
int z;
if(x>y)z=x;
else z=y;
return (z);
}
#include
int main()
{
int i,j=1;
for(i=1;i<=5;i++)
{
j*=i;
}
printf("%d\n",j);
return 0;
}
#include
int main()
{
int i;
int No[50],Score[50];
for(i=0;i<50;i++)
{
printf("请输入第%d个学生的学号和成绩\n",i+1);
scanf("%d %d",&No[i],&Score[i]);
}
printf("成绩高于80分的学生的学号是:\n");
for(i=0;i<50;i++)
{
if(Score[i]>80)
{
printf("%d ",No[i]);
}
}
return 0;
}
#include
int main()
{
int i;
for(i=2000;i<=2500;i++)
{
if(i%4==0&&i%100!=0||i%400==0)
{
printf("%d年是闰年 ",i);
}
else
printf("%d年不是闰年 ",i);
if(i%5==0)
{
printf("\n");
}
}
return 0;
}
#include
int main()
{
double t=1;
int i;
for(i=2;i<=50;i++)
{
if(i%2==0)
{
t+=-1*(1.0/i);
}
else
{
t+=1.0/i;
}
}
printf("%lf\n",t);
return 0;
}
#include
int main()
{
int i,t,n;
scanf("%d",&n);
for(t=1,i=2;i<n;i++)
if(n%i==0)
t=0;
if(t)
printf("%d是素数\n",n);
else
printf("%d不是素数\n",n);
return 0;
}
#include
int main()
{
float f,c;
f=64.0;
c=(5.0/9)*(f-32);
printf("f=%f\nc=%f\n",f,c);
return 0;
}
在这里插入图片描述
#include
int main()
{
float p0=1000,r1=0.0036,r2=0.0225,r3=0.0198,p1,p2,p3;
p1=p0*(1+r1);
p2=p0*(1+r2);
p3=p0*(1+r3/2)*(1+r3/2);
printf("p1=%f\np2=%f\np3=%f\n",p1,p2,p3);
return 0;
}
#include
int mian()
{
char c1,c2;
c1='A';
c2=c1+32;
printf("%c\n",c2);
printf("%d\n",c2);
return 0;
}
去博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片
.
// An highlighted block
var foo = 'bar';
#include
#include
int main()
{
double a,b,c,s,area;
a=3.67;
b=5.43;
c=6.21;
s=(a+b+c)/2;
area=sqrt(s*(s-a)*(s-b)*(s-c));
printf("a=%f\tb=%f\tc=%f\n",a,b,c);
printf("area=%f\n",area);
return 0;
}
#include
#include
int main()
{
double a,b,c,disc,x1,x2,p,q;
scanf("%lf%lf%lf",&a,&b,&c);
disc=b*b-4*a*c;
p=-b/(2.0*a);
q=sqrt(disc)/(2.0*a);
x1=p+q;x2=p-q;
printf("x1=%7.2f\nx2=%7.2f\n",x1,x2);
return 0;
}
#include
int main()
{
double a=1.0;
printf("%lf\n",a/3);
return 0;
}
#include
int main()
{
double a;
a=10000/3.0;
printf("%lf\n",a);
return 0;
}
#include
int main()
{
char a='B',b='O',c='Y';
putchar(a);
putchar(b);
putchar(c);
putchar('\n');
return 0;
}
#include
int main()
{
char a,b,c;
a=getchar();
b=getchar();
c=getchar();
putchar(a);
putchar(b);
putchar(c);
putchar('\n');
return 0;
}
#include
int main()
{
char c1,c2;
c1=getchar();
c2=c1+32;
putchar(c2);
putchar('\n');
return 0;
}
#include
#include
int main()
{
double a,b,c,disc,x1,x2,p,q;
scanf("%lf%lf%lf",&a,&b,&c);
disc=b*b-4*a*c;
if(disc<0)
printf("this equation has not real roots\n");
else
{
p=-b/(2.0*a);
q=sqrt(disc)/(2.0*a);
x1=p+q;
x2=p-q;
printf("real roots:\nxl=%7.2f\nx2=%7.2f\n",x1,x2);
}
return 0;
}
#include
int main()
{
float a,b,t;
scanf("%f,%f",&a,&b);
if(a>b)
{
t=a;
a=b;
b=t;
}
printf("%5.2f,%5.2f\n",a,b);
return 0;
}
#include
int main()
{
float a,b,c,t;
scanf("%f,%f,%f",&a,&b,&c);
if(a>b)
{
t=a;
a=b;
b=t;
}
if(a>c)
{
t=a;
a=c;
c=t;
}
if(b>c)
{
t=b;
b=c;
c=t;
}
printf("%5.2f,%5.2f,%5.2f\n",a,b,c);
return 0;
}
#include
int main()
{
char ch;
scanf("%c",&ch);
ch=(ch>='A'&&ch<='Z')?(ch+32):ch;
printf("%c\n",ch);
return 0;
}
#include
int main()
{
char grade;
scanf("%c",&grade);
printf("your score");
switch(grade)
{
case'A':printf("85~100\n");break;
case'B':printf("70~84\n");break;
case'C':printf("60~69\n");break;
case'D':printf("<60\n");break;
default:printf("enter data error!\n");
}
return 0;
}
#include
int main()
{
void action1(int,int),action2(int,int);
char ch;
int a=15,b=23;
ch=getchar();
switch(ch)
{
case'a':
case'A':action1(a,b);break;
case'b':
case'B':action2(a,b);break;
default:putchar('\a');
}
return 0;
}
void action1(int x,int y)
{
printf("x+y=%d\n",x+y);
}
void action2(int x,int y)
{
printf("x*y=%d\n",x*y);
}
#include
int main()
{
int year,leap;
printf("enter year:");
scanf("%d",&year);
if(year%4==0)
{
if(year%100==0)
{
if(year%400==0)
leap=1;
else
leap=0;
}
else
leap=1;
}
else
leap=0;
if(leap)
printf("%d is ",year);
else
printf("%d is not ",year);
printf("a leap year.\n");
return 0;
}
#include
#include
int main()
{
double a,b,c,disc,x1,x2,realpart,imagpart;
scanf("%lf,%lf,%lf",&a,&b,&c);
printf("the equation");
if(fabs(disc)<=1e-6)
printf("is not a quadratic\n");
else
{
disc=b*b-4*a*c;
if(fabs(disc)<=1e-6)
printf("has two equal roots:%8.4f\n",-b/(2*a));
else
if(disc>1e-6)
{
x1=(-b+sqrt(disc)/(2*a));
x2=(-b-sqrt(disc)/(2*a));
printf("has distinct real roots:8.4f and %8.4f\n",x1,x2);
}
else
{
realpart=-b/(2*a);
imagpart=sqrt(-disc)/(2*a);
printf("has complex roots:\n");
printf("%8.4f+%8.4fi\n",realpart,imagpart);
printf("%8.4f-%8.4fi\n",realpart,imagpart);
}
}
return 0;
}
#include
int main()
{
int i=1,sum=0;
while(i<=100)
{
sum=sum+i;
i++;
}
printf("sum=%d\n",sum);
return 0;
}
![在这里插入图片描述](https://img-blog.csdnimg.cn/20190221163222300.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L2JyaWdodF93b3Jk,size_16,color_FFFFFF,t_70)
#include
int main()
{
int i,sum=0;
printf("please enter i,i=?");
scanf("%d",&i);
while(i<=10)
{
sum=sum+i;
i++;
}
printf("sum=%d\n",sum);
return 0;
}
#include
int main()
{
int i,sum=0;
printf("please enter i,i=?");
scanf("%d",&i);
do
{
sum=sum+i;
i++;
}
while(i<=10);
printf("sum=%d\n",sum);
return 0;
}
#include
#define SUM 100000
int main()
{
float amount,aver,total;
int i;
for(i=1,total=0;i<=1000;i++)
{
printf("please enter amount:");
scanf("%f",&amount);
total=total+amount;
if(total>=SUM)break;
}
aver=total/i;
printf("num=%d\naver=%10.2f\n",i,aver);
return 0;
}
#include
int main()
{
int n;
for(n=100;n<=200;n++)
{
if(n%3==0)
continue;
printf(" %d",n);
}
printf("\n");
return 0;
}
#include
int main()
{
int i,j,n=0;
for(i=1;i<=4;i++)\
for(j=1;j<=5;j++,n++)
{
if(n%5==0)printf("\n");
printf("%d\t",i*j);
}
printf("\n");
return 0;
}
#include
#include
int main()
{
int sign=1;
double pi=0.0,n=1.0,term=1.0;
while (fabs(term)>=1e-6)
{
pi=pi+term;
n=n+2;
sign=-sign;
term=sign/n;
}
pi=pi*4;
printf("pi=%10.8f\n",pi);
return 0;
}
#include
int main()
{
int f1=1,f2=1,f3;
int i;
printf("%12d\n%12d\n",f1,f2);
for(i=1;i<=38;i++)
{
f3=f1+f2;
printf("%12d\n",f3);
f1=f2;
f2=f3;
}
return 0;
}
#include
int main()
{
int n,i;
printf("please enter a integer number ,n=?");
scanf("%d",&n);
for(i=2;i<n;i++)
if(n%i==0)break;
if(i<n)printf("%d is not a prime number .\n",n);
else printf("%d is a prime number.\n",n);
return 0;
}
#include
int main()
{
int i,a[10];
for(i=0;i<=9;i++)
a[i]=i;
for(i=9;i>=0;i--)
printf("%d",a[i]);
printf("\n");
return 0;
}
#include
int main()
{
int i;
int f[20]={1,1};
for(i=2;i<=20;i++)
f[i]=f[i-2]+f[i-1];
for(i=0;i<20;i++)
{
if(i%5==0)printf("\n");
printf("%12d",f[i]);
}
printf("\n");
return 0;
}
#include
int main()
{
int a[10];
int i,j,t;
printf("input 10 numbers :\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\n");
for(j=0;j<9;j++)
for(i=0;i<9-j;i++)
if(a[i]>a[i+1])
{
t=a[i];a[i]=a[i+1];a[i+1]=t;
}
printf("the sorted number s:\n");
for(i=0;i<10;i++)
printf("%5d", a[i] );
printf("\n");
return 0;
}
#include
int main()
{
int a[2][3]={{1,2,3},{4,5,6}};
int b[3][2],i,j;
printf("array a:\n");
for(i=0;i<=1;i++)
{
for(j=0;j<=2;j++)
{
printf("%5d",a[i][j]);
b[j][i]=a[i][j];
}
printf("\n");
}
printf("array b:\n");
for(i=0;i<=2;i++)
{
for(j=0;j<=1;j++)
printf("%5d",b[i][j]);
printf("\n");
}
return 0;
}
#include
int main()
{
char c[15]={'i',' ','a','m',' ','a',' ','s','t','u','d','e','n','t','.'};
int i;
for (i=0;i<15;i++)
printf("%c",c[i]);
printf("\n");
return 0;
}
#include
int main()
{
char diamond[][5]={{' ',' ','*'},{' ','*',' ','*'},{'*',' ',' ',' ','*'},{' ','*',' ','*'},{' ',' ','*'}};
int i,j;
for(i=0;i<5;i++)
{
for(j=0;j<5;j++)
printf("%c",diamond[i][j]);
printf("\n");
}
return 0;
}
#include
int main()
{
char string[81];
int i,num=0,word=0;
char c;
gets(string);
for(i=0;(c=string[i])!='\0';i++)
if(c==' ')word=0;
else if(word==0)
{
word=1;
num++;
}
printf("there are %d words in this line.\n",num);
return 0;
}
#include
#include
int main()
{
char str[3][20];
char string[20];
int i;
for(i=0;i<3;i++)
gets(str[i]);
if (strcmp(str[0],str[1])>0)
strcpy(string,str[0]);
else
strcpy(string,str[1]);
if(strcmp(str[2],string)>0)
strcpy(string,str[2]);
printf("\nthe largest is:\n%s\n",string);
return 0;
}
#include
#include
int main()
{
void print_star();
void print_message();
print_star();
print_message();
print_star();
return 0;
}
void print_star()
{
printf("**********\n");
}
void print_message()
{
printf("how do you do!\n");
}
int max(int x,int y)
{
int z;
z=x>y?x:y;
return (z);
}
#include
int main()
{
int max(int x,int y);
int a,b,c;
printf("please enter two inteter numbers:");
scanf("%d,%d",&a,&b);
c=max(a,b);
printf("max is %d\n",c);
return 0;
}
#include
int main()
{
int max(float x,float y);
float a,b;
int c;
scanf("%f,%f",&a,&b);
c=max(a,b);
printf("max is %d\n",c);
return 0;
}
int max(float x,float y)
{
float z;
z=x>y?x:y;
return(z);
}
#include
int main()
{
float add(float x,float y);
float a,b,c;
printf("please enter a and b:");
scanf("%f,%f",&a,&b);
c=add(a,b);
printf("sum is %f\n",c);
return 0;
}
float add(float x,float y)
{
float z;
z=x+y;
return (z);
}
#include
int main()
{
int max4(int a,int b,int c,int d);
int a,b,c,d,max;
printf("please enter 4 interger numbers:");
scanf("%d%d%d%d",&a,&b,&c,&d);
max=max4(a,b,c,d);
printf("max=%d\n",max);
return 0;
}
int max4(int a,int b,int c,int d)
{
int max2(int a,int b);
int m;
m=max2(a,b);
m=max2(m,c);
m=max2(m,d);
return (m);
}
int max2(int a,int b)
{
if(a>=b)
return a;
else
return b;
}
#include
int main()
{
int age(int n);
printf("no.5,age:%d\n",age(5));
return 0;
}
int age(int n)
{
int c;
if(n==1)
c=10;
else
c=age(n-1)+2;
return (c);
}
#include
int main()
{
int fac(int n);
int n;
int y;
printf("input an integer number:");
scanf("%d",&n);
y=fac(n);
printf("%d!=%d\n",n,y);
return 0;
}
int fac(int n)
{
int f;
if(n<0)
printf("n<0,data error!");
else if (n==0||n==1)
f=1;
else f=fac(n-1)*n;
return (f);
}
#include
int main()
{
void hanoi(int n,char one,char two,char three);
int m;
printf("input the number of diskes:");
scanf("%d",&m);
printf("the step to move %d diskes:\n",m);
hanoi(m,'A','B','C');
}
void hanoi(int n,char one ,char two,char three)
{
void move(char x,char y);
if(n==1)
move(one,three);
else
{
hanoi(n-1,one,three,two);
move(one,three);
hanoi(n-1,two,one,three);
}
}
void move(char x,char y)
{
printf("%c-->%c\n",x,y);
}
#include
int main()
{
int max(int x,int y);
int a[10],m,n,i;
printf("enter 10 integer numbers:");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
printf("\n");
for(i=1,m=a[0],n=0;i<10;i++)
{
if(max(m,a[i])>m)
{m=max(m,a[i]);
n=i;
}
}
printf("the lagest number is %d\nit is the %dth number.\n",m,n+1);
}
int max(int x,int y)
{
return (x>y?x:y);
}
#include
int main()
{
float average(float array[10]);
float score[10],aver;
int i;
printf("input 10 score:\n");
for(i=0;i<10;i++)
scanf("%f",&score[i]);
printf("\n");
aver=average(score);
printf("average score is %5.2f\n",aver);
return 0;
}
float average(float array[10])
{
int i;
float aver ,sum=array[0];
for(i=1;i<10;i++)
sum=sum+array[i];
aver=sum/10;
return(aver);
}
#include
int main()
{
float average(float array[],int n);
float score1[5]={98.5,97,91.5,60,55};
float score2[10]={67.5,89.5,99,69.5,77,89.5,76.5,54,60,99.5};
printf("the average of class A is %6.2f\n",average(score1,5));
printf("the average of class B is %6.2f\n",average(score2,10));
return 0;
}
float average(float array[],int n)
{
int i;
float aver ,sum=array[0];
for(i=1;i<n;i++)
sum=sum+array[i];
aver=sum/n;
return (aver);
}
#include
int main()
{
void sort(int array[],int n);
int a[10],i;
printf("enter array:\n");
for(i=0;i<10;i++)
scanf("%d",&a[i]);
sort(a,10);
printf("the sorted array :\n");
for(i=0;i<10;i++)
printf(" %d",a[i]);
printf("\n");
return 0;
}
void sort(int array[],int n)
{
int i,j,k,t;
for(i=0;i<n-1;i++)
{
k=i;
for(j=i+1;j<n;j++)
if(array[j]<array[k])
k=j;
t=array[k];array[k]=array[i];array[i]=t;
}
}
#include
int main()
{
int max_value(int array[][4]);
int a[3][4]={{1,3,5,7},{2,4,6,8},{15,17,34,12}};
printf("max value is %d\n",max_value(a));
return 0;
}
int max_value(int array[][4])
{
int i,j,max;
max=array[0][0];
for(i=0;i<3;i++)
for(j=0;j<4;j++)
if(array[i][j]>max)max=array[i][j];
return (max);
}
#include
float max=0,min=0;
int main()
{
float average(float array[],int n);
float ave,score[10];
int i;
printf("please enter 10 scores:");
for(i=0;i<10;i++)
scanf("%f",&score[i]);
ave=average(score,10);
printf("maz=%6.2f\nmin=%6.2f\naverage=%6.2f\n",max,min,ave);
return 0;
}
float average(float array[],int n)
{
int i;
float aver,sum=array[0];
max=min=array[0];
for(i=1;i<n;i++)
{
if(array[i]>max)max=array[i];
else if(array[i]<min)min=array[i];
sum=sum+array[i];
}
aver=sum/n;
return(aver);
}
#include
int a=3,b=5;
int main()
{
int max(int a,int b);
int a=8;
printf("max=%d\n",max(a,b));
return 0;
}
int max(int a,int b)
{
int c;
c=a>b?a:b;
return(c);
}
#include
int main()
{
int f(int);
int a=2,i;
for(i=0;i<3;i++)
printf("%d\n",f(a));
return 0;
}
int f(int a)
{
auto int b=0;
static c=3;
b=b+1;
c=c+1;
return(a+b+c);
}
#include
int main()
{
int fac(int n);
int i;
for(i=1;i<=5;i++)
printf("%d!=%d\n",i,fac(i));
return 0;
}
int fac(int n)
{
static int f =1;
f=f*n;
return (f);
}
#include
int main()
{
int max();
extern int A,B,C;
printf("please enter three integer numbers:");
scanf("%d%d%d",&A,&B,&C);
printf("max is %d\n",max());
return 0;
}
int A,B,C;
int max()
{
int m;
m=A>B?A:B;
if(C>m)m=C;
return (m);
}
#include
int A;
int main()
{
int power(int);
int b=3,c,d,m;
printf("enter the number a and its power m:\n");
scanf("%d,%d",&A,&m);
c=A*b;
printf("%d*%d=%d\n",A,b,c);
d=power(m);
printf("%d**%d=%d\n",A,m,d);
return 0;
}
extern A;
int power(int n)
{
int i,y=1;
for(i=1;i<=n;i++)
y*=A;
return(y);
}