C program to check whether given number is Armstrong or not - My CS Tutorial - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Friday, November 29, 2019

C program to check whether given number is Armstrong or not - My CS Tutorial

In this tutorial, we will learn how to write a program that check given number is Armstrong or not.





C Program Code



#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  int num,x,j,temp,sum=0;;
  printf("\n Enter a number to know it is armstrong or not:\n ");
  scanf("%d",&num);
  temp=num;
  while(num>0)
  {
    x=num%10;
    sum+=x*x*x;
    num=num/10;
  }
  if(sum==temp)
  {
    printf("\n Given number %d is an armstrong number.\n",temp);
  }
  else
  {
    printf("\n Given number %d is not an armstrong number.\n",temp);
  }
  getch();
}



OUTPUT 1:





OUTPUT 2:





In first output, enter value of number is 153

Given number is Armstrong.


In second output, enter value of number is 258

Given number is not Armstrong.


Please share this post and blog link with your friends.For more programs use this blog.
If you have any problem, please comment in comment box, subscribe this blog for notifications of new post on your email and follow this blog.

Created by-- HARSH CHAUHAN

No comments:

Post a Comment