首页 > 其他分享 >实验二

实验二

时间:2023-03-22 22:36:59浏览次数:29  
标签:截图 include int 源码 实验 printf main

实验任务1

源码

#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;

}

  

屏幕截图

 

 

 问题一:生成一个586~701之间的随机数

 问题二:随机生成5个尾号为586~701的学号

 

实验任务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("%lf,%lf", &x, &y);
    printf("x = %lf, y = %lf\n",x, y);
    
    return 0; 
}

屏幕截图

 

 

 

实验任务3

3.1

源码

#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);
    
    return 0;
    
}

 屏幕截图

 

 3.2

源码

#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;
}

屏幕截图

3.3

源码

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

int main()
{
    double c, f;

    while (scanf("%lf", &c) != EOF)
    {
        f = (9.0 / 5.0) * c + 32;
        printf("摄氏度c=%.2f时,华氏度f=%.2f\n", c, f);
        printf("\n");
    }
    return 0;

}

  屏幕截图

 

 实验4

源码

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

int main()
{
    char light;
    while (scanf("%c", &light) != EOF)
    {

        getchar();
        switch (light)
        {
        case 121:printf("wait a minute\n");break;
        case 103:printf("go go go\n");break;
        case 114:printf("stop!\n");break;
        default:printf("something must be wrong...\n");break;
        }

    }


    return 0;
}

  屏幕截图

 

实验5

源码

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

int main()
{
	int a, i, b;
	i = 1;
	srand((unsigned)time(NULL));
	a = rand() % (30 - 1 + 1) + 1;

	printf("猜猜4月哪一天会是你的lucky day\n开始喽,你有三次机会,猜吧(1—30):");
	while (i <= 3 || b == a)
	{
		scanf("%d", &b);
		if (b == a)
			printf("哇,猜中了");
		else if (b < a)
			printf("猜早了哦\n\n");
		else if (b > a)
			printf("日期已经过了哦\n\n");
		if (i < 3 && a != b)
			printf("再猜猜看:");
		i += 1;
	}
	if (i > 3)
		printf("还没猜对哦,你的lucky day是%d号", a);
	return 0;

}

  屏幕截图

实验6

源码

#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;
} 

 屏幕截图

 

 实验7

源码

#include<stdio.h>

int main() {

    int n;

    printf("input n:");
    scanf("%d", &n);

    for (int i = 1;i <= n; i++) {
        for (int k = 1;k <= 3; k++) {
            for (int j = 1;j <= i - 1; j++) {
                printf("      ");
            }
            for (int j = 1;j <= 2 * (n - i) + 1; j++) {
                if (k == 1) printf(" O    ");
                if (k == 2) printf("<H>   ");
                if (k == 3) printf("I I   ");
            }
            printf("\n");
        }
    }
    return 0;
}

  屏幕截图

 

标签:截图,include,int,源码,实验,printf,main
From: https://www.cnblogs.com/syhhh/p/17223521.html

相关文章

  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(time......
  • 实验2 字符串和列表
    一、实验结论:1、实验任务1:task1.py程序源码:1#字符串的基础操作2#课堂上没有演示的一些方法34x='nbaFIFA'5print(x.upper())#字符串转......
  • 实验2 字符串和列表
    任务1x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(10,'*'))print(x.rjust(10,'*'......
  • 实验2
    2.1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN6#defineR1586#defineR2701intmain(){intnumber;inti;srand(time(0));for(i=0;......
  • 实验2
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;srand(ti......
  • 实验2
    实验任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;......
  • 实验2 字符串与列表
    1x='nbaFIFA'2print(x.upper())3print(x.lower())4print(x.swapcase())5print()67x='abc'8print(x.center(10,'*'))9print(x.ljust(10,'*'))......
  • 实验2
    x='nbaFIFA'print(x.upper())print(x.lower())print(x.swapcase())print()x='abc'print(x.center(10,'*'))print(x.ljust(10,'*'))print(x.rjust(10,'*'))......
  • 实验二
    task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sra......
  • 实验2
    实验任务1  问题一:line18将几个随机数组合起来问题二:根据当时的电脑时间,随机生成四个四位数 实验任务2 #include<stdio.h>#include<stdlib.h>intmain()......