# 实验2

#include <stdio.h>
#include <stdlib.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 +1) + R1;
printf("20228330%04d\n", number);
}

return 0;

}

line18的功能是随机生成R1~R2的随机数。

#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);
getchar();

scanf("%c%c%c", &c1, &c2, &c3);
printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);

scanf("%lf,%lf", &x, &y);
printf("x = %lf, y = %lf\n", x, y);

return 0;
}

#include <stdio.h>
#include <math.h>

int main()
{
double x, ans;

scanf("%lf", &x);

ans = pow(x, 365);
printf("%.2f的365次方:%.2f\n", x, ans);
printf("\n");

return 0;
}
#include <stdio.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");
}

return 0;
}
#include <stdio.h>
#include <math.h>

int main()
{
double x, ans;

while(scanf("%lf", &x) != EOF)
{
ans = 9.0 / 5*x + 32;
printf("摄氏度%.2f时，华氏度%.2f\n", x, ans);
printf("\n");
}

return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
char c;
while(scanf("%c", &c)!=EOF)
{
switch(c)
{
case'r':printf("stop!\n");break;
case'g':printf("go go go\n");break;
case'y':printf("wait a minute\n");break;
default:printf("something must be wrong\n");
}
getchar();
}
return 0;
}

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main()
{
int n1,n2,i,flag;
srand(time(0));
n1=rand()%(30-1+1)+1;
printf("%d",n1);
printf("猜猜2023年4月哪一天会是你的lucky day\n");
printf("开始喽，你有三次机会，猜吧(1~30):");
scanf("%d",&n2);
printf("\n");
for(i=1;i<=2;i++)
{
flag=0;
if(n2==n1)
{
printf("哇，猜中啦~");
flag=1;
break;}
else if(n2<n1)
{
printf("你猜的日期早了,你的lucky day还没到呢\n");
printf("再猜：");
scanf("%d",&n2);
printf("\n");

}
else
{
printf("你猜的日期晚了，你的lucky day已经过了。\n");
printf("再猜：");
scanf("%d",&n2);
printf("\n");
}
}
if(flag==0)
printf("次数用完啦，偷偷告诉你，4月，你的lucky day是:%d",n1);

return 0;
} 

#include <stdio.h>

int main()
{

int i, j;

for(i = 1;i <= 9; i++)
{
for(j = 1;j <= i; j++)
{
printf("%d*%d =%3d ", j, i, j * i);
}
printf("\n");
}

return 0;
}

#include <stdio.h>
#include <stdlib.h>
int main()
{
int i,line,j;
printf("Input line:");
scanf("%d",&line);
for(i=1;i<=line;i++)
{    for(j=1;j<=(i-1);j++)
printf("\t");
for(j=1;j<=2*(line-i)+1;j++)
printf(" O \t");
printf("\n");

for(j=1;j<=i-1;j++)
printf("\t");
for(j=1;j<=2*(line-i)+1;j++)
printf("<H>\t");
printf("\n");

for(j=1;j<=i-1;j++)
printf("\t");
for(j=1;j<=2*(line-i)+1;j++)
printf("I I\t");
printf("\n");

}

return 0;
} 

posted @ 2023-03-18 14:59  &YT  阅读(10)  评论(0编辑  收藏  举报