实验2

task1

(1)line 18 代码实现的功能是 :一个586 到781 间的随机数

(2)该程序的功能为随机生成586到781 之间的"真·随机数"

task2

// .2.2.c.cpp : 定义控制台应用程序的入口点。
//

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


int _tmain(int argc, _TCHAR* argv[])
{
int a1, a2, a3;
char c1, c2, c3;
double x, y;


scanf(" %d %d %d\n", &a1, &a2, &a3);
getchar();
printf("a1 = %d, a2 = %d, a3 = %d\n",a1, a2, a3);
getchar();
scanf("%c %c %c\n",&c1, &c2, &c3);
getchar();
printf("c1 = %c, c2 = %c, c3 = %c\n",c1, c2, c3);


scanf(" %lf, %lf\n", &x, &y);
getchar();
printf("x = %lf, y = %lf\n", x, y);


system("pause");
return 0;
}

 

 

task3.1

// uuuuuu.cpp : 定义控制台应用程序的入口点。
//

#include "stdafx.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    double x, ans;
    scanf_s("%lf", &x);
    ans = pow(x, 365);
    printf("%.2f的365次方:%.2f\n", x, ans);

    system("pause");
    return 0;
}

 

task3.2

#include "stdafx.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    double x, ans;
    
    while(scanf_s("%lf", &x) != EOF)
    {
        ans = pow(x, 365);
    printf("%.2f的365次方:%.2f\n", x, ans);
    printf("\n");
    }

    system("pause");
    return 0;
}

task3.3

#include "stdafx.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    double C, F;
    
    while(scanf_s("%lf", &C) != EOF)
    {
        F =( C*9/5 + 32);
    printf("摄氏度C = %.2f时,华氏度F = %.2f\n", C, F);
    printf("\n");
    }

    system("pause");
    return 0;
}

task4

#include "stdafx.h"
#include <stdlib.h>
#include <math.h>
#include <stdio.h>

int _tmain(int argc, _TCHAR* argv[])
{
    char s;
    
    while((s = getchar()) != EOF)
    {
        switch(s)
        {
            case 'y': printf("wait a minute\n");break;
            case 'g': printf("go go go\n");break;
            case 'r': printf("stop!\n");break;
            default :{ printf("somehing must be wrong...\n");}break;
        }
    printf("\n");
    }

    system("pause");
    return 0;
}

task5

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

int _tmain(int argc, _TCHAR* argv[])
{
    int a, b, i;
    srand( time(0));

    a = rand() % 30 + 1;
    printf("猜猜2023年四月哪一天会是你的lucky day\n");

    for(i=1;i=3;++i)
    {
        scanf("%d", &b);
        if(a = b){
           printf("哇,猜中了:-)\n");break;
        }
        else{
           if(a > b)
              printf("你猜的日期早了,你的lucky day还没到呢\n");
           else
              printf("你猜的日期晚了,你的lucky day已经过啦\n");
        }
    }
    if(a = b)
        getchar();
    else
        printf("次数用完啦,偷偷告诉你:四月你的lucky day是%d\n", a);

    system("pause");
    return 0;
}

task6

// uuuuuu.cpp : 定义控制台应用程序的入口点。
//

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

int _tmain(int argc, _TCHAR* argv[])
{
  int i, n;
  for(i=1;i<=9;i++){
      for(n=1;n<=i;n++)
          printf("%d x %d = %d ", n, i, n*i);
      printf("\n");
  }

    system("pause");
    return 0;
}

task7

// uuuuuu.cpp : 定义控制台应用程序的入口点。
//

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

int _tmain(int argc, _TCHAR* argv[])
{
     int i, n, a, t, v;
     scanf("%d", &a);
 
     for(i=a;i>=1;i--){
         t = (2*i - 1);
        for(v=a;v>i;v--)
             printf("        ");
        for(n=1;n<=t;n++)
             printf(" O  \t");
             printf("\n");
        for(v=a;v>i;v--)
             printf("        ");
        for(n=1;n<=t;n++)
             printf("<H> \t");
             printf("\n"); 
        for(v=a;v>i;v--)
             printf("        ");
        for(n=1;n<=t;n++)
             printf("I I \t");
         printf("\n");
      }

    system("pause");
    return 0;
}

 

posted @ 2023-03-22 22:51  大帅浩淇  阅读(9)  评论(0编辑  收藏  举报