+ 8

Where is the problem in my code Strange root?

In Strange root challenge,when I input 7 the output should true. but it show false. I can't fix this. Someone help plz. As I used array first time. #include <stdio.h> #include<math.h> int times(int n); int main() {     int n,s,p,r,i,r1,r2,z,m;     double st,d;     scanf("%d",&n);     printf ("Input: %d",n);     s=n*n;     st=sqrt(n);     printf ("\nSquare: %d",s);     int intpart=(int)st;     double decpart=st-intpart;     d=decpart*1000;     int intpart2=(int)d;     p=intpart2;     i=100;     do     {         r=p%i;         i/=10;         if(r==0)         p/=10;         else         continue;     }while(r==0);     printf ("\nSquared first 3 digit: %d",p);     m=times(p);     z=times(s);     int sq[z],sqt[m];     do     {         r2=s%10;         scanf("%d",&sq[r2]);         s/=10;     }while(s>0);     do     {         r1=p%10;         scanf("%d",&sqt[r1]);         p/=10;     }while(p>0);     if(sq[r1]!=sqt[r2])     printf("\nNo strange https://code.sololearn.com/cfriNFAXiZT7/?ref=app

27th Sep 2018, 6:36 AM
Coder
Coder - avatar
4 ответов
+ 3
Md Ibrahim Bhuyia I think you are not doing it properly... why you want to compare array at r1 and r2 index only...? r1 and r2 are index of array you are trying to compare... r1 is 3 as 645 is sqrt of 7.. r2 is 2 as you are having 49 as sqr of 7... so, you can't compare r1 and r2 index.. what you have to do is loop through max index (r1 or r2) from zero and check if other array contains that or not... try or let me know if you want me to help on it..
27th Sep 2018, 7:22 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 7
'Keran Lalcheta' can you please give me the right formate in coding playground. It could really helpful for me!!
27th Sep 2018, 8:28 AM
Coder
Coder - avatar
+ 2
Md Ibrahim Bhuyia below is my code for c++ : https://code.sololearn.com/cn59YYKI5GZq/?ref=app do you want the same in c only ??
27th Sep 2018, 10:21 AM
Ketan Lalcheta
Ketan Lalcheta - avatar
+ 1
Md Ibrahim Bhuyia additional to above, I don't understand why you are doing scanf as below : scanf("%d",&sq[r2]); you need to store value into array and it can be stored with assignment operator rather than scanf ..scanf is for user input... you should do below : sq[0]= value of decimal digit
27th Sep 2018, 7:34 AM
Ketan Lalcheta
Ketan Lalcheta - avatar