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 / pooja

main()
{
int n,i,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);
}

Is This Answer Correct ?    57 Yes 11 No

how to find sum of digits in C? ..

Answer / shrth

example:435
the answer is 4+3+5=12

Is This Answer Correct ?    89 Yes 49 No

how to find sum of digits in C? ..

Answer / bhagwat

main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n!=0)
{
r=n%10;
n=n/10;
sum=sum+r;
}

Is This Answer Correct ?    53 Yes 19 No

how to find sum of digits in C? ..

Answer / leninraj

main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
for(i=0;i<=5;i++)
{
r=n%10;
n=n/10;
sum=sum+r;
}

Is This Answer Correct ?    57 Yes 32 No

how to find sum of digits in C? ..

Answer / pankaj khaitan

main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("sum = %d",sum);
}

Is This Answer Correct ?    40 Yes 15 No

how to find sum of digits in C? ..

Answer / keerthireddy

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
r=n%10;
sum=sum+r;
n=n/10;
}
printf("sum = %d",sum);
}
output:
3456
how it works as follows:
3456%10 means it gives reminder as 6
6 will be added to the sum
3456/10 means it gives quotient as 345
then again loop is executing until the n value is 0
finally the result as 6+5+4+3=18

Is This Answer Correct ?    9 Yes 1 No

how to find sum of digits in C? ..

Answer / d. prashant

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("sum = %d",sum);
}

Is This Answer Correct ?    7 Yes 3 No

how to find sum of digits in C? ..

Answer / anil kumar nahak

void main()
{
int n,i,sum=0,r;
printf("enter the value");
scanf("%d",&n);
while(n>0)
{
rem=num%10;
sum=sum+rem;
num=num/10;
}
printf("sum = %d",sum);
}

Is This Answer Correct ?    3 Yes 3 No

how to find sum of digits in C? ..

Answer / sarthak patwal

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

void main()
{
clrscr();
int a,b,c,d;
printf ("Enter the number");
scanf ("%d",a);
b=a%10;
c=a/10;
d=b+c;
printf ("The sum of digits is %d",d);
getch();
}

Is This Answer Correct ?    1 Yes 1 No

how to find sum of digits in C? ..

Answer / nona

int n1, n2, sum;
Console.WriteLine("plz type the 1st number");
n1 = int .Parse (Console .ReadLine ());
Console.WriteLine("plz type the 2nd number");
n2 = int .Parse (Console .ReadLine ());
sum = n1 + n2;

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

what will be the output of this program main() { int i=1; while (i<=10); { i++; } }

11 Answers  


What is New modifiers?

0 Answers   NA,


What is the stack in c?

0 Answers  


Write a program to print a (*)pattern programming (A to Z) in capital in one programming ?

2 Answers   TCS,


Program to display given 3 integers in ascending order

1 Answers   N Tech,






output for following code??? main() { int x=2,y,z; x*=3+2; printf("1.%d\n",x); x*=y=z=4; printf("2.%d %d %d\n",x,y,z); x=y==z; printf("3.%d\n",x); x==(y=z); printf("%d",x); }

2 Answers   Elysium,


what is bit rate & baud rate? plz give wave forms

0 Answers  


Can a variable be both constant and volatile?

0 Answers  


What is the difference between arrays and pointers?

0 Answers  


Why can't I perform arithmetic on a void* pointer?

0 Answers  


Explain what would happen to x in this expression: x += 15; (assuming the value of x is 5)

0 Answers  


what is the difference between #include<stdio.h> and #include "stdio.h" ?

3 Answers  


Categories