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

2. A student studying Information Technology at Polytechnic of Namibia is examined by coursework and written examination. Both components of assessment carry a maximum of 50 marks. The following rules are used by examiners in order to pass or fail students. a. A student must score a total of 40% or more in order to pass (total = coursework marks + examination marks) b. A total mark of 39% is moderated to 40% c. Each component must be passed with a minimum mark of 20/50. If a student scores a total of 40% or more but does not achieve the minimum mark in either component he/she is given a technical fail of 39% (this mark is not moderated to 40%) d. Grades are awarded on marks that fall into the following categories. Mark 100-70 69-60 59-50 49-40 39-0 Grade A B C D E Write a program to input the marks for both components (coursework marks out of 50 and examination marks out of 50), out put the final mark and grade after any moderation. [30]

0 Answers  


which typw of errors ? & how to solve it ?

0 Answers  


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

2 Answers  


I'm having trouble with coming up with the correct code. Thank You!! The assignment was to write a program using string functions that accepts a price of an item and displays its coded value. The base of the keys: X C O M P U T E R S 0 1 2 3 4 5 6 7 8 9 Sample I/O Dialogue: Enter Price: 489.50 Coded Value: PRS.UX

0 Answers  


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  






when i use cout or cin call & then either << or >> .....it shows declaration syntax error...what should i do? cout<<"anything"; int a; cin>>a; return 0;

2 Answers  


To generate the series 1+3+5+7+... using C program

18 Answers  


How to create a program that lists the capital country when told what the original country is? (Terribly sorry, I'm a novice programmer and would appreciate any help ;). Cheers, Alexxis

0 Answers  


what is exceptions?

5 Answers   HCL, Wipro,


loop1: { x=i<n?(i++):0; printf("%d",i); exit(x); continue; } Error- misplaced continue. Doubt-1.will the exit(x) be executed for all values of x 2.will this statement go out of the program.

5 Answers   CMC,


full c programming error question based problem

3 Answers   HCL, TCS,


Write a C program to enter 10 integer numbers through one variable and count how many of them are even using while loop ?

2 Answers  


Categories