Program 1
// file fk01_1.cpp
// program mencetak kata dalam beberapa baris
#include <iostream>
// fungsi utama
int main()
{
std::cout << “Fisika\nKomputasi\n\nDengan C++!\n”;
return 0; // akhir program

Program 2
// file fk01_1.cpp
// program mencetak kata dalam beberapa baris
#include <iostream>
// fungsi utama
int main()
{
std::cout << “Welcome “;
std::cout << “to C++!\n”;
return 0; // akhir program
} // akhir fungsi utama

Program 3
// file fk01_3.cpp
// Program penambahan
#include <iostream>
// fungsi utama
int main()
{
int integer1; // nilai pertama yang di input
int integer2; // nilai kedua yang di input
int sum; // variable untuk menyimpan hasil tambah
std::cout << “Enter first integer\n”; // label
std::cin >> integer1; // ambil nilai pertama
std::cout << “Enter second integer\n”; // label
std::cin >> integer2; // ambil nilai kedua
sum = integer1 + integer2; // masukkan kedalam rumus tambah
std::cout << “Sum is ” << sum << std::endl; // cetak hasil tambah
return 0; // selesai program
} // akhir fungsi utama

Program 4
// file fk01_4.cpp
// program yang menggunakan if dan operator
#include <iostream>
using std::cout; // penggunaan cout
using std::cin; // penggunaan cin
using std::endl; // penggunaan endl
// fungsi utama
int main()
{
int num1; // nilai pertama yang di input
int num2; // nilai kedua yang di input
cout << “Enter two integers, and I will tell you\n”
<< “the relationships they satisfy: “;
cin >> num1 >> num2; // baca dua nilai
if ( num1 == num2 )
cout << num1 << ” is equal to ” << num2 << endl;
if ( num1 != num2 )
cout << num1 << ” is not equal to ” << num2 << endl;
if (num1 < num2 )
cout << num1 << ” is less than ” << num2 << endl;
if ( num1 > num2 )
cout << num1 << ” is greater than ” << num2 << endl;
if ( num1 <= num2 )
cout << num1 << ” is less than or equal to “
<< num2 << endl;
if ( num1 >= num2 )
cout << num1 << ” is greater than or equal to “
<< num2 << endl;
return 0; // akhir program
} // akhir fungsi utama

Program 5
// file fk02_01.cpp
// Menjumlahkan nilai dari 1 sampai dengan 10.
#include <iostream>
using std::cout;
using std::endl;
// fungsi utama
int main()
{
int sum; // variabel sum untuk menyimpan
int x; // variabel x sebagai hitung
x = 1; // hitung mulai dari 1
sum = 0; // permulaan sum
while ( x <= 10 ) {
sum += x; // tambah x ke sum
++x; // naikkan nilai x sejumlah 1
} // akhir while
cout << “The sum is: ” << sum << endl;
return 0; // akhir program
} // akhir fungsi utama

Program 6
// program fk02_2.cpp
// x pangkat y.
#include <iostream>
using std::cout;
using std::cin;
using std::endl;
// fungsi utama
int main()
{
int x; // dasar
int y; // pangkat
int i; // hitung dari 1 ke y
int power; // hintung x pangkat y
i = 1; // i mulai dari 1
power = 1; // mulai pangkat
cout << “Enter base as an integer: “; // label
cin >> x; // masukkan x
// untuk pangkat
cout << “Enter exponent as an integer: “;
cin >> y; // masukkan pangkat
// hitung dari 1 ke y dan kali pangkat x
while ( i <= y ) {
power *= x;
++i;
} // akhir while
cout << power << endl; // tampilkan hasil
return 0; // akhir program
} // akhir fungsi utama

Program 7
// program fk02_3.cpp
// Total nilai
#include <iostream>
using std::cout;
using std::endl;
// fungsin utama
int main()
{
int y; // deklarasi y
int x = 1; // mulai x
int total = 0; // mulai total
while ( x <= 10 ) { // looping 10 kali
y = x * x; // hitung dengan kali
cout << y << endl; // hasil
total += y; // tambah y ke total
++x; // tambahkan x
} // akhir while
cout << “Total is ” << total << endl; //tampilkan hasil
return 0; // akhir program
} // akhir fungsi utama

<!– /* Font Definitions */ @font-face {font-family:”Cambria Math”; panose-1:2 4 5 3 5 4 6 3 2 4; mso-font-charset:0; mso-generic-font-family:roman; mso-font-pitch:variable; mso-font-signature:-1610611985 1107304683 0 0 159 0;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {mso-style-unhide:no; mso-style-qformat:yes; mso-style-parent:”"; margin:0in; margin-bottom:.0001pt; mso-pagination:widow-orphan; font-size:12.0pt; font-family:”Times New Roman”,”serif”; mso-fareast-font-family:”Times New Roman”;} .MsoPapDefault {mso-style-type:export-only; margin-bottom:10.0pt; line-height:115%;} @page Section1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in; mso-header-margin:.5in; mso-footer-margin:.5in; mso-paper-source:0;} div.Section1 {page:Section1;} –>
/* Style Definitions */
table.MsoNormalTable
{mso-style-name:”Table Normal”;
mso-tstyle-rowband-size:0;
mso-tstyle-colband-size:0;
mso-style-noshow:yes;
mso-style-priority:99;
mso-style-qformat:yes;
mso-style-parent:”";
mso-padding-alt:0in 5.4pt 0in 5.4pt;
mso-para-margin-top:0in;
mso-para-margin-right:0in;
mso-para-margin-bottom:10.0pt;
mso-para-margin-left:0in;
line-height:115%;
mso-pagination:widow-orphan;
font-size:11.0pt;
font-family:”Calibri”,”sans-serif”;
mso-ascii-font-family:Calibri;
mso-ascii-theme-font:minor-latin;
mso-fareast-font-family:”Times New Roman”;
mso-fareast-theme-font:minor-fareast;
mso-hansi-font-family:Calibri;
mso-hansi-theme-font:minor-latin;
mso-bidi-font-family:”Times New Roman”;
mso-bidi-theme-font:minor-bidi;}
Program 8
// program fk02_4.cpp
// apa hasilnya
#include <iostream>
using std::cout;
using std::endl;
// fungsi utama
int main()
{
int count = 1; // mulai hitung
while ( count <= 10 ) { // loping 10 kali
// hasil teks
cout << ( count % 2 ? “****” : “++++++++” )
<< endl;
++count; // tambahkan count
}
return 0; // akhir program
} // akhir fungsi utama
