Програма, която подрежда 10 числа по големина.

31 10 2010

Задача. Да се състави програма, която подрежда 10 числа от най-малкото към най-голямото.

За решението на програмата е използвана функцията if.

Една програма, която решава задачата е следна:

#include <iostream>
#include <iomanip>
using namespace std;
int main(){
 cout<<"Vavedete 10 chisla:"<<endl;

int q, w, e, r, t, y, u, i, o, p, x;
cin>>q>>w>>e>>r>>t>>y>>u>>i>>o>>p;

if (q>w) x=q, q=w, w=x;
if (q>e) x=q, q=e, e=x;
if (q>r) x=q, q=r, r=x;
if (q>t) x=q, q=t, t=x;
if (q>y) x=q, q=y, y=x;
if (q>u) x=q, q=u, u=x;
if (q>i) x=q, q=i, i=x;
if (q>o) x=q, q=o, o=x;
if (q>p) x=q, q=p, p=x;
if (w>e) x=w, w=e, e=x;
if (w>r) x=w, w=r, r=x;
if (w>t) x=w, w=t, t=x;
if (w>y) x=w, w=y, y=x;
if (w>u) x=w, w=u, u=x;
if (w>i) x=w, w=i, i=x;
if (w>o) x=w, w=o, o=x;
if (w>p) x=w, w=p, p=x;
if (e>r) x=e, e=r, r=x;
if (e>t) x=e, e=t, t=x;
if (e>y) x=e, e=y, y=x;
if (e>u) x=e, e=u, u=x;
if (e>i) x=e, e=i, i=x;
if (e>o) x=e, e=o, o=x;
if (e>p) x=e, e=p, p=x;
if (r>t) x=r, r=t, t=x;
if (r>y) x=r, r=y, y=x;
if (r>u) x=r, r=u, u=x;
if (r>i) x=r, r=i, i=x;
if (r>o) x=r, o=t, o=x;
if (r>p) x=r, r=p, p=x;
if (t>y) x=t, t=y, y=x;
if (t>u) x=t, t=u, u=x;
if (t>i) x=t, t=i, i=x;
if (t>o) x=t, t=o, o=x;
if (t>p) x=t, t=p, p=x;
if (y>u) x=y, y=u, u=x;
if (y>i) x=y, y=i, i=x;
if (y>o) x=y, y=o, o=x;
if (y>p) x=y, y=p, p=x;
if (u>i) x=u, u=i, i=x;
if (u>o) x=u, u=o, o=x;
if (u>p) x=u, u=p, p=x;
if (i>o) x=i, i=o, o=x;
if (i>p) x=i, i=p, p=x;
if (o>p) x=o, o=p, p=x;

cout<<setw(4)<<q<<setw(4)<<w<<setw(4)<<e<<setw(4)<<r<<setw(4)<<t<<setw(4)<<y<<setw(4)<<u<<setw(4)<<i<<setw(4)<<o<<setw(4)<<p<<setw(4)<<endl;

return 0;}

~S.K.G~


Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: