Pemograman Gabungan
Pemograman Gabungan
int main(){
int bil;
bool prima = true;
return 0;
}
4. array sederhana, melihat tren data array. dimensi 1 integer. n selalu dari 0
Jawaban :
#include <iostream>
using namespace std;
int main() {
int n;
cout<<"Masukkan jumlah bilangan: ";
cin>>n;
int arr[n];
cout<<"\nArray: ";
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<"\nTerbalik: ";
for(int i=n-1;i>=0;i--){
cout<<arr[i]<<" ";
}
cout<<"\nAscending: ";
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<"\nDescending: ";
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
return 0;
}
5. array juga tapi lebih kompleks. sirkular array. bisa pake while atau for
Jawaban :
Jawaban :
#include<iostream>
using namespace std;
int main(){
int jumlah_data;
cin>>jumlah_data;
//input
int data[jumlah_data];
for (int a = 0; a<jumlah_data; a++){
cin>>data[a];
}
//cout<<tertinggi<<endl;
cout<<output;
}
#include <iostream> #include <iostream>
using namespace std; using namespace std;
cout<<"\nAscending: ";
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
cout<<"\nDescending: ";
for(int i=0;i<n;i++){
cout<<arr[i]<<" ";
}
return 0;
}
return 0;
}
#include <iostream> #include <iostream>
using namespace std; #include <string>
if(pertandingan[i].skor1>pertandingan[i].skor2){
skor[pertandingan[i].tim1-1]+=3;
}
else
if(pertandingan[i].skor2<pertandingan[i].skor1){
skor[pertandingan[i].tim2-1]+=3;
}
else {
skor[pertandingan[i].tim1-1]+=1;
skor[pertandingan[i].tim2-1]+=1;
}
}
int max = 0;
int top;
for(int i=0; i<5; i++){
cout<<skor[i]<<endl;
}
return 0;
}
cout<<endl;
}
cout<<endl;
}
return 0;
}
#include <iostream> #include<iostream>
#include <string> using namespace std;
ponsel_terjual penjualan[10] = {
{"IP", 1},
{"IP", 4},
{"VI", 2},
{"NO", 1},
{"SA", 4},
{"IP", 2},
{"SA", 1},
{"VI", 3},
{"NO", 5},
{"IP", 1}
};
return 0;
}
mhs[3].NIM="10004"; G.t1.x = 2;
mhs[3].Nama="Puji"; G.t1.y = 7;
mhs[3].IPK=3.75; G.t2.x = 10;
G.t2.y = 9;
mhs[4].NIM="10005";
mhs[4].Nama="Bayu"; S.t1.x = 2;
mhs[4].IPK=1.45; S.t1.y = 0;
S.t2.x = 6;
double jumlah=0, rerata, ipkmax=0; S.t2.y = 5;
int imax=0; S.t3.x = 8;
S.t3.y = 3;
for(int i=0; i < N; i++){
jumlah += mhs[i].IPK; cout << "panjang G=" << sqrt(
if(ipkmax<mhs[i].IPK) { (G.t1.x-G.t2.x)*(G.t1.x-G.t2.x)+
ipkmax=mhs[i].IPK; (G.t1.y-G.t2.y)*(G.t1.y-G.t2.y)
imax=i; ) << endl;
}
} cout << "keliling S=" <<
rerata=jumlah/N; sqrt(
cout << "ipk rerata=" << rerata << endl; (S.t1.x-S.t2.x)*(S.t1.x-S.t2.x)+
cout << "tertinggi=" << ipkmax << " yaitu: " << (S.t1.y-S.t2.y)*(S.t1.y-S.t2.y)
mhs[imax].Nama << endl; )+
sqrt(
return 0; (S.t3.x-S.t2.x)*(S.t3.x-S.t2.x)+
} (S.t3.y-S.t2.y)*(S.t3.y-S.t2.y)
)+
sqrt(
(S.t1.x-S.t3.x)*(S.t1.x-S.t3.x)+
(S.t1.y-S.t3.y)*(S.t1.y-S.t3.y)
)
<< endl;
return 0;
}
cout<<endl<<endl;
getch ();
return 0;
}
#include <iostream> BUTTERFLY #include <iostream>
using namespace std; using namespace std;
return 0;
}
// Menampilkan hasil
cout << "Jarak antara kedua titik: " << jarak <<
std::endl;
return 0;
}
Difference between Interpreter and Compiler:
Interpreter:
An interpreter translates code line by line, executing each line immediately after translation.
Errors are often detected and reported one at a time, which can make debugging easier.
Compiler:
A compiler translates the entire source code into machine code or an intermediate form before execution.
Errors are detected after the entire code is compiled, which may make debugging more challenging.
Examples: GCC for C/C++, Java Compiler for Java, Microsoft Visual C# Compiler for C#.
Usage of Compiler:
Compilers are used to translate high-level programming languages (like C, C++, Java) into machine code or
intermediate code.
Compilers are essential for developing standalone software applications and operating systems.
<iostream> is a header file in C++ that provides input and output functionality.
You include it in your C++ program to use standard input/output streams like cin (for input) and cout (for
output).
It allows you to perform operations like reading from the keyboard and displaying information on the
console.
Examples of Compilers:
GCC (GNU Compiler Collection): Compiles C, C++, and various other languages.
Clang: A C, C++, and Objective-C compiler front end for the LLVM compiler infrastructure.
Java Compiler (javac): Compiles Java source code into bytecode for the Java Virtual Machine (JVM).
Examples of Interpreters:
Inisialisasi variabel count dengan 0. Variabel ini akan digunakan untuk menghitung jumlah
kemunculan angka 4.
Inisialisasi variabel total dengan 0. Variabel ini akan digunakan untuk menghitung jumlah total dari
semua kemunculan angka 4.
Tambahkan 1 ke count.
Tambahkan x ke total.
Setelah iterasi selesai, Anda akan memiliki jumlah kemunculan dalam count dan jumlah total dalam
total.
Tampilkan nilai total sebagai hasil dari jumlah total dari semua kemunculan angka 4.
for i in range(n):
for j in range(n):
if matrix[i][j] == element_to_search:
print(f"Element {element_to_search}
found at position ({i + 1}, {j + 1})")
found = True
if not found:
print(f"Element {element_to_search} not
found in the matrix.")