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...


how to find sum of digits in C?

Answers were Sorted based on User's Feedback



how to find sum of digits in C? ..

Answer / vani

//sum of digits in c//
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,sum=0;
clrscr();
printf("\n enter the number:");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("sum=%d");
getch();
}

Is This Answer Correct ?    0 Yes 0 No

how to find sum of digits in C? ..

Answer / jay soni

#include<stdio.h>
#include<conio.h>
void main()

{
int n,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
printf("\nsum of digits is %d",sum);

getch();
}

Is This Answer Correct ?    0 Yes 0 No

how to find sum of digits in C? ..

Answer / giri

#include <stdio.h>
#include <conio.h>

void main()
{
int sum=0, num, mul=1;
printf("Enter the number");
scanf("%d", &num);

while(num)
{
sum = sum + ((num%10)*mul);
num = num/10;
mul = mul * 10;
}

printf("Sum is %d", sum);
}

Is This Answer Correct ?    6 Yes 7 No

how to find sum of digits in C? ..

Answer / rajan praksh more (vangani-tha

#include<stdio.h>
#include<conio.h>
void main()
{
int rem,a;
int sum=0;
clrscr();
printf("Enter The Number: ");
scanf("%d",&a);
while(a>0)
{
rem=a%10;
sum=sum+rem;
a=a/10;
}
printf("sum of digits of entered number is =%d",sum);
getch();
}

Is This Answer Correct ?    0 Yes 1 No

how to find sum of digits in C? ..

Answer / mokhtar

all your answers are wrong, guys, for example when you get the reminder of 2/10, it gives you 0, because all of you used int as a data type.
so I think the the method is right, but the implementation is wrong.

regards.

Is This Answer Correct ?    0 Yes 1 No

how to find sum of digits in C? ..

Answer / rakesh ranjan

#include<conio.h>
#include<stdio.h>
main()
{
int x=0,n,i;
printf("entre the number");
scanf("%d",&n);
for(;n>0;n/=10)
x=x+n%10;
printf("sum = %d",x);
getch();
}

Is This Answer Correct ?    0 Yes 2 No

how to find sum of digits in C? ..

Answer / gg

try this....

#include<stdio.h>
int main()
{
int n,m,sum=0;
scanf("%d",&n);
for(m=0;((m=n%10)!=0);n=(n/10))
sum+=m;
printf("count is %d\n",sum);
}

Is This Answer Correct ?    13 Yes 16 No

how to find sum of digits in C? ..

Answer / ruchi

#include<stdio.h>
#include<conio.h>
int main()
{
int n,m,d,m1,s=0,s1;
printf("enter the number ");
scanf("%d",&n);
m=n%10;
d=n/10;
while(d>=10)
{
m1=d%10;
d=d/10;
s=s+m1;
}
s1=s+m+d;
printf("\nThe sum of digits is ");
printf("%d",s1);
getch();
}

Is This Answer Correct ?    7 Yes 11 No

how to find sum of digits in C? ..

Answer / deepak upadhyay

#include<stdio.h>
void main()
{
int num,a,b,c,d,e,sum;
printf("enter the num");
scanf("%d",&num);
a=num%10;
b=((num%100)-a)/10;
c=((num%1000)-(num%100))/100;
d=((num%10000)-(num%1000))/1000;
e=((num%100000)-(num%10000))/10000;
sum=a+b+c+d+e;
printf("\n1's place= %d \n10's place= %d \n100's
place= %d \n1000's place= %d \n10000's place=
%d",a,b,c,d,e);
printf("\nsum=%d",sum);
}

Is This Answer Correct ?    1 Yes 6 No

how to find sum of digits in C? ..

Answer / leelanarasimhareddy

void main()
{
int a[20];
printf("enter no of values");
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
sum=sum+a[i];
}
printf("%d",sum);
}

Is This Answer Correct ?    63 Yes 86 No

Post New Answer

More C Interview Questions

Why is conio.h not required when we save a file as .c and use clrscr() or getch() ?

2 Answers  


int main() { int *p=new int; *p=10; del p; cout<<*p; *p= 60; cout<<*p; } what will be the output & why?

4 Answers   TCS,


The differences between Windows XP and Windows Visa

8 Answers   HCL,


wap to print "hello world" without using the main function.

22 Answers   TCS, Wipro,


How many types of operator or there in c?

0 Answers  


write a program for odd numbers?

15 Answers  


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

0 Answers  


What is volatile in c language?

2 Answers   HCL, TCS,


In CMM or CMMI certified organizations,we assess only the standard software processes of the organization. We do not assess the organizations other functional departments like HR or Admin. Then how can we certify the entire organization as CMM level company?? We have assessed only software related activities. Right. There is no relation with other departments like Accounts, HR or Admin. Then how can we claim that the whole company is a CMM certified company?

1 Answers   Melstar,


what is the output of following question? void main() { int i=0,a[3]; a[i]=i++; printf("%d",a[i] }

3 Answers  


#include<conio.h> #include<stdio.h> void main() { int i; if(1,0,2,3) { printf("if"); } else { printf("else"); } getch(); } Can any body tell the answer of this question with explanation?

3 Answers   Huawei,


#ifdef TRUE int I=0; #endif main() { int j=0; printf("%d %d\n",i,j); }

3 Answers   ADITI,


Categories