实验任务1

#include <stdlib.h>

#include <stdio.h>

#include<time.h>

#define N 5

int main() {

    int number;

    int i;

 

    srand(time(0));

    for (i = 1; i < N; ++i) {

         number = rand() % 500 + 1;

         printf(“20228329%04d\n”, number);

    }

    return 0;

}

 

 

问题1:功能是产生一个以时间为种子500及以内的随机数并赋值给number

问题2:产生一个根据时间变化的随机学号

实验任务2

#include <stdlib.h>

#include <stdio.h>

#include<time.h>

 

int main() {

    int j, x, y;

    printf(“Guess which day is your lucky day.\nYou totally have three chances to try.\n”);

    srand(time(0));

    y = rand() % 30+1;

    for (j = 1; j <= 3; j++) {

         printf(“Enter your answer:”);

         scanf_s(“%d”, &x);

         if (y == x) { printf(“Yes,you are right.\n”); break; }

         else if (x > y) { printf(“More\n”); }

         else if (x < y) { printf(“Less\n”); }

    }

    if (y != x){

         printf(“Your chances are used up.The true date is:%d”,y);

         }

    return 0;

}

实验任务3

#include <stdlib.h>

#include <stdio.h>

int main() {

    char y;

    printf(“Enter the color of traffic light:\n”);

    printf(“r for red,g for green,y for yellow\n”);

 

    while (1) {

         y = getchar();

         getchar();

         if (y == ‘r’)printf(“Stop! \n”);

         else if (y == ‘g’)printf(“go go go \n”);

         else if (y == ‘y’)printf(“Wait a minute \n”);

         else printf(“Something must be wrong \n”);

         if (y == EOF)break;

    }

    return 0;

}

 

实验任务4

#include <stdlib.h>

#include <stdio.h>

#include<math.h>

 

int main() {

    while (1) {

         double s, ans = 0.0;

         int k = 0;

         int n, a, i, m;

         scanf_s(“%d %d”, &n, &a);

         for (i = 1; i <= n; i++) {

             for (m = 1; m <= i; m++) {

                  k = a * (pow(10, m) – 1) / 9;

             }

             ans += double (i) / k;

         }

         printf(“n=%d,a=%d,s=%lf \n”, n, a, ans);

 

        

    }

    return 0;

}

实验任务5

#include <stdlib.h>

#include <stdio.h>

#include<math.h>

 

int main() {

    int j = 1, k = 1;

    int m=1, ans;

    while (j <= 9) {

         k = 1,m=1;

         while (k <= j) {

             ans = 0;

             ans = m * j;

             printf(“%d * %d = %d  “, m, j, ans), k++;

             m++;

         }

         j++;

         printf(“\n”);

    }

   

    return 0;

}

实验任务6

#include <stdlib.h>

#include <stdio.h>

#include<math.h>

 

int main() {

    int line,m,n,j;

    scanf_s(“%d”, &line);

    for (m = 1; m <= line; m++) {

         for (j = m; j > 1; j–) {

             printf(“\t”);

         }

         for (n = 2 * m – 1; n <= 2 * line – 1; n++) {

             printf(” o \t”);

         }

         printf(“\n”);

         for (j = m; j > 1; j–) {

             printf(“\t”);

         }

         for (n = 2 * m – 1; n <= 2 * line – 1; n++) {

             printf(“<H>\t”);

         }

         printf(“\n”);

         for (j = m; j > 1; j–) {

             printf(“\t”);

         }

         for (n = 2 * m – 1; n <= 2 * line – 1; n++) {

             printf(“I I\t”);

         }

         printf(“\n”);

    }

   

    return 0;

}

当输入为n时:

第i行,需要打印2n-2i+1个字符小人

第i行,需要打印i-1个空白

原文地址:http://www.cnblogs.com/molsonxx/p/16807909.html

1. 本站所有资源来源于用户上传和网络,如有侵权请邮件联系站长! 2. 分享目的仅供大家学习和交流,请务用于商业用途! 3. 如果你也有好源码或者教程,可以到用户中心发布,分享有积分奖励和额外收入! 4. 本站提供的源码、模板、插件等等其他资源,都不包含技术服务请大家谅解! 5. 如有链接无法下载、失效或广告,请联系管理员处理! 6. 本站资源售价只是赞助,收取费用仅维持本站的日常运营所需! 7. 如遇到加密压缩包,默认解压密码为"gltf",如遇到无法解压的请联系管理员! 8. 因为资源和程序源码均为可复制品,所以不支持任何理由的退款兑现,请斟酌后支付下载 声明:如果标题没有注明"已测试"或者"测试可用"等字样的资源源码均未经过站长测试.特别注意没有标注的源码不保证任何可用性