이것저것
C언어 swea 1945 - 간단한 소인수분해 본문
https://swexpertacademy.com/main/identity/anonymous/loginPage.do
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
#include <stdio.h>
int main(void){
int test_case, num, i, j;
int arr[5] = {2,3,5,7,11}; //배열 arr 선언
scanf("%d", &test_case);
for(i = 0; i< test_case; i++){
int cnt[5] = {0}; // 배열 cnt 초기화
scanf("%d", &num);
for(j = 0; j < 5; j++){
int count = 0;
while(1){
if(num % arr[j] == 0){
// arr배열의 숫자 순서대로 나눠 떨어질때까지 개수 세기
count++;
num /= arr[j];
cnt[j] = count;
}
else{
break;
}
}
}
printf("#%d ",i+1);
int k;
for(k = 0; k < 5; k++){
printf("%d ", cnt[k]);
}
printf("\n");
}
return 0;
}
'Language > C언어' 카테고리의 다른 글
C언어 백준 1120 변형 (0) | 2020.11.20 |
---|---|
C언어 swea 1989 - 초심자의 회문 검사 (0) | 2020.11.20 |
C언어 swea 2072 홀수만 더하기 (0) | 2020.11.20 |
C언어 swea 2047 신문 헤드라인 (0) | 2020.11.20 |
C언어 swea 2025 대각선 출력하기 (0) | 2020.11.20 |