Jump to content
Sign in to follow this  
Vova

Ordonare crescator/descrescator sir numere C++

Recommended Posts

Sa se ordoneze crescator/descrescator un sir de n numere naturale. Cine ma poate ajuta sa gasesc gresela?

#include <iostream>
	#include <conio.h>
using namespace std;
int main()
{
	    int s[100], n, i, j, tmp = 0;
    cout << "Numarul de componente in vector sunt: "; cin >> n;
    for (i = 0; i < n; i++) {
        cout << "s[" << i << "]=";
        cin >> s;
    }
    for (j = 1; j <= n; j++) {
        for (i = 0; i = n - 1; i++) {
            if (s > s[i + 1]) {
                tmp = s;
                s = s[i + 1];
                s[i + 1] = tmp;
            }
        }
    }
	    for (i = 0; i < n; i++) {
        cout << s << endl;
    }
	
    _getche();
    return 0;
}

Share this post


Link to post
Share on other sites

Foloseşte tag-ul [ CODE ], deoarece la [ i ] ţi-l converteşte forumul la text italic...

 

Share this post


Link to post
Share on other sites

Asta e tot? :O

Daca tot ai 2 INCLUDE, foloseste si la primul rand ( iostream.h )

Le vrei sortate folosind insertia sau prin numarare?

Tu trebuie a ai 3 parti, A, B, C, in genul: 

#include <iostream.h>

int a[25], b[25], c[25]

count << si aici numarul de elemente>>

Iar A, B, C trebuie duse in aceasi directie.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×