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 full form of c language
How would you use the functions fseek(), freed(), fwrite() and ftell()?
0 Answers Aspire, Infogain, TISL,
Why malloc is faster than calloc?
What's the difference between calloc() and malloc()?
What is the purpose of void pointer?
How to add two numbers without using semicolon n c????
What is the purpose of Scanf Print, getchar, putchar, function?
Define C in your own Language.
diff. between *p and **p
#include<stdio.h> #include<conio.h> void main() { float a; clrscr(); a=0.5; if(a==0.5) printf("yes"); else printf("no"); getch(); }
what is the output of printf("%d",(scanf("%d",10));
Explain the advantages of using macro in c language?