Randika Sagala

Download as pdf or txt
Download as pdf or txt
You are on page 1of 6

1.

Tugas perulangan bilangan ganjil

#include <iostream>
using namespace std;

int main (){


int n;
cout<<"Masukkan n : ";cin>>n;
for(int i=1;i<=n;i++){
if( i % 2 !=0 && i%5!=0){
cout<<i<<" ";}

}
}
2. Tugas perulangan bilangan genap

#include <iostream>
using namespace std;

int main (){


int n;
cout<<"Masukkan n : ";cin>>n;
for(int i=1;i<=n;i++){
if( i % 2 ==0 || i % 4 ==0){
cout<<i<<" ";}

}
}
3. VolumeBalok

#include <iostream>
using namespace std;

int VolumeBalok(){
int P, L , T, X;
cin >> P;
cin >> L;
cin >> T;
X = P * L * T;
cout << X;
return 0;

int main(){
VolumeBalok();

return 0;
}
4. VolumeKerucut

#include <iostream>
using namespace std;

int VolumeKerucut(){
float Pi, R, T, X;
Pi = 3.14;
cin >> R;
cin >> T;
X = Pi * R * R * T / 3;
cout << X;
return 0;

int main (){


VolumeKerucut();

return 0;
}
5. Soal Array
#include <iostream>
using namespace std;

int main() {
int a, i=0;
int y=1;

cout<<"Jumlah data: ";cin>>a;

int h[a];

for(i=0;i<a;i++){
h[i]=y; y++;
}
for(i=0;i<a;i++){
if(i%2==0){
cout<<h[i]<<" - ";
}
else {
cout<<"0 - ";
}
}
}
6. Soal Array

#include <iostream>
using namespace std;

int main(){
int n;
cout<<"Masukkan Banyaknya bilangan: ";
cin>>n;
int A[n];

for(int i = 1; i <= n; i++){


if( i%2 ==0){
cout<<i<<"\n";
}else{
cout<<"0"<<"\n";
}
}
return 0;
}

You might also like