Program Menampilkan deret Alphabet
code:
#include<iostream.h>
#include<conio.h>
void main ()
{
char ch;
for (ch='A'; ch<='Z'; ch++ )
{cout<<ch; }cout<<endl;
getch();
}
Program menampilkan Deret Genap1 s/d 100
code :
#include<iostream.h>
#include<conio.h>
void main()
{
for (int i=1; i<=100; i+=2)
cout<<i+1<<" ";
getch();
}
Program menampilkan Deret Ganjil 1 s/d 100 :
code :
#include<iostream.h>
#include<conio.h>
void main()
{
for (int i=1; i<=100; i+=2)
cout<<i+1<<" ";
getch();
}
Program Menampilkan Deret Fibonacci menggunakan Function :
code :
#include <iostream.h>
#include <conio.h>
long hitung(int n)
{
long fn_1=1,fn_2=1,fn=1;
int i;
//cout<<"\n\n\n\";
for (i=1;i<=n; i++)
{
if(i!=1 && i!=2)
{
cout<<fn<<" ";
fn = fn_1 + fn_2;
fn_2 = fn_1;
fn_1 = fn;
}
else if(i==2)
cout<<"1 ";
}
return fn;
}
void main()
{
char pilih;
do{
long pjg,m;
clrscr();
cout<<"\nInput Deret ";
cin>>pjg;
m = hitung(pjg);
cout<<m;
cout<<"\nUlang deret ? ";
cin>>pilih;
}while(pilih=='Y' || pilih=='y');
getch();
}
code:
#include<iostream.h>
#include<conio.h>
void main ()
{
char ch;
for (ch='A'; ch<='Z'; ch++ )
{cout<<ch; }cout<<endl;
getch();
}
Program menampilkan Deret Genap1 s/d 100
code :
#include<iostream.h>
#include<conio.h>
void main()
{
for (int i=1; i<=100; i+=2)
cout<<i+1<<" ";
getch();
}
Program menampilkan Deret Ganjil 1 s/d 100 :
code :
#include<iostream.h>
#include<conio.h>
void main()
{
for (int i=1; i<=100; i+=2)
cout<<i+1<<" ";
getch();
}
Program Menampilkan Deret Fibonacci menggunakan Function :
code :
#include <iostream.h>
#include <conio.h>
long hitung(int n)
{
long fn_1=1,fn_2=1,fn=1;
int i;
//cout<<"\n\n\n\";
for (i=1;i<=n; i++)
{
if(i!=1 && i!=2)
{
cout<<fn<<" ";
fn = fn_1 + fn_2;
fn_2 = fn_1;
fn_1 = fn;
}
else if(i==2)
cout<<"1 ";
}
return fn;
}
void main()
{
char pilih;
do{
long pjg,m;
clrscr();
cout<<"\nInput Deret ";
cin>>pjg;
m = hitung(pjg);
cout<<m;
cout<<"\nUlang deret ? ";
cin>>pilih;
}while(pilih=='Y' || pilih=='y');
getch();
}
Tidak ada komentar:
Posting Komentar