Armstrong Number Series from 1 to 500 - C Program

Armstrong Number Series from 1 to 500

#include <stdio.h>
int main()
{
    int num, n, qsum, r;
    printf("Armstrong Number from 1 to 500\n");
    for (num = 1; num <= 500; num++)
    {
        qsum = 0;
        n = num;
        while (n != 0)
        {
            r = n % 10;
            qsum = qsum + (r * r * r);
            n = n / 10;
        }
        if (num == qsum)
            printf("%d\n",num);
    }
           
    return 0;
}

Output - Armstrong Number Series from 1 to 500

Armstrong Number from 1 to 500                                                                                          
1                                                                                                                       
153                                                                                                                     
370                                                                                                                     
371                                                                                                                     
407 
Compile and Run Online