+ 1
program : Add a digit to all digits of n input : 2875 4 output; 612119
correct the code
8 Respuestas
+ 2
i tried this
#include<stdio.h>
int main()
{
int n,k,s=0,rem;
scanf("%d%d",&n,&k);
while(n!=0)
{
rem=n%10;
s=k+rem;
n=n/10;
printf("%d",s);
}
return 0;
}
+ 1
but i get the output 911126.
+ 1
you can do it using string or array
+ 1
#include<stdio.h>
int main()
{
int n,k,s=0,p;
scanf("%d%d",&n,&k);
while(n!=0)
{
p = n;
while(p>9)p/=10;
s=k+p;
int x = 1;
while(x<n)x*=10;
x/=10;
n%=x;
printf("%d",s);
}
return 0;
}
+ 1
#include<stdio.h>
int main()
{
int n,k,s=0,p=0;
scanf("%d%d",&n,&k);
while(n!=0)
{
p = n;
while(p>9)p/=10;
s=k+p;
int x = 1;
while(x<n)x*=10;
x/=10;
n%=x;
printf("%d",s);
}
return 0;
}
the output is only coming for the non-zero values. for ex: input 90100 9 output 1891099
but for this above program we have got the output as 1810...can anyone correct the logic...and explain it
+ 1
ok, i can make u it using array
+ 1
anything needed explain?