English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
所有分類

1.編寫C/C++語言程式,在輸入一個正整數後,列出該數所有因數
2.編寫C/C++語言程式,在輸入一個正整數後,若該數為7的倍數,則輸出YES,非7的倍數則輸出NO
就這兩題

2007-01-07 15:20:44 · 3 個解答 · 發問者 ? 4 in 電腦與網際網路 程式設計

3 個解答

第一题∶
#include
void main(){
int num=0;
int factor=1;
int temp;
printf("Please input a number : ");
scanf("%d",&num);
printf("\n factors : \n");
for(factor=1;factor<=num;factor++){
temp=num/factor;
if (temp*factor==num)
printf("%d\t",factor);
}
printf("\nEnd\n");
}

第二题∶
#include
void main(){
int num=0;
int temp;
printf("Please input a number : ");
scanf("%d",&num);
printf("\nResult : ");
if(num!=0&&num%7==0)
printf("Yes");
else
printf("No");
printf("\nEnd\n");
}

有问题再讨论。

2007-01-07 17:35:59 · answer #1 · answered by Anonymous · 0 0

//Microsoft Visual C++ 6.0編攥
#include
void main()
{
int a,b,i;
cout<<"第一題"< cout<<"請輸入一數:"< cin>>a;
cout<<"其所有因數為:"< for(i=1;i<=a;i++)
if(a%i==0) cout< cout< cout<<"第二題"< cout<<"請輸入一數:"< cin>>b;
cout<<"偵測此數是否為7的倍數"< (b%7==0)?cout<<"YES":cout<<"NO";
cout< }

2007-01-09 10:12:45 · answer #2 · answered by 敬閔 2 · 0 0

//Power by Microsoft Visual Studio 2005
//可以使用 Dev-C++ 編譯此程式
#include
#include
void no1(int NUM);
int no2(int NUM);
int main(int argc, char *argv[]){
//=====START=====//
int i=28;
no1(i);
printf("\\n");
printf("%s\\n",(no2(i)!=0?"YES":"NO"));
//=====END=====//
system("PAUSE");
return 0;
}
void no1(int NUM){
int i;
for(i=1;i<=NUM;i++){
if((NUM%i)==0){
printf(" %d",i);
}
}
}
int no2(int NUM){
return ((NUM%7)==0?EOF:0);
}

2007-01-07 17:16:27 · answer #3 · answered by Big_John-tw 7 · 0 0

fedest.com, questions and answers