코딩/Language Coder

158 : 배열1 - 형성평가9

pikapika 2018. 5. 6. 22:57



100개 이하의 정수를 입력받다가 0 이 입력되면 0 을 제외하고 그 때까지 입력 받은 개수를 출력한 후 입력받은 정수를 차례로 출력하되 그 수가 홀수이면 2배한 값을, 짝수인 경우에는 2로 나눈 몫을 출력하는 프로그램을 작성하시오.



8 10 5 15 100 0
5
4 5 10 30 50

[코드]

#include <stdio.h>

int main() {

 int arr[100];
 int i = 0, count = 0;

 while (1) {
  scanf("%d", &arr[i]);
  if (arr[i] == 0)
   break;
  count++;
  i++;
 }

 printf("%d \n", count);

 for (i = 0; i < count; i++) {
  if (arr[i] % 2 == 0)
   printf("%d ", arr[i] / 2);
  else
   printf("%d ", arr[i] * 2);
 }

 return 0;
}