CODING: ========================================================= #include #include int main() { clrscr(); int x, y, z, bil=10; for( x = 1; x <= bil; x++ ) { for( z = bil; z >= x; z-- ) cout << ' '; for( z = x; z < 2*x; z++ ) { y = z % 10; cout << y; } for( z = 2*(x-1); z >= x; z-- ) { y = z % 10; cout << y; } cout << endl; } getch(); } 2. Tampilkan bilangan Ganjil dan Genap dari 1 sampai 20?
CODING: 1
TUGAS 1 TI 9 IMAM CIPTARJO – 6307130
========================================================= #include #include void main() { clrscr(); int angka; cout << "Angka Genap dari 1-20" << endl;; for (angka=2; angka<=20; angka+=2) cout << angka << endl;
ALGORITMA PEMROGRAMAN
cout << "\nAngka Ganjil dari 1-20" << endl;; for (angka=1; angka<=20; angka+=2) cout << angka << endl; getch(); } 3. Buat program konversi Celcius ke Fahrenheit?
CODING: ========================================================= #include #include void main() { clrscr(); float celcius, fahrenheit; char lagi='Y'; printf("Program konversi celcius ke fahrenheit \n"); do { printf("\nNilai celcius : "); scanf("%f", &celcius); fahrenheit=1.8*celcius+32; printf("Nilai fahrenheit : %.2f \n", fahrenheit); printf("Coba lagi (Y/T) ? "); scanf("%s", &lagi); } while (lagi=='Y' || lagi=='y'); getch(); } 4. Buat program menentukan bilangan prima dari n_awal ke n_akhir?
CODING: ========================================================= #include #include #include void prima(); int a,b,c; void main () {
2
TUGAS 1 TI 9 IMAM CIPTARJO – 6307130
clrscr (); cout<<"Masukkan nilai awal : "; cin>>a; cout<<"Masukkan nilai akhir: "; cin>>b; prima (); getch ();