i am a noob in programming,i tried writing a program to check if a given 3 digit number is armstrong or not, but at the end the if statement is not giving the desired results.please help.
#include <stdio.h>
#include <stdlib.h>
int main()
{
int n, i, j = 0, nd = 0;
printf("enter the 3 digit number:");
scanf("%d", &n);
for (i = 0; i = n; i++)
{
if (n / 10)!=0)
{
nd++;
n = (n / 10);
}
else
{
break;
}
}
int digits = nd + 1;
printf("enter the number with space in between:");
int ar[digits];
int qr[digits];
for (i = 0; i < digits; i++)
{
scanf("%d", &ar[i]);
}
for (i = 0; i < digits; i++)
{
qr[i] = (ar[i] * ar[i] * ar[i]);
}
for (i = 0; i < digits; i++)
{
j += qr[i];
}
printf("%d\n", j);
//<facing issue here>
if (j == n)
{
printf("the number is armstrong");
}
else { printf("the number is not armstrong"); }
return 0;
}
Aucun commentaire:
Enregistrer un commentaire