# 实验二

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

#define N 5
#define R1 586
#define R2 701
int main ()
{
int number ,i ;
srand (time(0));

for(i=0;i<N;++i)
{
number = rand() % (R1 - R2 + 1) + R1;
printf("20228330%04d\n", number);
}
return 0 ;
}
//Q1 取一个在586到701之间的随机数
//Q2 功能是随机抽出5个学号用来点名 

#include<stdio.h>
int main()
{
double x, y;
char c1, c2, c3;
int a1, a2, a3;

scanf_s("%d%d%d", &a1, &a2, &a3);//ERROR 缺少&
printf("a1 = %d, a2 = %d, a3 = %d\n", a1,a2,a3);

getchar();
scanf_s("%c%c%c", &c1,1, &c2,1, &c3,1);
getchar();
printf("c1 = %c, c2 = %c, c3 = %c\n", c1, c2, c3);

scanf_s("%lf,%lf", &x, &y);//ERROR 应该是lf数值类型
printf("x = %lf, y = %lf\n",x, y);
return 0;
}
//int型变量a1, a2, a3分别获得整数 1、2、3
//char型变量c1, c2，c3分别获得字符'x' 'y' 'z'
//double型变量x, y分别获得小数3.2和4.6 

#include <stdio.h>
#include <math.h>
int main()
{
double C,F;
while(scanf_s("%lf", &C) != EOF)
{
F = (9/5)*C + 32 ;
printf("%.2f摄氏度转换为华氏度为: %.2f\n", C, F);
printf("\n");
}
return 0;
}

#include <stdio.h>
#include <stdlib.h>
main ()
{
char COLOR;

while(scanf_s("%c",&COLOR,1) != EOF )
{
switch(COLOR)
{
case 'y':
printf("wait a minute\n")    ;break;
case 'g':
printf("go go go\n")    ;break;
case 'r':
printf("stop!\n")    ;break;
default :
printf("something must be wrong...\n")     ;break;

}
getchar();
}
return 0 ;
} 

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N1 30
main ()
{
int number ,date ,i,m;
srand (time(0));
i = 1;
m = 0;
number = rand() % ( N1 -0 +1)+1 ;
printf("你有三次机会，猜吧（1-30）：") ;
;

while (scanf_s("%d", &date) != EOF && i <3)
{

if (date == number)
{
m = 1; printf("caizhongla\n"); break;
}
else
{
if (date < number && date> 0)
{
m = 2; printf("猜早啦\n"); i = i + 1;
}
else
{
if (date > number && date <= 30)
{
m = 3; printf("猜晚啦\n"); i = i + 1;
}
else
{
m = 4; printf("你怎么浪费了一次机会呢\n"); i = i + 1;
}
}
continue;
}

getchar();
}
printf("这一天其实是 %d 号.\n",number);

return 0 ;

#include <stdio.h>
int main() {
int i, j, n;
for (i = 1; i <= 9; i++) {

for (j = 1; j <= i; j++)
printf("%d*%d=%2d  ", i, j, i * j);

printf("\n");
}
return 0;
}

#include <stdio.h>
int main() {
int i, j, n ;
scanf_s("%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");
}

//第一行 空出0个小人位置,打印2n-1个小人
//第二行 空出2个小人位置,打印2n-3个小人
//第三行 空出4个小人位置,打印2n-5个小人
//第j行 空出2(j-1)个小人位置,打印2n-2j+1个小人
return 0;
}

posted @ 2023-03-17 16:19  Orangpetofi  阅读(23)  评论(0编辑  收藏  举报