1. Kasus 4.1
Flowchart :
Dev C++ :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
for (int i=1;i<=4;i++)
{
cout << i << " \t " ;
}
return 0;
}
2. Kasus 4.2
Flowchart :
Dev C++ :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
for ( int i = 1; i<10; i++ )
{
if ( i % 2 == 1)
cout << i << "\t";
}
return 0;
}
3. Kasus 4.3
Flowchart :
Dev C++ :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int n, i;
cout << " Masukan Jumlah Suku : " ; cin >> n; cout << endl;
cout << " Nilai Suku Pertama : " ; cin >> i; cout << endl;
while (i<n)
{
cout << i << " \t ";
i = i + 1;
}
return 0;
}
4. Kasus 4.4
Flowchart :
Dev C++ :
#include <iostream>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int n, nilai, x, jumlah;
float rata;
cout << " Masukan Banyak Nilai : "; cin >> n;
for (int i=1 ; i<=n ; i++ )
{
cout << " Masukan Nilai Ke- " << i << ": "; cin >> x;
jumlah=jumlah+x;
}
rata = jumlah/n;
cout << " Jumlah Nilai Keseluruhan : " << jumlah << endl;
cout << " Rata-rata Nilai : " << rata;
return 0;
}
5. Kasus 4.7
Flowchart :
Dev C++ :
#include <iostream>
#include <math.h>using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int bil, pangkat, hasil;
cout << " Masukan Angka Bilangan : "; cin >> bil;
cout << " Masukan Pangkat Bilangan : "; cin >> pangkat;
hasil = pow(bil,pangkat);
cout << " Jadi " << bil << " Pangkat " << pangkat << " adalah " << hasil;
return 0;
}
6. Kasus 4.8
Flowchart :
Dev C++ :
#include <iostream>
#include <math.h>using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */
int main(int argc, char** argv) {
int jumlah, bil1, bil2;
cout << " Masukan Angka Pertama "; cin >> bil1;
cout << " Masukan Angka Kedua "; cin >> bil2;
for ( int i = 0;i<abs(bil2);i++)
{
jumlah += bil1;
}
if (bil2<0) jumlah = -jumlah;
cout << bil1 << " x " << bil2 << " = " << jumlah << endl;
return 0;
}
Terimakasih dan selamat mencoba
0 komentar:
Posting Komentar