//task1.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define N 5
int main() {
int number;
int i;
srand( time(0) ); // 以当前系统时间作为随机种子
for(i = 0; i < N; ++i) {
number = rand()%65 + 1;
printf("20238331%04d\n", number);
}
system("pause");
return 0;
}
//从范围返回伪随机整数值[0, RAND_MAX],并对65取余数之后的值再加一。
//利用当前系统时间作为随机种子,随机生成后2位数字在01~65的12位学号。
//task2.c
#include <stdio.h>
#include <stdlib.h>
int main() {
char color;
while (1) {
if (scanf(" %c", &color) == EOF) {
break;
}
if (color == 'r') {
printf("stop!\n");
} else if (color == 'g') {
printf("go go go\n");
} else if (color == 'y') {
printf("wait a minute\n");
} else {
printf("something must be wrong...\n");
}
}
system("pause");
return 0;
}
//task3.c
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main() {
srand(time(0));
int luckyDay = rand() % 31 + 1;
int guess;
int chances = 2;
printf("猜猜2024年5月哪一天会是你的lucky day\n");
printf("开始喽,你有三次机会,猜吧(1~31):");
while (chances >= 0) {
scanf("%d", &guess);
if (guess == luckyDay) {
printf("哇,猜中了:-)\n");
break;
}
if (chances == 0) {
if (guess < luckyDay) {
printf("你猜的日期早了,你的lucky day还没到呢\n");
} else {
printf("你猜的日期晚了,你的lucky day在前面哦\n");
}
printf("次数用完啦。偷偷告诉你,5月你的lucky day是%d号\n", luckyDay);
break;
}else if (guess < luckyDay) {
printf("你猜的日期早了,你的lucky day还没到呢\n");
printf("再猜(1~31):");
} else {
printf("你猜的日期晚了,你的lucky day在前面哦\n");
printf("再猜(1~31):");
}
chances--;
}
system("pause");
return 0;
}
//task4.c
#include <stdio.h>
#include <stdlib.h>
double fun(int x,int y);
int main() {
int n,a;
double s;
while(scanf("%d%d",&n,&a)!=EOF){
s=fun(n,a);
printf("n = %d,a = %d,s = %f\n",n,a,s);
}
system("pause");
return 0;
}
double fun(int x,int y){
int i,m;
m=0;
double result;
for(i=1;i<=x;i++)
m=m*10+1;
m=m*y;
result=(x*1.0)/m;
if(x==1)
return result;
else
return result+fun(x-1,y);
}
//task5.c
#include <stdio.h>
#include <stdlib.h>
int main() {
int i,j,result;
for (i=1;i<10;i++){
for(j=1;j<=i;j++){
result=i*j;
printf("%dx%d=%-3d",j,i,result);
}
printf("\n");
}
system("pause");
return 0;
}
//task6.c
#include <stdio.h>
#include <stdlib.h>
int main() {
int i=1,j,k,t,n,m;
printf("input n:");
scanf("%d",&n);
while(i<=n){
m=2*(n+1-i)-1;
t=i-1;
if(t==0){
for(j=1;j<=m;j++){
printf(" o \t");
}
printf("\n");
for(j=1;j<=m;j++){
printf("<H>\t");
}
printf("\n");
for(j=1;j<=m;j++){
printf("I I\t");
}
printf("\n");
}
else{
for(k=1;k<=t;k++){
printf("\t");
}
for(j=1;j<=m;j++){
printf(" o \t");
}
printf("\n");
for(k=1;k<=t;k++){
printf("\t");
}
for(j=1;j<=m;j++){
printf("<H>\t");
}
printf("\n");
for(k=1;k<=t;k++){
printf("\t");
}
for(j=1;j<=m;j++){
printf("I I\t");
}
printf("\n");
}
i++;
}
system("pause");
return 0;
}
标签:return,int,编程,C语言,else,result,printf,include,分支 From: https://www.cnblogs.com/wpydcyyzy/p/18121104