archive
[C언어 실습/기컴프 과제] 3.3 본문
프로그래밍 연습 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);
}
-
'C \ C++ > 22_1 기컴프 (C)' 카테고리의 다른 글
[C언어 실습/기컴프 과제] 4.19 (0) | 2022.06.21 |
---|---|
[C언어 실습/기컴프 과제] 4.12 (0) | 2022.06.21 |
[C언어 실습/기컴프 과제] 복습 질문 3.18 (0) | 2022.06.21 |
[C언어 실습/기컴프 과제] 2.15 (0) | 2022.06.21 |
[C언어 실습/기컴프 과제] 2.14 (0) | 2022.06.21 |