博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
to Generate Armstrong Numbers
阅读量:5817 次
发布时间:2019-06-18

本文共 1425 字,大约阅读时间需要 4 分钟。

Generate Armstrong Numbers in C++

To generate Armstrong numbers in C++ programming, you have to ask to the user to enter the interval to print the Armstrong number

between the given interval as shown here in the following program.

C++ Programming Code to Generate Armstrong Numbers

Following C++ program ask to the user to enter the interval, to print the Armstrong numbers in the given interval.

Since if you start from 1 then the first Armstrong number will be 153.

So enter the interval which contain 153 like enter starting number as 1, 2, 3, 4...... etc.

and enter the ending number like 154, 155, 156.......etc. It is just a clue that the first Armstrong number is 153 so to check/print, you can follow it.

Generate Armstrong number from the following C++ program, so following C++ program illustrates it:

 

#include <iostream>

using namespace std;

int main()

{

//

int num1, num2, i, n, rem, temp, count=0;
//enter the interval (enter the two number)
cout<<"Enter Starting Number : ";
cin>>num1;
cout<<"Enter Ending Number : ";
cin>>num2;

//

for(i=num1+1; i<num2; i++)
{
temp=i;
n=0;

//

while(temp!=0)
{
rem=temp%10;
n = n + rem*rem*rem;
temp=temp/10;
}

//

if(i==n)
{
if(count==0)
{
cout<<"Armstrong numbers between the given interval are : \n";
}
cout<<i<<" ";
count++;
}

}//

if(count==0)

{
cout<<"Armstrong number not found between the given interval";
}
return 0;
}

转载于:https://www.cnblogs.com/poission/p/10909954.html

你可能感兴趣的文章
java面向对象1
查看>>
网站页面直接跳转到别的页面
查看>>
JavaScript学习笔记(十三)——生成器(generator)
查看>>
vue组件
查看>>
实例练习:购物车
查看>>
access数据库
查看>>
TP5.1 钩子与行为应用
查看>>
第7章课后总结
查看>>
js5
查看>>
json-c与树
查看>>
Spring AOP 笔记
查看>>
Jmeter之保存响应到文件
查看>>
(01背包)Buy the souvenirs (hdu 2126)
查看>>
5.多线程基础1
查看>>
事务隔离级别实现原理
查看>>
Fence Obstacle Course
查看>>
eclipse 中引用其他项目及项目打包
查看>>
Android获取屏幕宽度的4种方法
查看>>
用for循环计算任意两个日期之间的工作日(去掉周六周日)
查看>>
软件系统架构质量属性——淘宝网分析
查看>>