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

Do you have any idea how to compare array with pointer in c?

0 Answers  


What is indirection?

0 Answers  


1234554321 1234 4321 123 321 12 21 1 1 12 21 123 321 1234 4321 1234554321

0 Answers  


Can a variable be both static and volatile in c?

0 Answers  


What are the types of operators in c?

0 Answers  






Explain which of the following operators is incorrect and why? ( >=, <=, <>, ==)

0 Answers  


how can i calculate mean,median,mode by using c program

1 Answers   HCL,


How we can set and clear bit in a byte using macro function?

2 Answers   L&T, Samsung,


A variable that is defined in a specified portion of a program but can be used throughout the program a) global variable b) local variable c) character d) none

0 Answers  


What is the best way of making my program efficient?

0 Answers  


What are c identifiers?

0 Answers  


What is a loop?

0 Answers  


Categories