首页 > 其他分享 >实验2

实验2

时间:2024-10-14 09:35:30浏览次数:1  
标签:%. int money random 实验 printf include

 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 #define N 5
 #define N1 397
 #define N2 476
 #define N3 21
 int main() {
 int cnt;
 int random_major, random_no;
 srand(time(NULL));      
cnt = 0;
 while(cnt < N) {
 random_major = rand() % 2;
 
if(random_major) {
 random_no = rand() % (N2 - N1 + 1) + N1;
 printf("20248329%04d\n", random_no);
 }
     else {
     random_no = rand() % N3 + 1;
     printf("20248395%04d\n", random_no);
     }
     cnt++;
  }
  return 0;
 }

1.随机选取379到476中的数

2.随机选取1到21中的数

3.随机生成学号

#include <stdio.h>
 #include <math.h>
 int main() {
    double a, b, c;
    double delta, p1, p2; 
    while(scanf("%lf%lf%lf", &a, &b, &c) != EOF) {
        if(a == 0) {
            printf("a = 0, invalid input\n");
            continue;
        }
        delta = b*b - 4*a*c;
        p1 = -b/2/a;
        p2 = sqrt(fabs(delta))/2/a;
        if(delta == 0)
            printf("x1 = x2 = %.2g\n", p1);
        else if(delta > 0)
            printf("x1 = %.2g, x2 = %.2g\n", p1+p2, p1-p2);
        else {
            printf("x1 = %.2g + %.2gi, ", p1, p2);
            printf("x2 = %.2g - %.2gi\n", p1, p2);
        }
    }
    return 0;
 }

#include<stdio.h>
int main(){
    char color;
    while(scanf("%c",&color)!=EOF){
        getchar();
        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");
    }
    return 0;
}

include <stdio.h>
  
  int main(){
      double money,max = 0,min = 20000,total=0;
      
      printf("请输入今日开销,直到输入-1终止:\n");
      
      while(1){
          scanf("%lf",&money);
         
         if(money == -1){
             break;
         }
         if(money < min){
             min = money;
         }
         if(money > max){
             max = money;
         }
         total += money;
     }
     
     printf("今日累计消费总额:%.1f\n",total);
     printf("今日最高一笔开销:%.1f\n",max);
     printf("今日最低一笔开销:%.1f\n",min);
     
     return 0;
 }

#include <stdio.h>
  
  int main(){
      int a,b,c;
      
      while(scanf("%d%d%d",&a,&b,&c) !=EOF){
          if(a+b<=c||b+c<=a||a+c<=b)
           printf("不能构成三角形\n");
          else if(a==b&&b==c)
          printf("等边三角形\n");
         else if(a==b||b==c||a==c)
          printf("等腰三角形\n");
         else if(a*a==b*b+c*c||b*b==a*a+c*c||c*c==a*a+b*b)
          printf("直角三角形\n");
         else
          printf("普通三角形\n");
     }
     
     return 0;
 }

 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>
 
 int main(){
     int luckyday,x,y=3;
     
     printf("猜猜2024年11月哪一天会是你的lucky day\n"); 
     
     srand(time(NULL));
     luckyday = rand() % 30 + 1;
     
     printf("开始喽,你有三次机会,猜吧(1~30):");
     
     while(y>0){
         scanf("%d",&x);
         
         if(x==luckyday){
             printf("哇,猜中了:)");
             return 0;
         }
         else if(x>luckyday){
             printf("你猜的日期晚了,你的lucky day在前面哦\n");
         }
         else{
             printf("你猜的日期早了,你的lucky day还没到呢\n");
         }
         printf("再猜(1~30):");
         y--;
     }
     printf("次数用光啦。偷偷告诉你,11月你的lucky day是%d号\n",luckyday);
     
     return 0;
 }

 

标签:%.,int,money,random,实验,printf,include
From: https://www.cnblogs.com/znw-820/p/18463449

相关文章

  • 实验二
    task_1#include<stdio.h>#include<stdlib.h>#include<time.h>#defineN5#defineN1397#defineN2476#defineN321intmain(){intcnt;intrandom_major,random_no;srand(time(NULL));cnt=0;while(cnt<......
  • 操作系统:实验二:进程调度
    1.实验目的  1.了解三级调度的基本概念;  2.通过对先来先服务算法、时间片轮转算法和短作业优先算法的模拟实现掌握它们的工作原理。2.三级调度的基本概念  现在的操作系统大多是多道程序系统,在同一时段内,允许用户同时执行多个作业进(或进程)。一个作业从提......
  • 操作系统:实验三:存储器管理
    1.实验目的  1.理解固定式分区及可变式分区两种存储管理模式,知道各自的优缺点;  2.验证型实验需理解可变式分区方式的三种算法最先适应算法、最佳适应算法和最坏适应算法的工作原理,理解内存释放的具体实现过程;  3.提高型实验需在提供的代码框架下根据提示自主......
  • 实验1 现代c++编程初体验
    任务1:task1.cpp//现代C++标准库、算法库体验//本例用到以下内容://1.字符串string,动态数组容器类vector、迭代器//2.算法库:反转元素次序、旋转元素//3.函数模板、const引用作为形参#include<iostream>#include<string>#include<vector>#include<algorithm>......
  • 实验1
    实验任务1代码:1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<string>9#......
  • 面向对象程序设计-实验1
    任务一: #include<iostream>#include<string>#include<vector>#include<algorithm>usingnamespacestd;template<typenameT>voidoutput(constT&c);voidtest1();voidtest2();voidtest3();intmain(){cout&l......
  • 实验1 现代c++编程初体验
    实验任务一task1.cpp1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参6#include<iostream>7#include<string>8#includ......
  • openssl实验截图记录
                                    ......
  • 实验1 C++
    task1:代码:1//现代C++标准库、算法库体验2//本例用到以下内容:3//1.字符串string,动态数组容器类vector、迭代器4//2.算法库:反转元素次序、旋转元素5//3.函数模板、const引用作为形参67#include<iostream>8#include<string>9#......
  • 实验1
    实验任务1:1#include<iostream>2#include<string>3#include<vector>4#include<algorithm>56usingnamespacestd;78template<typenameT>9voidoutput(constT&c);1011voidtest1();12voidtest2();13voi......