if a five digit number is input through the keyboard, write
a program to calculate the sum of its digits.
(hint:-use the modulus operator.'%')
Answer Posted / ruchi
#include<stdio.h>
#include<conio.h>
int main()
{
int n,m,m1,s=0,d,sum;
printf("\nEnter the number ");
scanf("%d",&n);
m=n%10;
d=n/10;
while(d>=10)
{
m1=d%10;
d=d/10;
s =s+m1;
}
sum=s+m+d;
printf("\nSum is %d",sum);
getch();
}
| Is This Answer Correct ? | 13 Yes | 17 No |
Post New Answer View All Answers
How do you determine whether to use a stream function or a low-level function?
How main function is called in c?
how can use subset in c program and give more example
What are c identifiers?
What is #ifdef ? What is its application?
p*=(++q)++*--p when p=q=1 while(q<=6)
Why do we use main function?
Explain how do you print an address?
what is the syallabus of computer science students in group- 1?
What is void pointers in c?
What are actual arguments?
The purpose of this exercise is to benchmark file writing and reading speed. This exercise is divided into two parts. a). Write a file character by character such that the total file size becomes approximately >10K. After writing close the file handler, open a new stream and read the file character by character. Record both times. Execute this exercise at least 4 times b). Create a buffer capable of storing 100 characters. Now after generating the characters, first store them in the buffer. Once the buffer is filled up, store all the elements in the file. Repeat the process until the total file size becomes approximately >10K.While reading read a while line, store it in buffer and once buffer gets filled up, display the whole buffer. Repeat the exercise at least 4 times with different size of buffer (50, 100, 150 …). Records the times. c). Do an analysis of the differences in times and submit it in class.
Why are all header files not declared in every c program?
What is the explanation for the dangling pointer in c?
Are local variables initialized to zero by default in c?