C-Code To Find Magic Number - NESTED CODE || TECH FLOAT

Breaking

Post Top Ad

Post Top Ad

Saturday, 17 November 2012

C-Code To Find Magic Number

C-Code To Find Magic Number


#include<stdio.h>
int sum(int);
int main(){
  int num,r,s,rum=0,f,c=0;
  float f1;
  printf("Enter a number: ");
  scanf("%d",&num);
  f=sum(num);
  while(1)
  {
          f1=f/10;
  if(f1>=1)
  {
  f=sum(f);
   printf("\nSum of digits of number after %d - iteration:  %d",c+1,f);
   c++;
}
   else {
        break;
        }

    
     }
     if(f==1)
     {
   printf("\nThe digit %d is a Magic No.",num);
}
else
{
    printf("\nOMG!! The digit %d is not a Magic No.",num);
      
}
  getch();
  return 0;
}
int sum(int num)
{
    int sum=0,r;
    while(num){
      r=num%10;
      num=num/10;
      sum=sum+r;
  }
 return sum;
  }

The output::



No comments:

Post a Comment

Post Bottom Ad