실험 2

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

#define STUDENT_COUNT 5
#define RANGE_START 397
#define RANGE_END 476
#define SHORT_RANGE 21

int main() {
    int counter;
    int category;
    int random_value;
    
    srand(time(NULL));
    
    counter = 0;
    while(counter < STUDENT_COUNT) {
        category = rand() % 2;
        
        if(category){
            random_value = rand() % (RANGE_END - RANGE_START + 1) + RANGE_START;
            printf("20248329%04d\n", random_value);
     
     
 }
        else{
            random_value = rand() % SHORT_RANGE + 1;
            printf("20248329%04d\n", random_value);
            
        }
        
        
        counter++;
}

      return 0;
  }
선 21: N1-N2 범위 정수 생성 선 25: N2-N3 범위 정수 생성 기능: 랜덤 학번 생성 실험2
#include <stdio.h>
#include <math.h>

int main (){
    double a,b,c;
    double discriminant, root1, root2;
    
    while(scanf("%lf%lf%lf", &a, &b, &c) != EOF) {
        if(a == 0){
            printf("a = 0, invalid input\n");        
            continue;
            
            }
            discriminant =b*b -4*a*c;
            root1 = -b/2/a;
            root2 = sqrt(fabs(discriminant))/2/a;
            
            if(discriminant == 0)
                printf("x1 = %.2g,x2 = %.2g\n",root1+root2,root1-root2);
            else if(discriminant > 0)
                printf("x1 = %.2g, x2 = %.2g\n",root1+root2,root1-root2);
            else{
                printf("x1 = %.2g + %.2gi,",root1,root2);
                printf("x2 = %.2g - %.2gi,",root1,root2);
            }
    }
    return 0;
}
실험3
#include

int main()
{
    char signal;
    while((signal = getchar())   !=EOF){
    if (signal == 'r'){
    printf("정지!\n");}
    else if (signal == 'y'){
    printf("잠시 기다리세요\n");}
    else if(signal == 'g'){
    printf("전진 전진!\n");}
    else{
    printf("무언가 문제가 있습니다...\n");}
    getchar();
    }
    
    return 0;
}
실험4
#include

int main()
{
    double cost;
    double max_expense = 0.0;
    double min_expense = 20000.0;
    double total = 0.0;
    printf("오늘 지출을 입력하세요, -1을 입력하면 종료됩니다:\n");
    while (scanf_s("%lf", &cost) != EOF && cost != -1)
    {
        if (cost > max_expense)
        {
            max_expense = cost;
        }
        if (cost < min_expense)
        {
            min_expense = cost;
        }
        total += cost;
    }
    if (max_expense > 0 && min_expense < 20000 && total > 0)
    {
        printf("오늘 누적 지출: %.1lf\n", total);
        printf("오늘 최고 지출: %.1f\n", max_expense);
        printf("오늘 최저 지출: %.1f\n", min_expense);
    }
    else
    {
        printf("오류\n");
    }
    return 0;
}
실험5<br></br>#include

int main()
{
    int side1, side2, side3;
    while (scanf_s("%d %d %d", &side1, &side2, &side3) != EOF)
    {
        if (side1 + side2 <= side3 || side1 + side3 <= side2 || side2 + side3 <= side1)
        {
            printf("삼각형을 형성할 수 없습니다\n");

        }
        else {
            if (side1 == side2 && side2 == side3) {
                printf("등변 삼각형");
            }
            else if (side1 == side2 || side1 == side3 || side2 == side3) {
                if (side1 * side1 + side2 * side2 == side3 * side3 || side2 * side2 + side3 * side3 == side1 * side1 || side1 * side1 + side3 * side3 == side2 * side2) {
                    printf("등변 직각 삼각형\n");

                }
                else {
                    printf("등변 삼각형\n");
                }
            }else if (side1 * side1 + side2 * side2 == side3 * side3 || side2 * side2 + side3 * side3 == side1 * side1 || side1 * side1 + side3 * side3 == side2 * side2) {
                printf("직각 삼각형\n");
            
            }
            else { printf("일반 삼각형\n"); }

            
        }

    }
}
실험6
 #include <stdio.h>
 #include <stdlib.h>
 #include <time.h>

 int main() {
         srand(time(NULL));
         int target_date = rand() % 30 + 1;
         int user_guess;
         int attempts = 3;
         printf("2024년 11월 중 당신의 운이 좋은 날을 맞춰보세요\n 시작합니다, 3번의 기회가 있습니다(1~30):\n");
         while (attempts > 0) {
                 scanf_s("%d", &user_guess);
                 if (user_guess == target_date) {
                         printf("정답입니다!\n");
                         return 0;
            
        }
        else if (user_guess < target_date) {
                         printf("당신이 예측한 날은 너무 이릅니다.\n");
            
        }
        else {
                         printf("당신이 예측한 날은 너무 늦습니다.\n");
            
        }
                 attempts--;
        
    }
         printf("기회가 모두 소진되었습니다. 비밀을 공개합니다, 11월 당신의 운이 좋은 날은 %d입니다.\n", target_date);
         return 0;
    
}

태그: 시뮬레이션 입력처리 알고리즘 데이터구조 함수형 프로그래밍

7월 27일 23:32에 게시됨