Thanks've come to visit my blog, you can know everyday I'm, I'm feeling and experience it all. excuse me if I have offended in the blog or whatever it is you could comment:) if my blog more interesting for you , you can klik . "like this , amazing , etc" :)

Jumat, 04 Februari 2011

Tipe Data, Perulangan, & Percabangan : Program Segitiga Atas & Segitiga Bawah

1. Buatlah bentuk segitiga atas dan segitiga bawah dengan menggunakan konsep percabangan dan perulangan. :
a. Tabel Pertambahan
  • Segitiga Atas

#include<stdio.h>

#include<conio.h>

main()

{    int baris, kolom, max, hasil, kosong;

printf("Masukkan nilai input:");

scanf("%d", &max);

kosong=max;

for(baris=1; baris<=max; baris++)

{

for(kolom=1; kolom<=max; kolom++)

{

if(baris==1)

printf("%d\t", kolom);

if(baris>=2 && kolom==1)

printf("%d\t", baris);

if(baris>=2 && kolom>=2)

{      hasil=baris+kolom;

if(hasil>kosong+1)

printf(" \t");

else

printf("%d\t", hasil);

}

}printf("\n");

}getch();

}

  • Segitiga Bawah

#include<stdio.h>

#include<conio.h>

main()

{

int baris, kolom, max, hasil, kosong;

printf("Masukkan nilai input:");

scanf("%d", &max);

kosong=max;

for(baris=1; baris<=max; baris++)

{

for(kolom=1; kolom<=max; kolom++)

{

if(baris==1)

printf("%d\t", kolom);

if(baris>=2 && kolom==1)

printf("%d\t", baris);

if(baris>=2 && kolom>=2)

{

hasil=baris+kolom;

if(hasil<=kosong+1)

printf(" \t");

else

printf("%d\t", hasil);

}

}

printf("\n");

}

getch();

}
b. Tabel Perkalian
  • Ø Segitiga Atas

#include <stdio.h>

#include <math.h>

#include <conio.h>

void main ()

{

int baris, kolom, kosong,max;

double hasil;

printf("masukkan input:");

scanf("%d",&max);

kosong = max;

for(baris=1;baris<=max;baris++)

{

for(kolom=1;kolom<=max;kolom++)

{

if(baris == 1)

printf("%d\t",kolom);

if(baris >= 2&& kolom == 1)

printf("%d\t",baris);

if(baris >= 2&& kolom >= 2)

{

hasil=baris*kolom;

if(kolom > kosong)

printf(" \t");

else

printf("%.lf\t",hasil);

}

}printf("\n");

kosong--;

}

getch();

}
  • Ø Segitiga Bawah

#include <stdio.h>

#include <math.h>

#include <conio.h>

void main ()

{

int baris, kolom, kosong,max;

double hasil;

printf("masukkan input:");scanf("%d",&max);

kosong = max;

for(baris=1;baris<=max;baris++)

{

for(kolom=1;kolom<=max;kolom++)

{

if(baris == 1)

printf("%d\t",kolom);

if(baris >= 2&& kolom == 1)

printf("%d\t",baris);

if(baris >= 2&& kolom >= 2)

{

hasil=baris*kolom;

if(kolom <= kosong)

printf(" \t");

else

printf("%.lf\t",hasil);

}

}printf("\n");

kosong--;

}getch();

}

Tidak ada komentar:

Posting Komentar