Created
March 20, 2013 03:21
-
-
Save yswallow/5202059 to your computer and use it in GitHub Desktop.
素因数分解をするプログラム。
掃除してたら出てきたから書きなおしてみた。(昔は割ったあとのfloat==intかどうかで判断してたなんて言えない)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
int main(int argc,char *argv[]) | |
{ | |
unsigned int a,b,amari,i; | |
if(argc<2) | |
{ | |
printf("整数を入力してください。\n"); | |
scanf("%u",&a); | |
}else{ | |
a = atoi(argv[1]); | |
} | |
printf("%uの素因数は\n",a); | |
if(a==1) | |
{ | |
printf("…何だろうね。\n"); | |
return 0; | |
} | |
b=a; | |
for(i=2;;) | |
{ | |
amari = b % i; | |
if(amari==0) | |
{ | |
//iはbの因数 | |
printf("%d\n",i); | |
b=b/i; | |
if(b==1) | |
break; | |
}else{ | |
i++; | |
} | |
} | |
printf(" です。\n"); | |
printf("プログラムを終了します。\n"); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment