Notice
Recent Posts
Recent Comments
Link
«   2025/03   »
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
Tags
more
Archives
Today
Total
관리 메뉴

archive

[C언어 실습/기컴프 과제] 3.3 본문

C \ C++/22_1 기컴프 (C)

[C언어 실습/기컴프 과제] 3.3

안정민 2022. 6. 21. 20:58

프로그래밍 연습 3.3

주어진 수의 집합에서 음수와 양수의 갯수를 계산하고 출력하는 프로그램을 작성하시오. 숫자를 읽을 때 scanf 문을 사용하고, 0이 읽혀질 때 읽기를 중지시킨다.

-

#include <stdio.h>

main()
{
    int i;
    int positive = 0;
    int negative = 0;


    while (1) {

        printf("i data input : ");
        scanf_s("%d", &i);

        if (i != 0)
            if (i > 0)
                positive++;
            else
                negative++;

        else
            break;
    }


    printf("positive number Cnt : %d \n", positive);
    printf("negative number Cnt : %d \n", negative);
}

 

-