how to find sum of digits in C?
Answers were Sorted based on User's Feedback
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
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 |
Reverse the part of the number which is present from position i to j. Print the new number. eg: num=789876 i=2 j=5 778986
What is a function in c?
What is c basic?
int main() { unsigned char a = 0; do { printf("%d=%c\n",a,a); a++; }while(a!=0); return 0; } can anyone please explain me output????
What do you mean by command line argument?
Binary tree traversing
What is getch?
What is dynamic variable in c?
3. Program to print all possible substrings. ex: String S St Str Stri Strin String t tr tri trin tring r
List a few unconditional control statement in c.
What is the difference between struct and union in C?
main() { int x=5; printf("%d %d %d\n",x,x<<2,x>>2); } what is the output?