C Programming and Computer Geeks

Search MY Blog

Thursday, 28 November 2013

What getchar function returns and list out similar functions?



what is the Output of the following Program?

#include “stdio.h”
void main(void)
{
printf("\t %d ",getche());
getch();
}

ANSWER:  it will return the Equivalent ASCII decimal value of entered character..


getchar, getch, getche functions
getchar() Function

 
getch(), getche(), getchar() will return integer value.

getchar() returns the Equivalent decimal(ASCII) value of entered character with echoing the entered character.

getche() returns the Equivalent decimal(ASCII) value of entered character with echoing the entered character.

getch() returns the Equivalent decimal(ASCII) value of entered character without echoing the entered character.

Note: Here getchar() is ASCII C Standard Function. getche() and getch() functions are non-standard functions. so this program may not be compiled successfully in many Platforms.. This can be compiled
successfully in VC++ and Turbo C/C++ compilers...

Click here for more C Faq



Wednesday, 27 November 2013

Find Armstrong Number between 1 to 500 using loop



Armstrong numbers are those number whose sum of the cube of all digits equal to Original number.

i.e 153= (1x1x1 + 5x5x5 + 3x3x3)

void main()
{
     int i, sum=0, cube, num=0, neen=0, a;
    
     for(i=1; i<=500; i++)
     {
          neen = i;
          num=i;
          sum=0;

          while(num!=0)
          {
              cube=0;
              a=num%10;
              num=num/10;
              cube=a*a*a;
             
              sum=sum+cube;
          }

          if(neen == sum)
          printf("\n %d is Armstrong Number",neen);
     }

     getch();
}

OutPut:

Armstrong Number
Armstrong Number


Click here for more C Faq

Search This Blog