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
How do we open a binary file in Read/Write mode in C?
What are called c variables?
What is an array? What the different types of arrays in c?
Explain what will be the outcome of the following conditional statement if the value of variable s is 10?
Can a pointer be volatile in c?
What is the deal on sprintf_s return value?
Are local variables initialized to zero by default in c?
What is difference between main and void main?
What is main () in c?
Why is main function so important?
hi... can anyone help me to make a two-dimensinal arrays in finding the sum of two elements plzzz. thnx a lot...
how to find anagram without using string functions using only loops in c programming
What is string in c language?
What are shell structures used for?
What are the header files used in c language?