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

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

1 Answers  


Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


void main() { int i=5; printf("%d",i+++++i); }

14 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 can not get my C++ program to work right. It is supposed to tell if a word is a palindrome or not, but it only tells thet the word is not a palindrome. And I can't fix it.

1 Answers  






How to reverse a linked list without using array & -1? Thank you.

2 Answers   Access, Satyam,


Write a program to accept two strings of Odd lengths. Then take all odd characters from one string and even characters from the other and concatenate and produce a string.

1 Answers  


Given that two int variables, total and amount, have been declared, write a loop that reads integers into amount and adds all the non-negative values into total. The loop terminates when a value less than 0 is read into amount. Don't forget to initialize total to 0. Instructor's notes: This problem requires either a while or a do-while loop.

3 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 tally is useful?

2 Answers  


which typw of errors ? & how to solve it ?

0 Answers  


wap for bubble sort

3 Answers  


Categories