# 实验二

#include<stdio.h>
int main()
{
double x, y;
char c1, c2, c3;
int a1, a2, a3;
scanf("%d %d %d",&a1,&a2,&a3);
getchar();
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("%lf,%lf", &x, &y);
printf("x = %f, y = %lf\n",x, y);
return 0;
}


任务三

#include <stdio.h>
#include <math.h>
int main()
{
double x, ans;
scanf("%lf", &x);
for(;;)
{

ans = pow(x, 365);
printf("%.2f的365次方: %.2f\n", x, ans);
scanf("%lf",&x);
}
return 0;
}


#include <stdio.h>
#include <math.h>
int main()
{
double c, f;
scanf("%lf", &c);
for(;;)
{

f = 9*c/5+32;
printf("摄氏度c=%lf时，华氏度f=%.2f\n", c, f);
scanf("%lf",&c);
}
return 0;
}


任务四

#include<stdio.h>

int main()
{
char x;
x=getchar();
for(;x!=EOF;x=getchar())
{

getchar();
if(x=='y')
printf("wait\n");
else if(x=='r')
printf("stop\n");
else if(x=='g')
printf("go\n");
else printf("wrong\n");

}
return 0;
}


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

int main()
{
int d,g,j=1;
srand(time(0));
d=rand()%30+1;
for(;j<=3;j++)
{
scanf("%d",&g);
if(g==d)
{printf("right\n");
j=3;}
else
if(g<d)
printf("猜得早了\n");
else
printf("猜得晚了\n");
}
printf("正确的day是%d\n",d);
printf("game over\n");
return 0;
}


#include<stdio.h>
int main()
{
int i,j,k,n;
i=1;
n=1;
j=1;
for(;j<=9;j++)
{
n=1;
i=1;
for(;n<=j;n++)
{
k=i*j;
printf("%d x %d= %-2d",i,j,k);
printf(" ");
printf(" ");
printf(" ");
i++;
}
printf("\n");
}
return 0;
}


任务七

#include <stdio.h>
int main() {
int i, j, n ;
scanf("%d", &n);
i = 1;

for (j = 1 ; j <= n ; j++)
{

while (i <= (j - 1))
{
printf(" ");
printf(" ");
printf(" ");
printf("    ");
i = i + 1;
}
printf("\n");

i = 1;
while (i <=  (j - 1))
{
printf(" ");
printf(" ");
printf(" ");
printf("    ");
i = i + 1;
}
i = 1;
while (i <= (2 * n - 2 * j + 1))
{
printf(" ");
printf("O");
printf(" ");
printf("    ");
i = i + 1;
}

printf("\n");
i = 1;
while (i <=  (j - 1))
{
printf(" ");
printf(" ");
printf(" ");
printf("    ");
i = i + 1;
}
i = 1;
while (i <= (2 * n -2*j+ 1))
{
printf("<");
printf("H");
printf(">");
printf("    ");
i = i + 1;
}

printf("\n");
i = 1;
while (i <=  (j - 1))
{
printf(" ");
printf(" ");
printf(" ");
printf("    ");
i = i + 1;
}
i = 1;
while (i <= (2 * n - 2 * j + 1))
{
printf("I");
printf(" ");
printf("I");
printf("    ");
i = i + 1;
}
printf("\n");
i = 1;
while (i <=  (j - 1))
{
printf(" ");
printf(" ");
printf(" ");
printf("    ");
i = i + 1;
}
printf("\n");
i = 1;
while (i <=  (j - 1))
{
printf(" ");
printf(" ");
printf(" ");
printf("    ");
i = i + 1;
}

printf("\n");
}
}


posted @ 2023-03-22 22:18  Cobalt丶o.O\  阅读(5)  评论(0编辑  收藏  举报