Jumat, 02 November 2012

TUGAS 4 PEMOGRAMAN C++


PROGRAM MENAMPILKAN BILANGAN PRIMA

SCRIPTNYA


#include<iostream.h>
int main ()
{
    int i,n;
cout<<" Deni Herdiansyah "<<endl;
cout<<"TI-111023  "<<endl;
cout<<"menampilkan bilangan prima " <<endl<<endl;
    cout<<"masukkan jumlah angka yang dinginkan= ";
    cin>>n;
    cout<<"angka primanya adalah ";
    for( i=2;i<=n;i++)
        { if ( i%2==1&&i%i==0)
        {cout<<" "<< i;}
        else if ( i==2){ cout<<" "<<i;}
        }
}

hasilnya
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhb7H2hn6pVQcyYIGviknbNplyccjscDqNaHV00MZh53WVBI7pQxd0yr9u2FNIrG7qjmWNuMY_PTVlv6RnmNIKfvdupM-tPLjd1IIcm_wqQAu2s6nCeveU0f6LqqkUPJ9Rh4LcjXtHQk9Q/s320/bilangan+prima+robby.jpg


PROGRAM PSIKOTES

PROGRAM PSIKOTES

SCRIPTNYA :


#include<iostream.h>
int main ()
{
    int i,n,w;
    w=3;
cout<<" Deni Herdiansyah "<<endl;
cout<<"TI-111023  "<<endl;
cout<<"membuat program psikotes " <<endl<<endl;
    cout<<"masukkan banyaknya angka tes yang anda inginkan ";
    cin>>n;
    cout<<"hasilnya adalah ";
    for( i=1;i<=n;i++)
    {w= w + i ;
     cout<<" "<< w;
    }
}

hasilnya :
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhmDJDTpSHXr0Fj33iOCpbtG8ogkKyfp_VP6dR0D9fKo9t7ZSaSMXiTGfaPHzCQr1sB3_vPvGezwYgTleslF88vzL0_QMQzu22lGR_aCmbCffaUL_YF5cscfhVON0tKfio8igf7lI4nj00/s320/psikotes+robby.jpg

PROGRAM PERULANGAN DENGAN FOR

PROGRAM PERULANGAN DENGAN FOR

SCRIPTNYA :


#include<iostream.h>
int main()
{
    int n,i;
cout<<" Deni Herdiansyah "<<endl;
cout<<"TI-111023  "<<endl;
cout<<"membuat program perulangan dengan for " <<endl<<endl;
    cout<<"masukkan angka yang diinginkan ";
    cin>>n;
    for(i=1;i<=n;i++)
        {if(i%2==0)
        {cout<<" "<<i*-1;}
        else cout<<" "<<i;
        }
}

hasilnya :
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEhx5iva3ntrIhZy-Y9EFvV_1CB46nrG_-lZW6xkTUrVwB107GLtdjwEZVepDW1ZJk8dT1nNMs0FxA0sHZoXQ5uz0WZAt1CpSC-GhqZg_5hlVHhrOCwL2qZeKMcEDDPaoqkzLEMEpC-KBbc/s320/perulangan+robby.jpg

PROGRAM MENGEHITUNG RATA-RATA

PROGRAM MENGEHITUNG RATA-RATA

scriptnya :


#include<iostream.h>
int main()
{
    int nilai,n,i,tot;
    tot=0;
cout<<" Deni Herdiansyah "<<endl;
cout<<"TI-111023  "<<endl;
cout<<"membuat program menghitung rata-rata " <<endl<<endl;
    cout<<"masukkan jumlah data ";cin>>n;
    for(i=1;i<=n;i++)
        {cout<<"Masukkan nilai ke-"<<i<<": ";
        cin>>nilai;
        tot=tot+nilai;
        }
    cout<<"TOTAL NILAI= "<<tot<<endl;
    cout<<"NILAI RATA-RATA= "<<tot/n<<endl;
}

hasilnya :
Description: https://blogger.googleusercontent.com/img/b/R29vZ2xl/AVvXsEjKtBSAY3n0bozz8jNn762L-eGvSc5sQG16s50ypvaXw75wvePEWh_Ltdq0WxnuOhcPQkB6T03nwXKfJPSApWtUvPpIh5Sa3wNpwv78EHFfx-QgKW4S9QCpYQabbdHlWsKlXwyzAQFPrYk/s320/rata2+robby.jpg


Tidak ada komentar:

Posting Komentar