0
C++help
I have a small problem in c++ I need a code whose output character string is formed from the characters of the source string with even ordinal numbers. Please help me
28 Answers
+ 3
char A B C D E F
index 0 1 2 3 4 5
B, D and F are all in odd indices ...
Which is it? odd or even?
+ 3
Alright, here's one way to implement it, not in code, though I'm sure you can figure it out
Let is_odd = false
For each character in text
If is_odd
Print the character
End if
Let is_odd = NOT is_odd
End For
Here <is_odd> initialized with false cause we begin loop from 1st character (index 0 ~ even), and <is_odd> will be inverted on each iteration.
+ 3
From index i=1 to str.length, print str[I] with i incrementing by 2=> i+=2 . simple.
+ 2
Pls post your try ..Daniel Alexis
+ 2
Sorry for the little inconvenience ๐
๐
I'm a little bad at C++ I'm pretty good at Python.Please you could make a very concrete example so that I could understand better.Please.
+ 2
Thx
+ 2
// I hope this link helps you
https://code.sololearn.com/cw5UvLs6C3bw
// or
for (int i=97; i<=122; i++) if (i%2==0) cout<<(char)i;
+ 2
Thx
+ 2
I will start very soon.Duty is for tomorrow ๐ญ
+ 1
Can you illustrate with example?
+ 1
Sorry, Odd
+ 1
Okay so from the illustration above
You can use the modulus operator to check if it odd the you just some them up
+ 1
I will try to figure out how to implement what you are telling me...tomorrow I have several exams of programmation.si I had the code already written, it would have made it easier for me.
+ 1
Loop through the characters of the source string. Check whether the character is even. If so, then print it.
if (source_string[i]&1==0)
cout << source_string[i];
+ 1
Thank you very much but I don't understand, because C++ is not really my field.
+ 1
Do you have a code already written?
+ 1
Daniel Alexis you might want to start learning C++ from the Sololearn tutorial. There you can learn about the char type, string type, arrays, input, output, loops, and all the syntax you need for this.
https://www.sololearn.com/Course/CPlusPlus/?ref=app
+ 1
I managed to display bdf but the teacher tells me that I must indicate abcdef too. Please help me.
+ 1
Daniel Alexis copy the code and paste in SL playground and save, share link here.. That's helps find easy solution.
Do you mean, you needed output is :
abcdefg
bdf
If yes, after 1st loop : print s
Like
cout<<s<<endl;