C++高手进,有问题请教,解决问题追加100分,急急急

编一个程序,实现输入一个整数,判断其是否能被3,5,7整除,并输出以下信息之一
1.同时能被357整除
2.能被其中2个整除,并指出哪两个
3能被一个整除
用C++应该怎么编写
需要具体的内容
解决问题者,追加100分
有效期至22点30分
急急急

以前写过,那个人是要要用文件输入输出的:

http://zhidao.baidu.com/question/22688814.html

我按你的要求改了,按ctrl + z结束输入:

#include <iostream>
#include <vector>
using namespace std;

int main()
{
int temp;
vector<int> seq;
while(cin >> temp)
{
if(temp % 3 == 0)seq.push_back(3);
if(temp % 5 == 0)seq.push_back(5);
if(temp % 7 == 0)seq.push_back(7);
if(!seq.empty() && seq.size() < 3)
{
cout << temp << "能被其中" << seq.size() << "个数整除";
cout << "这" << seq.size() << "个数是: ";
for(unsigned i = 0; i < seq.size(); ++i)
cout << seq[i] << ' ';
cout << "\n";
}
else if(seq.empty())
cout << temp << "不能被3, 5, 7中的任意一个数整除\n";
else
cout << temp << "能被3, 5, 7同时整除\n";
seq.clear();
}
}
温馨提示:答案为网友推荐,仅供参考
第1个回答  2007-04-11
#include<iostream>
#include<cmath>
bool l1,l2,l3;
long total,n;
using namespace std;
int main()
{
cin>>n;
if (n%3==0)
{
l1=true;
++total;
}
if (n%5==0)
{
l2=true;
++total;
}
if (n%7==0)
{
l3=true;
++total;
}

if (total==3) printf("同时能被357整除\n");
else if (total>=1)
{
printf("可以被");
if (l1) printf("3");
if (l2) printf("5");
if (l3) printf("7");
printf("整除\n");
}
system("pause");
}
第2个回答  2007-04-01
#include<iostream.h>
#include<iomanip.h>
void fun(int s)
{
int i,j,k;
i=3,j=5,k=7;
if(s%i*j*k=0)
count<<s<<endl;
else if(s%i*j=0||s%i*k=0||s%j*k=0)
count<<s<<endl;
else if(s%i=0||s%j=0||s%k=0)
count<<s<<endl;

main()
{
int n;
clrscr();
count<<"Enter the number:";
scanf("%d",&n);
fun(n);
count<<"The return:"<<endl;
随意写的,可能有错。与第二个条件不符合。

参考资料:个人发表

第3个回答  2007-04-01
#include <iostream>
using namespace std;
void main()
{
int a=3;
int b=5;
int c=7;
int n;
cout<<"please input the number"<<endl;
cin>>n;
if((n%a==0)&&(n%b==0)&&(n%c==0))//判断n能否被3个数整除
{
cout<<n<<"能被3,5,7整除 "<<endl;
exit(0); //判断完后没必要实行下面的语句,于是调用了系统语句停止程序
}
else if((n%(a*b)==0)||(n%(a*c)==0)||(n%(b*c)==0))//判断n能否被其中两个数整除
{
cout<<n<<"能被3,5,7其中两个整除"<<endl;
cout<<"这两个能整除"<<n<<"的数为:";
if(n%(a*b)==0) //下面几行判断n是被哪两个整除
{
cout<<a<<" "<<b<<endl;
}
else if(n%(a*c)==0)
{
cout<<a<<" "<<c<<endl;
}
else
{
cout<<b<<" "<<c<<endl;
}
exit(0);

}
else if((n%a==0)||(n%b==0)||(n%c==0)) //判断n能否 被其中一个整除
{
cout<<n<<"能被3,5,7其中一个整除"<<endl;
exit(0);

}
else
{
cout<<n<<"不能被3,5,7任何一个整除"<<endl;
}

}
小弟也是初学者,错误之处请指正,谢谢了。请高手多多指正
第4个回答  2007-04-12
最多只能追加50分,别蒙人了。
相似回答