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

‘SAVEPOINT’ and ‘ROLLBACK’ is used in oracle database to secure the data comment. Give suitable examples of each with sql command.

1880


Explain how do you generate random numbers in c?

627


What are static variables in c?

630


When should a far pointer be used?

605


What are compound statements?

630






How does pointer work in c?

622


How can I list all of the predefined identifiers?

582


hi any body pls give me company name interview conduct "c" language only

1670


How to create struct variables?

595


what are the facialities provided by you after the selection of the student.

1661


What does int main () mean?

553


Explain how are 16- and 32-bit numbers stored?

786


What does struct node * mean?

603


What is the scope of local variable in c?

579


What is the difference between void main and main in c?

626