面试题集锦C++解答1
2014-04-23 10:29
302 查看
题目网址http://student.csdn.net/mcd/topic/235300/753730,通过C++实现,可以优化的地方请留言指教,谢谢!vs2010环境编译运行通过。
#include "stdafx.h"
#include <string>
#include<iostream>
using namespace std;
bool pd3(int num)
{
if(num%3==0)
return true;
else
return false;
}
bool pd5(int num)
{
if(num%5==0)
return true;
else
return false;
}
void outputnum()
{
int flag =0;
for(int i=0;i<=100;i++){
string outtemp="";
if(pd3(i))
flag+=3;
if(pd5(i))
flag+=5;
switch(flag){
case 3:
outtemp = "*";
break;
case 5:
outtemp = "#";
break;
case 8:
outtemp = "*#";
break;
default:
flag = 0;
break;
}
flag = 0;
cout<<"数字"<<i<<"输出结果为:"<<"......"<<outtemp<<endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
outputnum();
system("pause");
return 0;
}
#include "stdafx.h"
#include <string>
#include<iostream>
using namespace std;
bool pd3(int num)
{
if(num%3==0)
return true;
else
return false;
}
bool pd5(int num)
{
if(num%5==0)
return true;
else
return false;
}
void outputnum()
{
int flag =0;
for(int i=0;i<=100;i++){
string outtemp="";
if(pd3(i))
flag+=3;
if(pd5(i))
flag+=5;
switch(flag){
case 3:
outtemp = "*";
break;
case 5:
outtemp = "#";
break;
case 8:
outtemp = "*#";
break;
default:
flag = 0;
break;
}
flag = 0;
cout<<"数字"<<i<<"输出结果为:"<<"......"<<outtemp<<endl;
}
}
int _tmain(int argc, _TCHAR* argv[])
{
outputnum();
system("pause");
return 0;
}
相关文章推荐