统计输入的整数区间内回文数的个数
2014-06-03 20:08
190 查看
// 回文数.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
using namespace std;
bool isHuiWen(int num){
int temp;
int sum = 0;
temp = num;
while (num)
{
sum = sum * 10 + num % 10;
num /= 10;
}
if (temp == sum)
return true;
else
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
system("chcp 936");
cout << "input 2 numbers:";
int a, b;
cin >> a >> b;
int count = 0;
for (int i = a; i <= b; i++){
if (isHuiWen(i))
count++;
}
cout << "there are " << count << " numbers between" << a << " and " << b << endl;
system("pause");
return 0;
}
// 回文数.cpp : 定义控制台应用程序的入口点。
//
#include "stdafx.h"
#include<iostream>
using namespace std;
bool isHuiWen(int num){
int temp;
int sum = 0;
temp = num;
while (num)
{
sum = sum * 10 + num % 10;
num /= 10;
}
if (temp == sum)
return true;
else
return false;
}
int _tmain(int argc, _TCHAR* argv[])
{
system("chcp 936");
cout << "input 2 numbers:";
int a, b;
cin >> a >> b;
int count = 0;
for (int i = a; i <= b; i++){
if (isHuiWen(i))
count++;
}
cout << "there are " << count << " numbers between" << a << " and " << b << endl;
system("pause");
return 0;
}
相关文章推荐
- 统计整数区间[a,b](a、b从键盘输入)中素数的个数,并输出这些素数。
- 从键盘输入一个整数,判断该数是否回文数.
- 输入一组整数,统计其中质数的个数。
- 数据统计 题目是输入一些整数,求出它们的最大值,最小值和平均值
- 求区间这种数的个数,这个数恰好等于k个互不相等的2的整数次幂之和 数位统计
- C 输入一个字符串,将其中连续的数字作为一个整数存到一数组中,统计整数个数并输出这些整数
- 输入一个字符串,统计共有多少个整数并输出。
- 【C代码练习17】输入数量不确定的0-9范围内的整数,统计每一种数字出现的次数,输入以-1结束
- 从键盘上输入两个整数_由用户回答它们的和_差_积_商和取余运算结果_并统计出正确答案的个数
- 输入一个字符串,统计共有多少个整数并输出。
- 判断输入的整数是不是回文数
- 输入一个字符串,内有数字和非数字字符,将其中连续的数字作为一个整数,依次存放到一数组a中。统计共有多少个整数,并输出这些数。
- 由计算机产生0-9之间的随机整数,用户输入猜测的数据,统计用户猜测的次数。产生随机数可以使用Math.rangom()静态方法,该方法返回正的double类型浮点数位于(0.0 1.0】间。
- 编一个程序,输入10个整数,并放在数组中,先降序输出全部的数,再统计并输出当中正数、负数和零的个数
- 输入数量不确定的[0,9]范围内的整数,统计每个数字出现的次数,输入-1时结束程序。
- 从键盘输入10个0-9的整数,统计为1、2、3的数字和其他数字的个数
- 设计算法来统计一个输入字符串中所包含的整数个数,并输出这些数
- 统计输入整数序列两两组合是7的倍数的个数
- 输入一个字符串内有数字和非数字字符,将连续的数字作为一个整数,存到数组a中,统计整数的个数,并输出这些数
- 对于给定的一个字符串,统计其中数字字符出现的次数。输入数据有多行,第一行是一个整数n,表示测试实例的个数,后面跟着n行,每行包括一个由字母和数字组成的字符串。