0

A c++ program to calculate the square of odd numbers between 1 and n

C++

21st Nov 2018, 11:04 PM
Akins
Akins - avatar
3 Antworten
+ 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
21st Nov 2018, 11:35 PM
LordHill
LordHill - avatar
+ 1
Home work?
22nd Nov 2018, 10:45 AM
LordHill
LordHill - avatar
0
can Your Write the real code for me
22nd Nov 2018, 10:09 AM
Akins
Akins - avatar