Pages - Menu
▼
Senin, 15 Agustus 2011
Deret Bilangan Prima (Fungsi)
#include < iostream.h>
void bilprima();
void main()
{
bilprima();
}
void bilprima()
{
int i,j;
for (i=1;i<=50;i++)
{
if (i==2)
cout<
else
{
for (j=2;j
{
if (i % j==0)
{ break; }
else
{
cout <<","<
break;
}
}
}
}
}
Minggu, 14 Agustus 2011
Mencari Bilangan Tertinggi dengan Fungsi C++
#include < iostream.h>
int maks(int a,int b,int c);
void main()
{
int a,b,c;
int max;
cout<<"a = "; cin >> a;
cout<<"b = "; cin >> b;
cout<<"c = "; cin >> c;
max = maks(a,b,c);
cout<
cout<<"Maksimal adalah = " << max;
}
int maks(int a,int b,int c)
{
int max;
max = a;
if(max < b)
{
max = b;
if(max < c)
{
max = c;
}
}
else if(max < c)
{
max = c;
}
else
{
max = a;
}
return max;
}
Sabtu, 06 Agustus 2011
Menentukan Bilangan Genap Ganjil dalam Fungsi C++
#include < iostream.h >
int genapganjil(int x);
void main()
{
int x;
cin >> x;
genapganjil(x);
}
int genapganjil(int x)
{
if(x % 2 == 0)
{
cout<<"Nilai Genap";
}
else
{
cout<<"Nilai Ganjil";
}
}
int genapganjil(int x);
void main()
{
int x;
cin >> x;
genapganjil(x);
}
int genapganjil(int x)
{
if(x % 2 == 0)
{
cout<<"Nilai Genap";
}
else
{
cout<<"Nilai Ganjil";
}
}