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 dynamic memory allocation?

0 Answers  


An integer that indentifies the position of a data item in a sequence of data items a) value b) number c) index d) all of the above

0 Answers  


i want to know the procedure of qualcomm for getting a job through offcampus

0 Answers   HCL,


marge linklist

0 Answers   HCL,


Write a client and server program in C language using UDP, where client program interact with the Server as given below: i) The client begins by sending a request to send a string of 8 characters or series of 7 numbers, the server sends back a characters or numbers as per the request of the client. ii) In case of series of 7 numbers: The client sends a multiplication of numbers, to the server. iii) In case of a string of 8 characters: The client sends a reverse order of string to the server.. iv) Server will send an acknowledgment to the client after receiving the correct answer

0 Answers   Ignou, Microsoft,






why ordinary variable store the later value not the initial

1 Answers  


What is queue in c?

0 Answers  


a=10;b= 5;c=3;d=3; if(a printf(%d %d %d %d a,b,c,d) else printf("%d %d %d %d a,b,c,d);

0 Answers   Wilco,


What is difference between main and void main?

0 Answers  


In c programming, explain how do you insert quote characters (? And ?) Into the output screen?

0 Answers  


char ch=10;printf("%d",ch);what is the output

14 Answers   Accenture,


int n=1; while(1) { switch(n) { case 1:printf("a"); n++; continue; case 2:printf("b"); n++; continue; default : printf("c"); break; } break; }

1 Answers  


Categories