Pages

Selasa, 19 Juni 2012

Contoh sederhana koding program C++ dengan Dev C++



Deret angka

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


main()
{
int n,m;
cout<<"  Deret angka "<<endl<<endl;


for(n=1;n<=9;n++)
{ cout<<n<<", "; }
{ cout<<"10."; }
cout<<endl<<endl;


for(m=10;m>=2;m-=1)
{ cout<<m<<", "; }
{ cout<<"1."; }
cout<<endl<<endl;


getch();
}

Input nilai part 1
#include <iostream.h>
#include <conio.h>
int main()
{
    int n1, n2;
    cout<<"Masukkan data anda :"<<endl<<endl;
    cout<<"Input nilai-1 = ";
    cin>>n1;
    cout<<"Input nilai-2 = ";
    cin>>n2;
    cout<<endl<<endl;
    cout<<"Data anda adalah "<<n1<<" & "<<n2; 
    getch ();
    return 0;
}

Input nilai part 2
#include <iostream.h>
#include <conio.h>
int main ()
{ char Nama [666];
  int  NPM;
  int Nilai;
system ("cls");
cout <<"Input Nama : "; cin.getline (Nama,666);
cout <<"Input NPM  : ";
cin>>NPM;
cout <<"Input Nilai = ";
cin>>Nilai;
system ("cls");
cout <<"Nama Anda : "<<Nama<<endl;
cout <<"NPM Anda : "<<NPM<<endl;
cout <<"NPM Anda adalah bil.";
if (NPM%2==0)
cout <<"GENAP";
else cout <<"GANJIL"; 
if (Nilai >=60 && Nilai <100)
cout <<"\nLulus";
else if (Nilai >=0)
cout <<"\nGagal";
else
cout <<"..............."; 
cout <<"\nNilai Anda = "<<Nilai;
getch ();
return 0;
}

Semoga bermanfaat kodingannya ya bloggers ! ;D
Don't repost please.

Tidak ada komentar:

Posting Komentar