首页 > 其他分享 >实验2

实验2

时间:2023-03-23 15:13:45浏览次数:32  
标签:main int scanf printf 实验 ans include

task1

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

#define N 5
#define R1 568
#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;
 } 

回答1:生成学号后四位数

回答2:随机生成五个在568-701之间的学号

 

 

 

task2

#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);  //输入必须为lf
    printf("x = %f, y = %f\n", x, y);
    
    return 0;
}

 

 

 

 

task3.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;
 } 

 

 

 

 

 

task3.3

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

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

 

 

 

 

 

task4

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

int main()
{
    char ans;
    
    ans = getchar();
    
    while(scanf("%c", &ans) != EOF){
        if(ans == 'g'){
           printf("go go go\n");
           getchar();
        }
           else if(ans == 'y') {
            printf("wait a minute\n");
            getchar();
            }
           
        else if(ans == 'r'){
            printf("stop!\n");
            getchar();
        }
        else if(ans != 'y' && ans != 'g' && ans != 'r')
          printf("something must be wrong\n");
    }
    
    return 0;
 } 

 

 

 

task5

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

int main()
{
    int i, a;
    int number;
    
    srand( time(0) );
    number = rand() % 30 + 1;
    
    printf("猜猜2023年4月哪一天会是你的lucky day 开始喽,你有三次机会,猜吧(1~30):\n");
    
    for(i = 1; i <= 3; ++i){
        scanf("%d", &a);
        if(a == number){
        printf("哇,猜中了:-)\n");break;
        }
        else
        {if(a < number)
            printf("你猜的日期早了,你的lucky day还没到呢 再猜(1~30)\n");
            else
            printf("你猜的日期晚了,你的lucky day已经过了 再猜(1~30)\n");
        }
    }
    
    if(a == number)
        getchar();
    else
        printf("次数用完啦。偷偷告诉你:4月,你的lucky day是%d号\n", number);
    
    return 0;
}

 

 

 

 

task6

#include <stdio.h>

int main()
{
    int i, j;
    for(i = 1; i < 10; i++){
        
        for(j = 1; j <= i; j++){
            
            printf("%d*%d=%-3d ", i, j, i*j);
        }
        printf("\n");
    }
    return 0;
}

 

 

 

task7

#include<stdio.h>

int main()
{
    int i, j, n;
    
    scanf("%d", &n);
 
    for(i = 1; i <= n; i++)
    {
        for(j = 1; j <= i-1; j++)
            printf("\t");
        for(j = 1; j <= 2*(n-i) + 1; j++)
            printf(" o \t");
               printf("\n");
        for(j = 1; j <= i-1; j++)
            printf("\t");
        for(j = 1; j <= 2*(n-i) + 1; j++)
            printf("<H>\t");
               printf("\n");
        for(j = 1; j <= i-1; j++)
            printf("\t");
        for(j = 1; j <= 2*(n-i) + 1; j++)
            printf("I I\t");
               printf("\n\n");

    }
    return 0;
}

 

标签:main,int,scanf,printf,实验,ans,include
From: https://www.cnblogs.com/hr-0120/p/17223589.html

相关文章

  • 实验2 输入输出和控制语句应用编程
     任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sran......
  • 实验二
    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,'*'......
  • 实验2
    1、实验任务1task1.c#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;int......
  • 实验2 字符串和列表
    实验任务1task11x='nbaFIFA'2print(x.upper())3print(x.lower())4print(x.swapcase())5print()67x='abc'8print(x.center(10,'*'))9p......
  • 实验2
    task1源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#include<math.h>#defineN5#defineR1663#defineR2701intmain(){intnumber,i......
  • 实验2
    #include"stdafx.h"#include<stdlib.h>#include<stdio.h>int_tmain(intargc,_TCHAR*argv[]){inta1,a2,a3;charc1,c2,c3;doublex,y;scanf("......
  • 实验二
    #include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){ intnumber; inti; srand(time(0)); f......
  • 实验二
    实验任务1task1.c源代码#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;int......
  • 实验二
    #task1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sran......
  • 实验2
    任务1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineR1586#defineR2701intmain(){intnumber;inti;sr......