Monday, 16 March 2015

Mengurutkan NIlai Terkecil ke Terbesar

#include<conio.h>
#include<stdio.h>
#include<iostream.h>

main(){
int a[50],jml;

   cout<<"Masukkan jumlah data : ";
   cin>>jml;

   for (int i=0;i<jml;i++){
    cout<<"Masukkan angka "<<i+1<<" : ";
    cin>>a[i];
   }

   int x;
   for (int i=0;i<jml-1;i++)
    for (int j=i+1;j<jml;j++){
    if (a[i]>a[j]){
          x=a[i];
            a[i]=a[j];
            a[j]=x;
         }
    }

   for (int i=0;i<jml;i++){
    cout<<a[i]<<" ";
   }

getche();//header conio.h
}

No comments:

Post a Comment

Konversi Suhu

#include <iostream> #include <conio.h> //#include <cstdlib> //#include <iostream.h> void main( float Celcius, Kelvi...