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

Is struct oop?

0 Answers  


How is a two dimensional array passed to function when the order of matrix is not known at complie time?

1 Answers   CSC,


Why c is called procedure oriented language?

0 Answers  


Tell about strtok & strstr functions

2 Answers   HCL, iFlex, Motorola,


write a program to reverse a every alternetive words in a string in a place. EX: Input is "this is the line of text" Output should be "shit is eht line fo text" Please any one tell me code for that.

0 Answers   TCS,






write a progam to compare the string using switch case?

1 Answers  


what will be the output for the following program? main() { char ch = 'k'; char c; printf("%c",c); }

3 Answers  


What is #line in c?

0 Answers  


Explain #pragma statements.

0 Answers  


What is binary tree in c?

0 Answers  


What is the purpose of clrscr () printf () and getch ()?

0 Answers  


size maximum allocated by calloc()

3 Answers   DELL,


Categories