Its a program for reversing an arr,but th code is acc C++ for 12th,after compiling there's no error but I won't get the output? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Its a program for reversing an arr,but th code is acc C++ for 12th,after compiling there's no error but I won't get the output?

https://code.sololearn.com/c3Hxko44lxEu/?ref=app

24th Jun 2020, 2:54 AM
Yash Sarnaik
13 Answers
25th Jun 2020, 6:36 AM
Yash Sarnaik
+ 2
You can change your code to this: for(int k=19;k>=0;k--){ out[19-k]=in[k]; } for (int l=0; l<20; l++) cout << out[l]; You can't use same index "i" for every loop cause it keeps changing.
24th Jun 2020, 3:35 AM
Blue!!
Blue!! - avatar
+ 1
Good luck, I am not that into C++, I usually code in Java, so my syntaxes might be different than yours.
24th Jun 2020, 6:20 AM
Blue!!
Blue!! - avatar
0
But we need to store the word in 'out' from 'in' ...so we need same var...isn't it
24th Jun 2020, 5:48 AM
Yash Sarnaik
0
Yes, I stored it, in out[19-k]=in[k] If you want words, then char can't store words you need to use string.
24th Jun 2020, 5:51 AM
Blue!!
Blue!! - avatar
0
Its a char array.. it can store a word I think... I hv introduced third array temp n did it like swapping but didn't got the output
24th Jun 2020, 6:03 AM
Yash Sarnaik
0
Okay, give me a sample, what you want to input, and what you expect the output to be.
24th Jun 2020, 6:05 AM
Blue!!
Blue!! - avatar
0
Just rev the input: Blue eulB
24th Jun 2020, 6:06 AM
Yash Sarnaik
0
Yes thats a string. Char can hold only one letter. In sololearn playground you have to enter it like this: B l u e Split it in line.
24th Jun 2020, 6:10 AM
Blue!!
Blue!! - avatar
0
Ok..then I will try to use strcpy n getline functions
24th Jun 2020, 6:13 AM
Yash Sarnaik
0
If its working.. then good.. I haven't checked yet.. though it seems correct.. and you didn't use getline or strcpy
25th Jun 2020, 8:22 AM
Blue!!
Blue!! - avatar
0
I tried getline n strcpy bt it didn't .. So I used simply 'cin' instead
25th Jun 2020, 8:25 AM
Yash Sarnaik
0
Okay, good
25th Jun 2020, 8:26 AM
Blue!!
Blue!! - avatar