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 |
write a program that eliminates the value of mathematical constant e by using the formula e=1+1/1!+1/2!+1/3!+
How will you write a code for accessing the length of an array without assigning it to another variable?
How the processor registers can be used in C ?
What is a header file?
When should the register modifier be used? Does it really help?
what is a c-language.what is do.
which of the following shows the correct hierarchy of arithmetic operations in C a) (), **, * or/,+ or - b) (),**,*,/,+,- c) (),**,/,*,+,- d) (),/ or *,- or +
Explain the difference between malloc() and calloc() function?
What is volatile, register definition in C
Sir i need notes for structure,functions,pointers in c language can you help me please
What is a pointer and how it is initialized?
What are structures and unions? State differencves between them.