how do i gain karma points to ask question ?
should i ask here?
maybe if someone sees this please solve this.
the question is from beginners section FLOW007 - reversing the number.
the code goes:
#include<stdio.h>
#include<math.h>
int main()
{
int t,num,temp,n,i,j,sum;
scanf("%d",&t);// no of test cases
while(t>0){
scanf("%d",&num);// asking the number
temp=num;
n=0;
while(temp>0){
temp=temp/10;
n++;// counting no of digits in the number given
}
int a[n];
sum=0;
for(i=0;i<n;i++){
a[i]=num%10;// storing each digit in an array cell
num=num/10;
sum=sum + a[i]*pow(10,(n-(1+i)));//summing by expanding
}
printf("%d\n",sum);
t–;
}return 0;
}
i am getting correct reversed number for all numbers except 3-digit numbers.
please solve someone.
thanks
#include<stdio.h>
#include<math.h>
int main()
{
int t,num,temp,n,i,j,sum;
scanf(“%d”,&t);// no of test cases
while(t>0)
{
scanf(“%d”,&num);// asking the number
temp=num;
n=0;
while(temp> 0)
{
temp=temp/10;
n++;// counting no of digits in the number given
}
int a[n];
sum=0; for(i=0;i< n;i++)
{
a[i]=num%10;// storing each digit in an array cell
num=num/10;
sum=sum + a[i]*pow(10,(n-(1+i)));//summing by expanding
}
printf(“%d\n”,sum);
t–;
}
return 0;
}
What are you saying? Your code passed all test cases. Copy-paste it and try again. See here.