Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


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

How can I display a percentage-done indication that updates itself in place, or show one of those twirling baton progress indicators?

0 Answers  


char ch="{'H','I',0};printf("%s",ch);what is output

9 Answers   Accenture,


write a program in c to print **** * * * * ****

1 Answers   TCS,


Is the following code legal? struct a { int x; struct a b; }

4 Answers  


Write a program to print the prime numbers from 1 to 100?

7 Answers  


What are the types of arrays in c?

0 Answers  


Differentiate between declaring a variable and defining a variable?

0 Answers  


Is that possible to add pointers to each other?

0 Answers  


What is the difference between #include and #include 'file' ?

0 Answers  


What is the best way to comment out a section of code that contains comments?

0 Answers  


What is the OOPs concept?

3 Answers  


When is a “switch” statement preferable over an “if” statement?

0 Answers  


Categories