NRP: 1210197004
m
er as
Jawab :
co
eH w
#include <stdio.h>
o.
main()
{ rs e
ou urc
// Percobaan 1
int n, x, a, b;
printf("Masukkanjumlahbintang: ");scanf("%d",&n);
o
for(x=n;x>0;x--){
aC s
for(a=x-1;a>0;a--){
vi y re
printf(" ");
}
for(b=n-(x-1);b>0;b--){
ed d
printf("*");
ar stu
}
printf("\n");
}
for(x=0;x<n-1;x++){
sh is
for(a=0;a<x+1;a++){
Th
printf(" ");
}
for(b=0;b<n-(x+1);b++){
printf("*");
}
printf("\n");
}
}
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/
2. Dengan menggunakan nested loop, buatlah tampilan seperti gambar
m
dibawah ini:
er as
Tampilan:
co
eH w
12345
o.
2 4 6 8 10
rs e
ou urc
3 6 9 12 15
Jawab :
o
aC s
#include <stdio.h>
vi y re
main()
{
ed d
// Percobaan 2
ar stu
Int hitung, a, b;
sh is
{
for (b = 1; b <= 5; b++)
{
hitung = a * b;
printf ("%4d", hitung);
}
printf("\n");
}
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/
}
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/
mahasiswa ini akan diulangi kembali. Proses untuk mengembalikan ke awal
perulangan kembali dapat dilakukan dengan pernyataan continue)
Jawab :
#include <stdio.h>
main()
{
// Percobaan 3
m
int a, b, bdata;
er as
co
float rata;
eH w
double jum=0;
o.
rs e
printf("banyak data? ");scanf("%d",&a);
ou urc
for(b=1;b<=a;b++){
printf("data ke %d ?",b);scanf("%d",&bdata);
o
if(bdata<=0){
aC s
b--;
vi y re
continue;
}
ed d
jum+=bdata;
ar stu
}
rata =(float)jum/a;
sh is
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/
Jawab :
#include <stdio.h>
#include <stdlib.h>
main()
{
// Percobaan 4
int A,B;
floathasil;
Tak_hingga :
printf("Masukkan nilai ke-1: ");
m
er as
scanf("%d",&A);
co
eH w
printf("Masukkan nilai ke-2: ");
o.
scanf("%d",&B);
if(B!=0){ rs e
ou urc
hasil=A/B;
printf("hasil baginya adalah = %f",hasil);}
o
aC s
else{
vi y re
goto Tak_hingga;
}
ed d
ar stu
}
sh is
Th
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/
m
er as
co
eH w
o.
rs e
ou urc
o
aC s
vi y re
ed d
ar stu
sh is
Th
https://www.coursehero.com/file/50305875/p6-imroatus1210197004docx/