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

Tell me a C program to display the following Output? 1 1 1 1 1 2 2 2 2 3 3 3 4 4 5

3 Answers  


main() { int i; for(i=0;i<5;i++) printf("%d",1l<<i); } why doesn't 'l' affect the code??????

1 Answers  


What are the advantages of the functions?

0 Answers  


What is console in c language?

0 Answers  


How do you do dynamic memory allocation in C applications?

0 Answers  






how to reverse string "Hello World" by using pointers only. Without any temp var

1 Answers  


Write a program to implement a round robin scheduler and calculate the average waiting time.Arrival time, burst time, time quantum, and no. of processes should be the inputs.

0 Answers   Aspiring Minds,


C program code int zap(int n) { if(n<=1)then zap=1; else zap=zap(n-3)+zap(n-1); } then the call zap(6) gives the values of zap [a] 8 [b] 9 [c] 6 [d] 12 [e] 15

6 Answers   TCS, Wipro,


main() { FILE *fs; char c[10]; fs = fopen(“source.txt”, ”r”); /* source.txt exists and contains “Vector Institute” */ fseek(fs,0,SEEK_END); fseek(fs,-3L,SEEK_CUR); fgets(c,5,fs); puts(c); }

1 Answers   Vector,


what does ‘#include’ mean?

1 Answers   TCS,


Write an algorithm for implementing insertion and deletion operations in a singly linked list using arrays ?

0 Answers   MNC,


What is type qualifiers?

0 Answers  


Categories