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
What is structure in c language?
In c language can we compile a program without main() function?
What is character set?
Explain what are its uses in c programming?
Explain the difference between malloc() and calloc() function?
What is the use of in c?
Write the Program to reverse a string using pointers.
Can one function call another?
what is stack , heap ,code segment,and data segment
What is ctrl c called?
Why pointers are used in c?
Why is a semicolon (;) put at the end of every program statement?
What is the use of the function in c?
Why does not c have an exponentiation operator?
Explain what is gets() function?