ganjil apa genap.,,

#include<iostream.h>

#include<conio.h>

using namespace std;

int main()

{

char q;

int bilangan,hasil;

do

{

system(“cls”);

cout<<” | ========================|”<<endl;

cout<<” | Program Identifikasi Ganjil/Genap |”<<endl;

cout<<” |========================|”<<endl<<endl;

cout<<” Masukkan Bilangan : “;

cin>>bilangan;

cout<<endl;

hasil = bilangan%2;

if (hasil == 0)

{

cout<<” ” << bilangan <<” adalah : Bilangan genap”;

}

else

{

cout<<” ” << bilangan <<” adalah : Bilangan ganjil”;

}

cout<<endl<<endl;

cout<<” Ingin Hitung Kembali (y/t)?”;

cin>>q;

}

while(q==’y’);

return 0;

}

ganjilgenap

Posted in Struktur Control | Tagged , | Leave a comment

akar persamaan kuadrat .. D=b2-4ac

#include <cstdlib>

#include <iostream>

#include<math.h>

using namespace std;

int main()

{

char ulang;

double A,B,C,D, hasil1,hasil2,;

cout<<“===Akar persamaan Kuadrat  (D = B2 – 4AC) == “<<endl;

cout<<“==================================”<<endl;

do

{

A=0;

B=0;

C=0;

cout<<“A:”;

cin>>A;

cout<<“B:”;

cin>>B;

cout<<“C:”;

cin>>C;

D=(B*B)-(4*A*C);

cout<<A <<endl;

cout<<B <<endl;

cout<<C <<endl;

cout<<D <<endl;

if (D > 0)

{

hasil1=-B+sqrt(D)/(2*A);

hasil2=-B-sqrt(D)/(2*A);

cout<<“Ini merupakan 2 Akar yang berbeda : “<<endl;

cout<< “x1=” ;

cout<<hasil1 <<endl;

cout<< “x2=” <<hasil2 <<endl;

}

else if (D==0) {

hasil1=-B/(2*A);

hasil2=hasil1;

cout<<“Ini merupakan 2 Akar kembar : “<<endl;

cout<<“x1=”<<hasil1 <<endl;

cout<<“X2=”<<hasil2 <<endl;

}

else

{

hasil1=-B/(2*A);

hasil2=sqrt(fabs(D))/(2*A);

cout<<“Ini merupakan Akar Imaginer: “<<endl;

cout<<“x1=”<<hasil1<<“+”<<hasil2 <<endl;

cout<<“x2=”<<hasil1<<“-“<<hasil2 <<endl;

}

cout<<“===============================”<<endl;

cout<<“Ulangi penghitungan persamaan kuadrat dengan rumus (D = B2 – 4AC) <y/t> ? “;

cin>>ulang;

} while(ulang==’y’);

return 0;

}

akar_persamaan

Posted in Algoritma Pemrograman & Elemen Dasar C++ | Tagged , | Leave a comment