본문 바로가기

대학교 1-2/컴프

challenge6a

두 개의 단어를 입력받아서 같은가 다른가를 판별하는 프로그램을 작성 하라. 아래의 실행결과를 모두 실행시켜보아 프로그램의 완성도를 확인하라.

 

이번학기:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
int main(void)
{
    char first[99], second[99];
    int i,j,flag=1;
 
    printf("Enter the first word:");
    scanf("%s", first);
    printf("Enter the second word:");
    scanf("%s", second);
    for (i = 1; first[i] != '\0'; i++);
    for (j = 1; second[j] != '\0'; j++);
    
    if (i == j) {
        for (int k = 0; k < i; k++)
            if (first[k] != second[k]) {
                flag = 0;
                break;
            }
    }
    else
        flag = 0;
 
    if (flag == 0)
        printf("두 단어는 다르다");
    else
        printf("두 단어는 같다");
 
    return 0;
}
cs

지난학기:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#define _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
 
int main(void)
{
    char firstWord[81], secondWord[81];
    int flag = 1;
 
    printf("Enter the first word:");
    scanf("%s", firstWord);
    printf("Enter the second word:");
    scanf("%s", secondWord);
 
    for (int i = 0; firstWord[i] != '\0' || secondWord[i] != '\0'; i++)
        if (firstWord[i] != secondWord[i])
        {
            flag = 0;
            break;
        }
 
    if (flag == 0)
        printf("두 단어는 다르다");
    else //if(flag==1)
        printf("두 단어는 같다");
        
    return 0;
}
cs

지난학기에 저 문제 gpt사용했나..?코드가 낯설다

 

'대학교 1-2 > 컴프' 카테고리의 다른 글

challenge6d  (0) 2023.10.12
challenge6b  (1) 2023.10.12
HW6_3  (0) 2023.10.12
HW6_2  (1) 2023.10.12
Project1  (1) 2023.10.12