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

Answers were Sorted based on User's Feedback



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

Answer / 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

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

Answer / jagan

i don't know pls give me response

Is This Answer Correct ?    1 Yes 1 No

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

Answer / nitin garg

int j,num,rem,diff=0;
printf("
Enter Digit
");
scanf("%d",&num);

while(num!=0)
{
rem=num%10;
j=rem+rem;
diff=diff-rem;
num=num/10;
}
diff=diff+j;
printf("
Difference of Digit is : %d",diff);

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

What is the argument of a function in c?

0 Answers  


main() { float a=3.2e40; printf("%d",a); }

9 Answers   Satyam,


int a=0,b=2; if (a=0) b=0; else b=*10; What is the value of b ?

6 Answers   TCS,


what is the little endian and big endian?

1 Answers  


why r u join this company? give solid resons.

16 Answers   IBM, Infosys, TCS,






Write a program, where i have a grid with many cells, how many paths are possible from one point to other desired points.

0 Answers   Expedia,


What does static mean in c?

1 Answers  


without a terminator how can we print a message in a printf () function.

7 Answers   NIIT,


what is the use of operator ^ in C ? and how it works?

2 Answers  


Is c procedural or object oriented?

0 Answers  


what is the height of tree if leaf node is at level 3. please explain

0 Answers  


What is #define size in c?

0 Answers  


Categories