0
A c++ program to calculate the square of odd numbers between 1 and n
C++
3 Respuestas
+ 2
Break your problem down into small pieces and build it one piece at a time.
First, your going to need to get n.. Perhaps take user input and store it into a variable.
Next I would get an array of odd numbers. Use a for loop to build an array list from 1 thru n.. Before you add the number, check if it is odd using % ..
if (x % 2 !=0) then add it to the array
Once you have the array, decide what you want to do with those numbers. You want to calculate the square of them.. Perhaps a job for a foreach loop (assuming c++ has that, I dont know C++) ...
All problems are solvable, just break it into pieces and build it
+ 1
Home work?
0
can Your Write the real code for me