0
#include<stdio.h>
int add(int);
int main()
{
    int a,sum=1,c,d;
    printf("enter a number \n");
    scanf("%d",&a);
    sum=add(a);
    if(sum==a)
    printf("entered number is armstrong number");
    else
        printf("entered number is not armstrong number");

}
int add(int a)
{
     int rem,sum=0;
        while(a!=0)
         {
                    rem=a%10;
                    a=a/10;
                    sum=sum+(rem*rem*rem);
                    }

                              }
2
Contributors
1
Reply
9
Views
3 Years
Discussion Span
Last Post by tinstaafl
0

You need a method to force the user the press a key before the console is allowed to close. Here's a pretty good article that discusses the various options for that. In your case, since you seem to be using c, I would suggest this answer from that article:

void PressEnterToContinue()
{
  int c;
  printf( "Press ENTER to continue... " );
  fflush( stdout );
  do c = getchar(); while ((c != '\n') && (c != EOF));
}
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.