write a program to gat the digt sum of a number (et. 15=
>1+5=6)

Answers were Sorted based on User's Feedback



write a program to gat the digt sum of a number (et. 15= >1+5=6)..

Answer / sagarsp2010

#include<stdio.h>
#include<conio.h>
void main()
{
int n,i,sum=0,no;
clrscr();

printf("ENTER THE NO. OF TERMS:");
scanf("%d",&n);

for (i=1;i<=5;i++)
{

no=n%10;
sum=sum+no;
n=n/10;

}
printf("sum=%d",sum);

getch();
}

Is This Answer Correct ?    2 Yes 0 No

write a program to gat the digt sum of a number (et. 15= >1+5=6)..

Answer / santhosh kumar

#include<stdio.h>
#include<string.h>

int main ()
{
char no[100];
char num[2];
int i;
int length = 0;
int sum = 0;

memset(num, 0, 2);
printf("Enter the number: ");
gets(no);
length = strlen(no);

for(i=0; i<length; i++)
{
num[0] = no[i];
sum += atoi(num);
}

printf("Sum = %d", sum);
return 0;
}

Is This Answer Correct ?    2 Yes 1 No

Post New Answer

More C Interview Questions

Can two or more operators such as and be combined in a single line of program code?

0 Answers  


what is the disadvantage of using macros?

1 Answers   Wipro,


What is the use of in c?

0 Answers  


Why c is called a middle level language?

0 Answers  


What is %d called in c?

0 Answers  






What is size of union in c?

0 Answers  


Draw a diagram showing how the operating system relates to users, application programs, and the computer hardware ?

0 Answers  


Why is sizeof () an operator and not a function?

0 Answers  


What is a double c?

0 Answers  


What is array in C

0 Answers  


What is key word in c language?

4 Answers   ABC,


how to find the sizof of any datatype using bit manipulations

3 Answers  


Categories