You are on page 1of 7

1.

Bai1
#include<iomanip>
#include<stdlib.h>
#include<math.h>
#include <iostream>
using namespace std;

int main()
{
// TODO
int N;
cin >> N;
float a[100];
float sum = 0;
for (int i = 1; i <= N; ) {
cin>>a[i];
sum = sum + a[i];
i=i+1;
}
float average = sum / N;
cout <<fixed<<setprecision(2)<< average;
return 0;
}
2. Bai2
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
double hourlyRates[] = { 9.5, 6.4, 12.5, 5.5, 10.5 };
double workingHours[5];
double wages[5];

for (int i = 0; i < 5; i++) {


cin >> workingHours[i];
wages[i] = hourlyRates[i] * workingHours[i];

}
cout << setw(30) << left << "Hourly Rate" << setw(30) << left << "Working Hour" <<
setw(30) << left << "Wage" << endl;
for (int i = 0; i < 5; i++) {
cout << setw(30) << left<<fixed<<setprecision(10) << hourlyRates[i] << setw(30) << left
<<fixed<<setprecision(10)<< workingHours[i] << setw(30) << left << fixed << setprecision(10)
<< wages[i] << endl;
}

return 0;
}
3. Bao3
#include<iostream>
#include<iomanip>
#include<string.h>

using namespace std;

const int MAX = 100;

struct student {
char name[20];
long int rollno;
char sex;
float height;
float weight;
};

int main() {
student cls[MAX];
int i, n;
cout << "How many names ? \n";
cin >> n;

for (i = 0; i <= n - 1; ++i) {


cout << "record = " << i + 1<<endl;
cout << "name : "; cin >> cls[i].name;
cout << "rollno : "; cin >> cls[i].rollno;
cout << "sex : "; cin >> cls[i].sex;
cout << "height : "; cin >> cls[i].height;
cout << "weight : "; cin >> cls[i].weight;
cout << endl;
}
// TODO
cout
<<setw(20)<<left<<"Name"<<setw(20)<<left<<"Rollno"<<setw(20)<<left<<"Sex"<<setw(20)<
<left<<"Height"<<setw(20)<<left<<"Weight"<<endl;
for (i = 0; i <= n - 1; i++) {
cout<<setw(20) << left << cls[i].name << setw(20) << left <<cls[i].rollno << setw(20) <<
left << cls[i].sex<< setw(20) << left <<fixed<<setprecision(2)<< cls[i].height << setw(20) << left
<< fixed<<setprecision(2)<<cls[i].weight << endl;
}
float sum1 = 0;
float sum2 = 0;
for (i = 0; i <= n - 1; i++) {
sum1 = sum1 + cls[i].height;
sum2 = sum2 + cls[i].weight;
}
float aver1 = sum1 / n;
float aver2 = sum2 / n;
cout <<fixed<<setprecision(5)<< aver1 << " " <<fixed<<setprecision(5)<< aver2;
return 0;
}
4. Bao4
#include<iostream>
#include<iomanip>
#include<stdlib.h>

using namespace std;


int main()
{
// TODO
int n;
cin >> n;
float x; cin >> x;
float duong = 1,am=1;

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


duong = duong * x;
}
for (int i = 1; i <= n; i++) {
am = am * (1 / x);
}
cout <<fixed<<setprecision(2)<< duong << " " <<fixed<<setprecision(2)<< am;
return 0;
}
5. Bai5
#include <iostream>
using namespace std;

void count_pos_neg(int n, double arr[]) {


int pos = 0;
int neg = 0;
for (int i = 0; i < n; i++) {
if (arr[i] >= 0) {
pos++;
} else {
neg++;
}
}
cout << pos << " " << neg << endl;
}

int main() {
int n;
cin >> n;
double arr[n];
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
count_pos_neg(n, arr);
return 0;
}
6. Bai6\
#include <iostream>
using namespace std;

int main() {
int n;
cin >> n;
long long a = 0, b = 1, c;
if (n == 1 || n==0) {
cout << "0" << endl;
}
else {
for (int i = 3; i <= n; i++) {
c = a + b;
a = b;
b = c;
}
cout << b << endl;
}

return 0;
}
7. Bai7
#include <iostream>
using namespace std;

int main() {
int n;
cin >> n;
long long a = 0, b = 1, c;
if (n!=1){
cout <<"0"<<" "<<"1"<<" ";
for (int i = 3; i <= n; i++) {
c = a + b;
a = b;
b = c;
cout<<b<<" ";
}
}
else {
cout <<"0";
}
return 0;
}
8. Bai8
#include <iostream>
#include <iomanip>
using namespace std;

int main() {

int i, n;
float arr[100];

cin >> n;

for (i = 0; i < n; ++i) {

cin >> arr[i];


}

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

if (arr[0] < arr[i])


arr[0] = arr[i];
}

cout<<fixed<<setprecision(2)<<arr[0];

return 0;
}
9. Bai9
#include<iostream>
#include<iomanip>
#include<stdlib.h>
#include<math.h>

using namespace std;


int main()
{
// TODO
float x,rad;
const float pi = 3.14;

for (x = 5; x <= 85; x += 5)


{
rad = (x * pi) / 180;
cout<<fixed<<setprecision(2)<<sin(rad) <<" "<< fixed << setprecision(2) << cos(rad) << "
"<< fixed << setprecision(2) << sin(rad) / cos(rad)<<endl;
}
return 0;}
10. Bai10
#include <iostream>
using namespace std;

int main() {
int n;
cin >> n;
int matrix[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cin >> matrix[i][j];
}
}
int transpose[n][n];
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
transpose[i][j] = matrix[j][i];
}
}
for (int i = 0; i < n; i++) {
for (int j = 0; j < n; j++) {
cout << transpose[i][j] << " ";
}
cout << endl;
}
return 0;
}
11. Bai11
#include <iostream>
#include <unordered_map>
using namespace std;

int main() {
int n;
cin >> n;
int nums[n];
for (int i = 0; i < n; i++) {
cin >> nums[i];
}
unordered_map<int, int> freq;
for (int i = 0; i < n; i++) {
freq[nums[i]]++;
}
int majority = -1;
for (auto& p : freq) {
if (p.second > n / 2) {
majority = p.first;
break;
}
}
cout << majority << endl;
return 0;
}

You might also like