Find Here !!!

Tuesday, 22 April 2014

Program Sederhana Menentukan Data Terkecil \ Terbesar

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

void main()
{
 int n,i,j;
  int nilai [100], temp;
 cout<<"JumLah data = "; cin>>n;

 for(i=0;i<n;i++) {
 cout<<"data ke-"<<i+1<<" = ";
 cin>>nilai[i];
 }


 for (j=0;j<n;j++) {
  for (i=0;i<n-1;i++) {
  if (nilai[i]<nilai[i+1]) {
  temp = nilai[i];
  nilai [i]= nilai[i+1];
  nilai[i+1] = temp;
}
}
  }
  for(i=0;i<n;i++)
  cout<<" "<<nilai[i];
  cout<<"\nnilai terbesar = "<<nilai[i<n]<<"\n";
  cout<<"nilai terkecil = "<<nilai[n-1];
  cout<<endl;
  }

No comments:

Post a Comment