answersLogoWhite

0


Best Answer

import java.io.*;

public class Arms

{

public static void main(String args[]) throws Exception

{

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

System.out.println("Enter the number to be printed: ");

int n=Integer.parseInt(br.readLine());

int num,sum,r,temp;

System.out.println("Armstrong numbers upto given limit are:\n");

for(num=1;num<n;num++)

{

temp=num;

sum =0;

while (temp!=0)

{

r=temp%10;

sum=sum+(r*r*r);

temp=temp/10;

}

if(sum==num)

{

System.out.println(num);

}

}

}

}

Regards

Ramakrishna Nallapati

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

7y ago

#include<limits.h> // defines CHAR_BIT

#include<math.h> // defines pow()

#include<stdio.h> // defines printf()

bool is_armstrong (const int n, const int b=10) {

// Returns true if n base b is narcissistic.

// Preconditions: n>=0, b>=2

int digit[sizeof (int) * CHAR_BIT]; // caters for all digits in all bases

int i, j, k; // local variables

i = 0; // count of digits (so far)

j = n;

while (j) {

digit[i] = j%b; // store least significant digit

j/=b; // shift-right by one digit

++i; // increment count

}

k = 0; // sum of all digits raised to the power of i

for (j=0; j<i; ++j) k+=pow (digit[j], i);

return k==n;

}

int main (void) {

for (int n=100; n<=999; ++n)

if (is_armstrong (n)) // base 10

printf ("%d ", n);

return 0;

}

Output:

153 370 371 407

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a C program to check for Armstrong numbers in three digit values from 100 to 999 using do while loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

To find Armstrong number in java?

/*Program to find whether given no. is Armstrong or not. Example : Input - 153 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); int n = num; //use to check at last time int check=0,remainder; while(num &gt; 0){ remainder = num % 10; check = check + (int)Math.pow(remainder,3); num = num / 10; } if(check == n) System.out.println(n+" is an Armstrong Number"); else System.out.println(n+" is not a Armstrong Number"); } }


Write a java program to check a number is Armstrong number?

import java.io.*; public class Jerry { public static void main(String as[]) throws IOException { int k=Integer.parseInt(as[0]); int n=k; int d=0,s=0; while(n&gt;0) { d=n%10; s=s+(d*d*d); n=n/10; } if(k==s) System.out.println("Armstrong number"); else System.out.println("not Armstrong number"); } }


How do you check if your ohm meters resistance is working properly?

Get some resistors of known values and check your meter with them.


What is Ensuring that a field must contain two values is an example of a?

Range Check


How do you write a program to print Armstrong numbers between 1 and 100 using for loop?

/*Program to find Armstrong number between 1 to N*/ int main() { int n = 0, remainder, sum = 0, i = 0, noDigits = 0, isArm = 0; char ch[60] = {0}; printf("Find the Arm Strong Numbers between 1 to N"); scanf("%d", &amp;n); for(i = 1; i&lt;n; i++) { isArm = i; itoa(isArm, ch, 10); noDigits = strlen(ch); while(isArm) { remainder = isArm%10; isArm=isArm/10; sum= sum+pow(remainder, noDigits); } if(sum == i) printf("\nArm Strong Nos are %d\n", i); sum = noDigits = 0; } }

Related questions

To find Armstrong number in java?

/*Program to find whether given no. is Armstrong or not. Example : Input - 153 Output - 1^3 + 5^3 + 3^3 = 153, so it is Armstrong no. */ class Armstrong{ public static void main(String args[]){ int num = Integer.parseInt(args[0]); int n = num; //use to check at last time int check=0,remainder; while(num &gt; 0){ remainder = num % 10; check = check + (int)Math.pow(remainder,3); num = num / 10; } if(check == n) System.out.println(n+" is an Armstrong Number"); else System.out.println(n+" is not a Armstrong Number"); } }


Write a java program to check a number is Armstrong number?

import java.io.*; public class Jerry { public static void main(String as[]) throws IOException { int k=Integer.parseInt(as[0]); int n=k; int d=0,s=0; while(n&gt;0) { d=n%10; s=s+(d*d*d); n=n/10; } if(k==s) System.out.println("Armstrong number"); else System.out.println("not Armstrong number"); } }


Shell program for gcd of three given numbers?

write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? write a shell program for finding out gcd of three given numbers? check bellow link http://bashscript.blogspot.com/2009/08/gcd-of-more-than-two-numbers.html


What are the values of two numbers when their product is -168.75 and their sum is 1?

-12.5 and 13.5 Check: -12.5*13.5 = -168.75 and -12.5+13.5 = 1


Program to check whether the given number is an Armstrong number?

&lt;html&gt; &lt;head&gt; &lt;Script Language="JavaScript"&gt; var a,n,b=0,t; n=parseInt(window.prompt("enter n","0")); t=n; while(n&gt;0) { a=n%10; b=b+a*a*a; n=n/10; } if(b==t) { document.writeln("Armstrong no"); } else { document.writeln("Not an Armstrong no"); } &lt;/script&gt; &lt;/head&gt; &lt;/html&gt;


How old is bllie joe Armstrong?

i think he is 36. check wikipedia.


What is the colt 3rd generation pistol serial numbers made in 2000 through 2011?

You will have to call Colt for anything after @ 2003. Check Blue Book of Gun values.


How do you program fax numbers in one-touch dialing?

That depends on the specific make and model of your fax machine. Check your user's manual, or look on the manufacturer's website.


Which program would you run to check for possible disk errors and where is the program located?

program would you run to check for possible disk errors


How can you use Javascript to identify the largest of three numbers using forms and buttons?

You will need to make a form with the following: - three input fields with IDs for the three numbers. Alternatively you may use one input and ask the user to separate the numbers with commas. - a button Let the button execute a function when clicked. This function will get the input fields' values using getElementById, check whether they are really numbers and then compare them. If you used the one textfield alternative, you will have to get the value, explode it at the commas and then check whether the values are correct and compare the numbers. As for comparing there are several possibilities. You could make decision trees with if-constructs or subtract the numbers from each other and check whether the result is &gt;0. Then you could display the result in a previously empty p- or div-element.


How did neil Armstrong show bravery and courage for walking on the moon?

check erid


i need a completly free vin check program?

i need a completly free vin check program