input any 4 digit number and find the difference of all the
digits?
Answers were Sorted based on User's Feedback
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 |
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 |
What is the argument of a function in c?
main() { float a=3.2e40; printf("%d",a); }
int a=0,b=2; if (a=0) b=0; else b=*10; What is the value of b ?
what is the little endian and big endian?
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.
What does static mean in c?
without a terminator how can we print a message in a printf () function.
what is the use of operator ^ in C ? and how it works?
Is c procedural or object oriented?
what is the height of tree if leaf node is at level 3. please explain
What is #define size in c?