Monday, 16 March 2015

Mencari Nilai Tertinggi


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

main(){
int a[3];


   for (int i=0;i<3;i++){
    cout<<"Masukkan angka "<<i+1<<" : ";
    cin>>a[i];
   }
   int x;
   for (int i=0;i<2;i++)
    for (int j=i+1;j<3;j++){
    if (a[i]>a[j]){
          x=a[i];
            a[i]=a[j];
            a[j]=x;
         }
    }

   cout<<"\nTertinggi : "<<a[2];
   cout<<"\nTengah : "<<a[1];
   cout<<"\nTerendah : "<<a[0];

getche();//header conio.h
}



Sumber : http://ilmusayabagi.blogspot.com/2013/03/c-mencari-nilai-tertinggi.html

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
}

Mencari Bilangan Terbesar

#include <cstdlib>
#include <iostream>

using namespace std;
void CariElemenTerbesar(int a[], int &maks){
     int k,n;
     maks = a[0];
     n = sizeof (a);
     for(k=2;k<=n;k++){
                       if (a[k] > maks){
                               maks = a[k];
                               }
                       }
     }
int main(int argc, char *argv[])
{
    int maks;
    int a[]={7,6,13,10,8,9};
    CariElemenTerbesar(a,maks);
    cout<<endl<<maks<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Mencari bilangan pangkat

#include <cstdlib>
#include <iostream>

using namespace std;
int pangkat (int a, int n)
{
      int k, hasil;
      hasil=1;
      for (k=1; k<=n; k++){
            hasil *= a;
            }
            return hasil;
      }     

int main(int argc, char *argv[])
{
    cout<<pangkat(2,3)<<endl;
    system("PAUSE");
    return EXIT_SUCCESS;
}

Konversi Suhu

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