標題:
[作業] 三數求公因數
[打印本頁]
作者:
周政輝
時間:
2017-6-13 18:22
標題:
[作業] 三數求公因數
讓使用者依序輸入三個正整數, 電腦回應它們有那些公因數, 以及共有幾個公因數.
執行畫面如下:
[attach]2259[/attach]
作者:
巫沛庭
時間:
2017-6-13 18:24
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int num=0,numm=0,nummm=0,factor=1,num1=0,num2=0;
cout<<"因數計算機"<<endl;
cout<<"請輸入一個數";
cin>>num;
cout<<"請輸入另一個數";
cin>>numm;
cout<<"請輸入第三數";
cin>>nummm;
while(factor<=num)
{
if(num%factor==0&&numm%factor==0&&nummm%factor==0)
{
cout<<factor<<",";
num1++;
num2+=factor;
}
factor++;
}
cout<<"有"<<num1<<"個因數";
cout<<"總數為:"<<num2<<endl;
system("pause");
return 0;
}
作者:
張閎鈞
時間:
2017-6-13 18:25
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=0,b=1,c=0,d=0,e=0,f=0;
cin>>a;
cin>>e;
cin>>f;
while(b<=a)
{
if(a%b==0&&e%b==0&&f%b==0)
{
cout<<b<<" "<<endl;
c=c+1;
d=d+b;
}
b++;
}
cout<<c<<endl;
cout<<d<<endl;
system("pause");
return 0;
}
複製代碼
作者:
顏羽彤
時間:
2017-6-13 18:26
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int num=0,num1=0,num2=0,same=1,count=0;
cout<<"公因數計算器"<<endl;
cout<<"請輸入一個數值:"<<endl;
cin >>num;
cout<<"請輸入第二個數值:"<<endl;
cin >>num1;
cout<<"請輸入第三個數值:"<<endl;
cin >>num2;
cout<<"公因數有:";
while(true)
{
if(num%same==0&&num1%same==0&&num2%same==0)
{
cout<<same;
cout<<" ";
count=count+1;
}
same++;
}
cout<<"有"<<count<<"個因數"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
巫晉宇
時間:
2017-6-13 18:36
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int k=1,j2=0,j1=0,j=0,g=0,u=0,;
cout<<"英數計算器"<<endl;
cout<<"輸入一個數值"<<endl;
cin>>j;
cout<<"輸入一個數值"<<endl;
cin>>j1;
cout<<"輸入一個數值"<<endl;
cin>>j2;
while (k<=j)
{
if(j%k==0&&j1%k==0&&j2%k==0)
{
cout<<k<<","<<endl;
g++;
u=k+u;
}
k++;
}
cout<<"有"<<g<<"個因數"<<endl;
cout<<"總合為"<<u<<endl;
system("pause");
return 0;
}
作者:
林峻安
時間:
2017-6-13 18:38
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
int num=0; int nun=0; int Factor=1; int count=0; int num1=0; int num2=0; int nub=0;
cout<<"因數計算器"<<endl;
cout<<"輸入一個值"<<endl;
cin>>num;
cout<<"輸入另一個值"<<endl;
cin>>nun;
cout<<"輸入第三個值"<<endl;
cin>>nub;
while(Factor<=num)
{
if(num%Factor==0&&nun%Factor==0&&nub%Factor==0)
{
cout<<Factor<<",";
count++;
num1 += Factor;
}
Factor++;
}
cout<<"有"<<count<<"因數"<<endl;
cout<<num1<<"因數"<<endl;
system("pause");
return 0;
}
複製代碼
作者:
張凱婷
時間:
2017-6-13 18:45
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
int a=0,factor=1,c=0,d=0,e=0,f=0;
cin>>a;
cin>>e;
cin>>f;
while(factor<=a)
{
if(a%factor==0&&e%factor==0&&f%factor==0)
{
cout<<factor<<","<<endl;
c=c+1;
d=d+factor;
}
factor++;
}
cout<<c<<endl;
cout<<d<<endl;
system("pause");
return 0;
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2