input any 4 digit number and find the difference of all the
digits?

Answer Posted / senthil

char num[10];

printf ("Enter the number: ");
gets(num);
printf("Entered number = %s\n", num);

if (strlen(num) != 4) // check for 4 digit including NULL
{
printf("Error: number not 4 digit");
}
else
{
printf("\ndifference = %d", (num[0]&0x0F) - (num[1]&0x0F) - (num[2]&0x0F) - (num[3]&0x0F));
}

Is This Answer Correct ?    2 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is variable declaration and definition in c?

495


How can I automatically locate a programs configuration files in the same directory as the executable?

624


Write a program with dynamically allocation of variable.

600


How do you view the path?

658


Do you know what are bitwise shift operators in c programming?

581






How are pointers declared in c?

592


Which is an example of a structural homology?

776


Why is c not oop?

533


In a switch statement, what will happen if a break statement is omitted?

598


What are structure types in C?

660


Explain how do you print an address?

652


a direct address that identifies a location by means of its displacement from a base address or segment a) absolute address b) relative address c) relative mode d) absolute mode

648


When is the “void” keyword used in a function?

826


How can you return multiple values from a function?

626


What language is windows 1.0 written?

571