I'm trying to find from input to if is "Armstrong Number" or not. Here's my code. Probably I have another arrow but I can't divide (/) or multiplication (*) with int * variables. Why is that?
Also what is the best way to finding "Armstrong Number" and put information for user?
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
int main()
{
int n = 0, c = 0, result = 0;
printf( "Enter a number: " );
scanf("%d", &n);
int digit = log10(n)+1;
int ntemp1 = n;
while (ntemp1 != 0){
ntemp1 /= 10;
c++;
}
ntemp1 = n;
for (int i = 0; i < c; i++){
result += pow(ntemp1 % 10, c);
ntemp1 /= 10;
}
if (result == n)
printf("\nIt is an Armstrong Number!\n");
else
printf("\nIt is not an Armstrong Number!\n");
}
Also can I make this with arrays or maybe have different ways?
Undefined behaviour since
sis NULL. You need to pass a pointer to somewherescanfcan store anint.Dividing a pointer makes no sense. Division requires a number.
If we ignore the division to get to this spot, you assigned NULL to
scopy, and is derefencing a NULL pointer is undefined behaviour.As for fixes, I don't know what you are trying to do, but your code should start with