編寫一個程序,確定一個正整數是否完美。您的程序識別排列和組合足球比分
並顯示1到10,000之間的所有完美數字。 編寫一個從用戶讀取整數的程序。如果用戶輸入的值小於2,則您的程序應顯示相應的錯誤消息。否則,你的程序應該
顯示屏,可以相乘的素數計算N,每行出現
的一個因素。例如:
0-0, 1-0, 2-0, 2-1
0-0, 0-1, 1-1, 2-1
{
int m, n;
cout<<"Enter the finals scores of both teams";
cout<<"\nenter the score for team m :";
cin>>m;
cout<<"Enter the score for team n :";
cin>>n;
if (m < 0 && n < 0){
cout<<"score can't be negative";
cout<<"\nenter the score for team m :";
cin>>m;
cout<<"Enter the score for team n :";
cin>>n;
}
else{
int k=0;
if (n==0){
for (int j = 0; j <= m; j++){
for (k; k <= n; k+=1){
cout<<j<<"-"<<k<<",\t";
}
k--;
}
}
else if(m==1 && n==1){
int i=0;
int k=0;
for (int j = 0; j <= m; j++){
for (k; k <= n; k+=1){
cout<<j<<"-"<<k<<",\t";
}
k--;
}
cout<<endl<<endl;
for (int j = 0; j <= n; j++){
for (i; i <= m; i+=1){
cout<<i<<"-"<<j<<",\t";
}
i--;
}
}
else {
int i=0;
int k=0;
for (int j = 0; j <= m; j++){
for (k; k <= n; k+=1){
cout<<j<<"-"<<k<<",\t";
}
k--;
}
cout<<endl<<endl;
for (int j = 0; j <= n; j++){
for (i; i <= m; i++){
cout<<i<<"-"<<j<<",\t";
}
i--;
}
}
}
}
首先,如果'(M <0 &&Ñ<0){'應該是'如果(M <0 ||Ñ<0){' 。 – DimChtz
你並不需要所有'if/else if/else',你需要的只是2個嵌套for循環,用於'm','n'的任意組合。 – DimChtz
@DanialKhan你的調試器實際上被破壞了嗎? –