Write a c-programe that input one number of four digits and find digits sum?

Answers were Sorted based on User's Feedback



Write a c-programe that input one number of four digits and find digits sum?..

Answer / erdem

{
int num, sum ;
printf("Enter digit 1\n");
scanf("%d",num);
sum=sum+num;
for(i=1;i<4;i++)
{
printf("Enter digit %d\n",i);
scanf("%d",num);
sum=sum+num;
}
printf("the sum of digits is %d",sum);
getche();

Is This Answer Correct ?    6 Yes 1 No

Write a c-programe that input one number of four digits and find digits sum?..

Answer / greeshmaanair

{
int sum,digit1,digit2,digit3,digit4;
printf("enter the four digit number\n");
scanf("%d",digit1,digit2,digit3,digit4);
digit1=(digit1%1000)/10;
digit2=(digit2%1000)/10;
digit3=(digit3%1000)/10;
digit4=(digit4%1000)/10;
sum=digit1+digit2+digit3+digit4;
printf("the sum of digits is %d",sum);
return(0);
}

Is This Answer Correct ?    1 Yes 7 No

Post New Answer

More C C++ Errors Interview Questions

difference between c/c++ programing language? what is necessesity of c++ when existing c programing language?

2 Answers   TCS,


I am using Qt 5.6 during compilation it stops and gives error about Qmake The process "C:QtQt5.6.35.6.3msvc2015_64inqmake.exe" crashed. Error while building/deploying project untitled1 (kit: Desktop Qt 5.6.3 MSVC2015 64bit) When executing step "qmake"

0 Answers  


what is meant for variable not found?

3 Answers  


wap for bubble sort

3 Answers  


void main() { int i=7; printf("N= %*d",i,i); }

6 Answers   HCL,






how to convert decimal to binary in c using while loop without using array

50 Answers   Apple, Aptech, Arwen Tech, BCS, C2D Software, CEC,


I'm having trouble with coming up with the correct code. Do I need to put a loop? Please let me know if I'm on the right track and what areas I need to correct. I still don't have a good grasp on this programming stuff. Thanks =) The assignment was to write a program using string functions that accepts a coded value of an item and displays its equivalent tag price. The base of the keys: 0 1 2 3 4 5 6 7 8 9 X C O M P U T E R S Sample I/O Dialogue: Enter coded value: TR.XX Tag Price : 68.00

3 Answers   UCB,


What is the code for following o/p * * * * * * * * * * * * * * * *

1 Answers  


what is meant by linking error? how can i solve it? if there is a linking error " unable to open file 'cos.obj'? then what should i do?

1 Answers  


class test { int a; public: test(int b):a(b){} void show(){ cout<<a; } }; void main() { test t1; test t2(5); t1.show(); t2.show(); } }

1 Answers  


How to upgrade LOOP environment, I just mean, how can i make loop statement editable ? I just try some program using loop statement and checking it in multiple compilers. Every compiler showing different output, what's the wrong ? is it a compiler based problem, or loop based problem, tell me why ? and what will be the debugging process, for this kind of problem ?

1 Answers  


void main() { for(int i=0;i<5;i++); printf("%d",i); } What is the output?..

32 Answers   College School Exams Tests, CTS, HCL, iGate, SmartData,


Categories