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 putchar() function?
write a c program to accept a given integer value and print its value in words
4 Answers Vernalis, Vernalis Systems,
How does placing some code lines between the comment symbol help in debugging the code?
What is the purpose of 'register' keyword in c language?
What is meant by 'bit masking'?
write a program to find a given no. is divisible by 3 or not without using any arthimetic operators?
int a=2,b=3,c=4; printf("a=%d,b=%d\n",a,b,c); what is the o/p?
There seem to be a few missing operators ..
Why do we use int main instead of void main in c?
What is use of integral promotions in c?
whitch value return void main?
Explain how can I convert a string to a number?