Array

i was try to make some c++ program using array 1 dimention but i really confused. i'd try to make some program who input 1, 2, 3, 4 and 5 but in the last, the output will be 2, 3, 4, 5 and 1. can someone help me, please?
Can you post your code? We can't do much without seeing your code.
Can we see some code?
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
int data[5];
int i, j, tmp;
for(i=0; i<5; i++)
{
cout<<"Enter 5 Number Value: "<<(i+1)<<" : ";
cin>>data[i];
}

for(i=0; i<9; i++)
{
for(j=i+1; j<5; j++)
{
if(data[i]>data[j])
{
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
}
}
cout<<"Sorting Number: "<<endl;
for(i=0; i<5; i++)
{
cout<<data[i]<<" ";
}
getch();
}

it still sorting increase number, the output will be 1 2 3 4 5. i must make the output will be 2, 3, 4, 5, 1. please help
What is the specification for getting that output?
Example. Following the same rules used to get that output, what will be the output for
1 3 2 6 7 0?
the number must be 1 2 3 4 5. it must be input, not already yet in array.
Yeah i know that have to be input. I meant what if the user inputs
1 3 2 6 0
for the 5 numbers instead of
1 2 3 4 5

What output will you expect?
You should format your code with the format tags.

You're accessing elements beyond the end of your array.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include<iostream>
#include<conio.h>
using namespace std;
int main()
{
	int data[5];
	int i, j, tmp;
	for(i=0; i<5; i++)
	{
		cout<<"Enter 5 Number Value: "<<(i+1)<<" : ";
		cin>>data[i];
	}

	for(i=0; i<9; i++)	// OUT OF BOUNDS
	{
		for(j=i+1; j<5; j++)
		{
			if(data[i]>data[j])
			{
				tmp = data[i];
				data[i] = data[j];
				data[j] = tmp;
			}
		}
	}
	cout<<"Sorting Number: "<<endl;
	for(i=0; i<5; i++)
	{
		cout<<data[i]<<" ";
	}
	getch();
}

the output will be 3 2 6 0 1
ok. lets make this easier.
the numbers 1 2 3 4 5 has already yet in array. not must be input. so, how to make the output will be 2 3 4 5 1?
pleasee
Then you just have to swap the first and last position of the array.
1
2
#include <algorithm>
swap(data[0],data[4]);
i use swap but theres an error: expected constructor, destructor, or type conversion before '(' token|
how to solve that?
CODE??
#include<iostream>
#include<conio.h>
#include<algorithm>
swap(data[0], data[4]);
using namespace std;
int main()
{
int data[5];
int i, j, tmp;
for(i=0; i<5; i++)
{
cout<<"Enter 5 Number Value: "<<(i+1)<<" : ";
cin>>data[i];
}

for(i=0; i<9; i++)
{
for(j=i+1; j<5; j++)
{
if(data[i]>data[j])
{
tmp = data[i];
data[i] = data[j];
data[j] = tmp;
}
}
}
cout<<"Sorting Number: "<<endl;
for(i=0; i<5; i++)
{
cout<<data[i]<<" ";
}
getch();
}
Is this what you want??
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#include <iostream>
#include <algorithm>
#include <conio.h>
using namespace std;

int main()
{
	int data[5];
	int i, j, tmp;
	for(i=0; i<5; i++)
	{
		cout<<"Enter 5 Number Value: "<<(i+1)<<" : ";
		cin>>data[i];
	}

	for(int i = 0; i < 4; i++)
	{
		swap(data[i],data[i+1]);
	}
	cout<<"Sorting Number: "<<endl;
	for(i=0; i<5; i++)
	{
		cout<<data[i]<<" ";
	}
	
	getch();
}
thankyouu
Topic archived. No new replies allowed.