Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Studente : Scia Massimiliano
- Classe : 3IC
- Data : 15/04/2012 12:04
- Nome del file : ordina valori
- */
- #include <iostream>
- #include <cmath>
- #include <ctime>
- #include <cstdlib>
- #include <cctype>
- #include <windows.h>
- #include <fstream>
- #include <time.h>
- #include <stdio.h>
- #define N 100
- using namespace std;
- struct valori{
- int x;
- };//valori
- void end(void){
- fflush(stdin);
- cout<<"\n\nPremere Invio per continuare.";
- getchar();
- }//end
- int dim(){
- int n;
- cout<<"\nQuanti valori vuoi inserire? ";
- cin>>n;
- return n;
- }//dim
- valori val(){
- valori k;
- cin>>k.x;
- return k;
- }//val
- void val_val(valori k[], int n){
- for(int i=0;i<n;i++){
- cout<<"\nIl "<<i+1<<"' valore e`: ";
- k[i]=val();
- }//for
- }//val_val
- void scambia(int* a, int* b){
- int s;
- s=*a;
- *a=*b;
- *b=s;
- }//scambia
- void ordina(valori k[], int n){
- for(int i=0;i<n;i++)
- for(int j=i+1;j<n;j++)
- if(k[i].x>k[j].x)
- scambia(&k[i].x,&k[j].x);
- }//ordina
- void visualize(valori k[], int n){
- cout<<"\nI valori ordinati sono:\n\n";
- for(int i=0;i<n;i++)
- cout<<k[i].x<<" ";
- }//visualize
- int main(){
- valori k[N];
- int n=dim();
- val_val(k,n);
- ordina(k,n);
- visualize(k,n);
- end();
- return 0;
- }//main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement