#include <iostream>
using namespace std;
void judul() {
puts("=============================");
puts("\tcontoh Array Dimensi 1");
puts("=============================");
}
int main() {
judul();
int i;
float harga[5];
harga[0] = 1000;
harga[1] = 2000;
harga[2] = 3000;
harga[3] = 4000;
harga[4] = 5000;
printf("variable harga 1 adalah %.0f\n",harga[1]);
printf("variable harga 3 adalah %.0f\n",harga[3]);
cout<<"\n\n";
puts("nilai dari seluruh variable adalah:");
for(i=0;i<5;i++)
{
printf("variable harga %d adalah %.0f\n",i,harga[i]);
}
puts("===========================================")
cout<<"Nama : moh.faqih s.karim"<<end1;
cout<<"Email: mhammadfaqih1434@gmail.com"<<end1;
return 0;
}
#include <iostream>
#include <vector>
struct Data {
int No;
int A;
int B;
int A2B2;
};
int main() {
std::vector<Data> data = {
{1, 2, 4, 0},
{2, 3, 6, 0},
{3, 4, 8, 0},
{4, 5, 10, 0},
{5, 6, 12, 0}
};
for (auto& item : data) {
item.A2B2 = (item.A* item.A) + (item.B * item.B);
}
std::cout << "No A B A^2+B^2\n";
for (const auto& item : data) {
std::cout << item.No << " " << item.A << " " << item.B << " " << item.A2B2 << "\n";
}
return 0;
}