C language interview questions solution for freshers beginners placement tricky good pointers answers explanation operators data types arrays structures functions recursion preprocessors looping file handling strings switch case if else printf advance linux objective mcq faq online written test prime numbers Armstrong Fibonacci series factorial palindrome code programs examples on c++ tutorials and pdf
C program to print Armstrong numbers from 1 to 500
8 comments:
Anonymous
said...
what is wrong in following code?? #include #include main() { int i; for(i=1;i<=500;i++) { if(i==(((i%10)^3)+(((i/10)%10)^3)+((((i/10) /10)%10)^3))) printf("%d \n",i); else continue; }
@Anonymous first of all I looked up on your code and I tried to fix some issues, the result is almost good, but it's show just one number, 407.
Here is your code a litle bit updated: main() { int i; for(i=1;i<=500;i++) { if(i==(((i%10)*(i%10)*(i%10))+((((i/10)%10)*(i/10)%10)*(i/10)%10)+((((i/10) /10)%10)*(((i/10) /10)%10)*(((i/10) /10)%10)))) printf("%d \n", i); else continue; }
8 comments:
what is wrong in following code??
#include
#include
main()
{
int i;
for(i=1;i<=500;i++)
{
if(i==(((i%10)^3)+(((i/10)%10)^3)+((((i/10) /10)%10)^3)))
printf("%d \n",i);
else continue;
}
}
The only flaw that I see is that c does not have ^ operator.
@Anonymous first of all I looked up on your code and I tried to fix some issues, the result is almost good, but it's show just one number, 407.
Here is your code a litle bit updated:
main()
{
int i;
for(i=1;i<=500;i++)
{
if(i==(((i%10)*(i%10)*(i%10))+((((i/10)%10)*(i/10)%10)*(i/10)%10)+((((i/10) /10)%10)*(((i/10) /10)%10)*(((i/10) /10)%10))))
printf("%d \n", i);
else continue;
}
}
here output is 1,407;
i had modified it as
#include
int main()
{
int n,a,b,c,d,e,f,g,h;
for (h=001;h<=500;h++){
n=h;
a=n%10;
b=n%100;
c=(b-a)/10;
d=(n-b)/100;
e=a+c+d;
if (n==(a*a*a)+(c*c*c)+(d*d*d))
{
printf("%d\n",n);
continue;
}
}
}
output is:
1
153
370
371
407
Thanku sir
What wrong following code
Main()
{
int i;
For(i=1;i<=500;i++)
{if==(((i%10)^3)+(((i=10)%10)^3)+((((>/10)/10)%10)^3))))
Printf("%d\n",i);
else
}
}
Is it working
#include
#include
int main()
{
int a,b,c,n,i;
for(i=1;i<=500;i=i+1)
{
a=(i%10);
b=((i-a)/10)%10;
c=((i-10*b-a)/100)%10;
n=pow(a,3)+pow(b,3)+pow(c,3);
if(n==i)
printf("\n %d ",i);
else
continue;
}
}
Post a Comment