C
Programming and Technical
Programming
Arrays
if 1995 is the given number
you write the code to add like this
1+9+9+5=24
2+4=6
final result is 6;
write code without for loop and don't take unique digit numbers like 9999 ....
solve this programming puzzle...
Read Solution (Total 14)
-
- void main()
{
int i=1994,sum=0,j;
while(i>0)
{
j=i%10;
sum=j+sum;
i=i/10;
}
printf("%d",sum);
} - 8 years agoHelpfull: Yes(3) No(5)
- void main()
{
int n;
int plus(int);
printf("nEnter a number :");
scanf("%d", &n);
printf("nThe sum is %d", plus(n));
}
int plus(int n)
{
static int rem,sum;
if(n>0)
{
rem = n % 10;
sum += rem;
plus(num/10);
}
return sum;
}
- 8 years agoHelpfull: Yes(1) No(3)
- #include
#include
int main()
{
int n;
clrscr();
printf("enter number");
scanf("%d",&n);
printf("the sum of individual digits:%d",add(n));
return 0;
}
int add(int a)
{
int r,sum=0;
if(a>0)
{
r=a%10;
sum+=r;
a=a/10;
add(a);
}
if(sum>10)
{
add(sum);
}
return sum;
}
- 8 years agoHelpfull: Yes(1) No(2)
- main()
{
int n,sum=0,rem;
printf("enter n value");
scanf(%d,&n);
while(n - 8 years agoHelpfull: Yes(1) No(2)
- #include
int add(int, int);
int main()
{
int n,t;
printf("enter number");
scanf("%d",&n);
t=n;
printf("the sum of individual digits:%d",add(n,t));
return 0;
}
int add(int n, int t)
{
int r,sum=0;
while (t != 0)
{
r = t % 10;
sum = sum + r;
t = t / 10;
}
printf("Sum of digits of %d = %dn", n, sum);
if(sum>10)
{
n=t=sum;
add(sum,t);
}
return sum;
} - 7 years agoHelpfull: Yes(1) No(0)
- I have taken 'i' as 1995 . chnage the value of 'i' and get the respective output.
#include
void main()
{
int i=1995,j,sum=0,k,l,total=0;
while(i>0)
{
j=i%10;
sum=sum+j;
i=i/10;
}
if(sum - 7 years agoHelpfull: Yes(1) No(0)
- take i value as u wish and get the output
#include
void main()
{
int i=19957,j,sum=0,k,l,total=0;
while(i>0)
{
j=i%10;
sum=sum+j;
i=i/10;
}
if(sum - 7 years agoHelpfull: Yes(1) No(0)
- main()
{
int n;
scanf("%d",&n);
sum(n);
}
void sum(int n)
{
int rem;
rem=x%9;
if(rem9)
sum(rem);
else
{
printf("sum is 9");
exit(0);
}
} - 8 years agoHelpfull: Yes(0) No(2)
- int digitalRoot(int n){
if(n%9==0)
return 9;
else return n%9;
} - 8 years agoHelpfull: Yes(0) No(0)
- using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace sumofdigits
{
class Program
{
static void Main(string[] args)
{
int n = 1995;
int i = 1;
int sum=0;
int r=0;
while (i - 8 years agoHelpfull: Yes(0) No(1)
- first printf:0
second printf:garbage value - 7 years agoHelpfull: Yes(0) No(1)
- #include
int func(int ,int );
int func(int n,int sum)
{
if(n>0)
{
sum=sum+(n%10);
sum=func(n/10,sum);
}
else if(sum/10!=0)
{
sum=func(sum,0);
}
else
return sum;
}
int main(void) {
int n=1995;
int sum=0;
sum=func(n,sum);
printf("%d",sum);
return 0;
} - 7 years agoHelpfull: Yes(0) No(1)
- #include
void main()
{
int i,j,sum=0;
scanf("%d",&i); //input data
while(i>0)
{
j=i%10;
sum+=j;
i=i/10;
}
printf("%d",sum); //output display
} - 7 years agoHelpfull: Yes(0) No(2)
- #include
void main()
{
int i=1411997,j,sum=0,k,l,total=0;
while(i>0)
{
j=i%10;
sum=sum+j;
i=i/10;
}
if(sum - 7 years agoHelpfull: Yes(0) No(0)
C Other Question