Bab 6 Perulangan Proses (latihan)

  • Uploaded by: Bagus Windhya Kusuma Wardana
  • 0
  • 0
  • May 2020
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Bab 6 Perulangan Proses (latihan) as PDF for free.

More details

  • Words: 227
  • Pages: 6
Five: Proses Perulangan (Looping) Again and Again

DASAR PEMROGRAMAN by: Ahmad Syauqi Ahsan

Program ‘Pilihan’ #include <stdio.h> main() { char pil; do { printf("Ini programku\n"); printf("Bener lho ini programku\n"); printf("Mau ditulis lagi (Y/T)? "); scanf("%s", &pil); printf("\n"); } while ((pil == 'Y') || (pil == 'y')); } 2

Menghitung Jumlah Karakter #include <stdio.h> main() { char kar; int jumkar = 0, jumspasi = 0; printf("Masukkan kalimat, akhiri dgn ENTER.\n\n"); do { kar = getchar(); if (kar == ' ') jumspasi = jumspasi + 1; else jumkar = jumkar + 1; } while(kar != '\n'); printf("\nJumlah karakter = %d", jumkar - 1); printf("\nJumlah SPASI = %d\n\n", jumspasi); } 3

Menampilkan Bilangan Ganjil /*menampilkan bilangan ganjil antara 7 - 25 kecuali 15 */ #include <stdio.h> main() { int x = 5; do { x = x + 2; if (x == 15) break; printf("%d ", x); } while (x < 25); printf("\n"); }

4

Tabel Perkalian #include <stdio.h> main() { int baris, kolom, hasil_kali; for (baris = 1; baris <= 10; baris++) { for (kolom = 1; kolom <= 8; kolom++) { hasil_kali = baris * kolom; printf ("%3d", hasil_kali); } printf("\n"); /* pindah baris */ } } 5

Exercise 1.

2.

Buatlah program yang menampilkan bilangan ganjil mulai dari 1 sampai dengan n (input = n). Buatlah program untuk menampilkan bilangan: 1 22 333 4444 ..... nnnnnn..

6

Related Documents


More Documents from "cikgu benny"