TEST 1
源代码:
#include<stdlib.h>
#include<stdio.h>
#include<time.h>
#define N 5
#define R1 586
#define R2 701
int main()
{
int number;
int i;
srand(time(0) );
for(i =0;i<N;++i)
{
number=rand()%(R2-R1)+R1;
printf("20228330%04d\n",number);
}
return 0;
}
运行截图:
问题1:随机生成一个586到701之间的整数
问题二:生成5个尾号586-701的学号
TEST 2
源代码
#include<stdio.h>
int main()
{
double x,y;
char c1,c2,c3;
int a1,a2,a3;
scanf("%d%d%d",&a1,&a2,&a3); //未加&,错误
printf("a1=%d,a2=%d,a3=%d\n",a1,a2,a3);
scanf("%c%c%c",&c1,&c2,&c3);
printf("c1=%c,c2=%c,c3=%c\n",c1,c2,c3);
scanf("%f,%lf",&x,&y);
printf("x=%f,y=%lf\n",x,y);
return 0;}
TEST 3:
源代码:
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
double x,ans;
while(scanf("%lf",&x) !=EOF){
ans = pow(x,365);
printf("%.2f的365次方:%.2f\n",x,ans);
printf("\n");}
system("pause");
return 0;
}
截图
源代码
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{
double c,f;
while(scanf("%lf",&c) !=EOF){
f=c*9/5+32;
printf("摄氏度c=%.2lf,华氏度f=%.2lf",c,f);
printf("\n");}
system("pause");
return 0;
}
截图
TEST 4
#include<stdio.h>
#include<stdlib.h>
int main()
{
char x;
printf("Enter a color:");
while(scanf("%c",&x) !=EOF)
{
switch(x){
case 'r':printf("stop!\n");break;
case 'y':printf("wait a minute\n");break;
case 'g':printf("go go go!\n");break;
default :printf("something must be wrong\n");break;}
getchar();
printf("Enter a color:");}
return 0;}
TEST 5
源代码:
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
int main()
{int x,y,n;
srand(time(0));
x=rand()%30+1;
printf("猜猜2023年4月那一天会是你的lucky day\n");
printf("开始喽,你有三次机会,猜吧(1~30):");
for(n=1;n<=3;n++)
{scanf("%d",&y);
if(x==y)
break;
else{
if(y>x)
printf("你猜的日期晚了,你的lucky day已经过啦\n");
else
printf("你猜的日期早了,你的lucky day还没到呢\n");}
printf("再猜:\n");
}
if(x==y)
printf("哇,猜对了");
else
printf("次数用完啦。偷偷告诉你:4月,你的lucky day是%d\n",x);
system("pause");
return 0;
截图:
TEST6
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main()
{int line,column,sum;
line=1;
column=1;
sum=0;
for(;line<=9;line++)
{column=1;
for(;column<=line;column++){
sum=line*column;
printf("%d*%d = %d ",column,line,sum);}
printf("\n");
}
system("pause");
return 0;}
截图
TEST 7
输入为n时,第i行需要打印2n-1个小人,前面需要i-1个空格
源代码
#include<stdio.h>
#include<stdlib.h>
int main()
{int n,line,column,i,x;
printf("input n: ");
scanf("%d",&n);
i=n;
for (line=1;line<=n;line++)
{for(x=1;x<=n-i;x++)
printf(" \t");
for(column=2*i-1;column>=1;column--)
printf(" o \t");
printf("\n");
for(x=1;x<=n-i;x++)
printf(" \t");
for(column=2*i-1;column>=1;column--)
printf("<H>\t");
printf("\n");
for(x=1;x<=n-i;x++)
printf(" \t");
for(column=2*i-1;column>=1;column--)
printf("I I\t");
printf("\n");
i--;
}
system("pause");
return 0;}
截图:
标签:语句,main,编程,column,输入输出,int,printf,line,include From: https://www.cnblogs.com/cwpdpk/p/17223595.html