第11周项目6(4-2)-回文素数

来源:互联网 发布:php 支付码 编辑:程序博客网 时间:2024/06/06 23:16
/* *Copyright (c) 2014, 烟台大学计算机学院 *All rights reserved. *文件名称:week11-project6-4-2.cpp *作者:高赞 *完成日期:2014年 11 月 7 日 *版本号:v1.0 * *问题描述:输出1000以内所有回文数 */#include <iostream>#include <iomanip>using namespace std;bool isPalindrome(int);int main(){    int m=0;    cout << "1000以内所有回文数:" << endl;    cout.flags(ios::left); //设置左对齐    for (int n=1; n<=1000; ++n)    {        if (isPalindrome(n))        {            cout << setw(5) << n; //设置输出宽度为5            ++m;            if (m%10==0)                cout << endl;        }    }    return 0;}bool isPalindrome(int x){    bool huiwen;     int X=x,y,z=0;    while (x>0)    {        y=x%10;        z=z*10+y;        x=x/10;    }    if (X==z)        huiwen=true;    else huiwen=false;    return(huiwen);}


 

运算结果:

0 0
原创粉丝点击