i wrote in my prog

#include <iostream>
using namespace std;
int main ( )
{

int arraysize = 25;
int a [arraysize] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 }


wut kinda for loop do i need to print out 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 these numbers in reverse order..i used array for this programme.

Recommended Answers

All 7 Replies

Greetings bryan7890,

Do you want to print those numbers in reverse order as in starting at the last array and read until the first, or are you trying to sort the array to ascend or descend accordingly?


- Stack Overflow

this is C++ question

Write a complete program that staticaly declares an array with the following values:

2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3

and manipulates the resulting array so that the values in the array and reversed.
Print out the new array, which should look as follows:

-3, 0, 242, 324, 62, 64, 35, 57, 19, 21, 29, 35, 62, 93, 82, 45, -3, 123, 35, 20, 4, 19, 5, 3, 2

Note:
- you must use for-loop structure in order to complete your manipulations
- you may use only one (1) array - cannot create second array

if i had to declare numbers, we lets say 1 through 25 (not inclusing 1 and including 25) this how would i do it.
int[25];
for (int k= 1; k<=25;++k){
a[k] = kj
}

but this thing is really confusing, because the numbers are not in pattern.

how about

for(int i=24;i>=0;i--)
{
cout<<a<<" "<<endl;
}

#include <iostream>

using namespace std;

int main()
{

int a [] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324\
, 242, 0, -3 };

int size = sizeof(a);

cout << size << endl << endl;

for(int i = 0; i <= size; i++)
{
cout << a << " ";
}

}

y i m geeting this kinda output..

2 3 5 19 4 20 35 123 -3 45 82 93 62 35 29 21 19 57 35 64 62 324 242 0 -3 -4260908 5 -4260800 0 0 1 -4260916 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 -4260680 0 -4260674 -4260650 -4260637 -4260623 -4260604 -4260597 -4260428 -4260392 -4260353 -4260340 -4260326 -4260302 -4260289 -4260255 -4260238 -4260230 -4260177 -4260161 -4260152 -4260124 -4260099 -4260088 -4260079 -4259905 -4259898 -4259878 0 2008 -4259868 2014 -4259850 3 65588 4 32 5 5 9 67004 7 -12910592 8 2816 6

and numbers are not in reverse order..

Well,

kakilang's for loop looked like:

for(int i = 24; i >= 0; i--)

While yours looks like

for(int i = 0; i <= size; i++)

The difference is that you start at 0 [the beginning] and looping until the end. kakilang's example starts at the end, and loop until the beginning decrementing instead of incrementing.

Also, C provides a compile-time unary operator called sizeof that can be used to compute the size of any object. Here, we are not looking to find the size of the object, our goal is to know the size of our array. By simply creating the array with a fixed number of 25 may help. For example:

#define SIZE 25

int main() {
	int i, a[SIZE] = { 2, 3, 5, 19, 4, 20, 35, 123, -3, 45, 82, 93, 62, 35, 29, 21, 19, 57, 35, 64, 62, 324, 242, 0, -3 };

	// Start at end; decrement to beginning
	for (i = SIZE-1; i >= 0; i--)
		...

Where the ... means to keep going. This was just an example, and hopefully it helps.

If you have further questions, please feel free to ask.


- Stack Overflow

thanx everyone who helped me apriciated.. i finally got it to work..thanxx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.