Assignment - 3
Assignment - 3
Assignment – 3
Q1---->
ANS
#include<bits/stdc++.h>
sort(v.begin(),v.end());
if(n&1){
return v[(n/2)];
int main(){
int n;
cin >> n;
vector<int>v(n);
OUTPUT
Q2 ------
ANS-
#include<bits/stdc++.h>
map<int,int>mp;
int mode_value = 0;
int mode_cnt = 0;
for(auto c:mp){
if(c.second>mode_cnt){
mode_cnt = c.second;
mode_value = c.first;
int cnt_mode = 0;
for(auto c:mp){
if(c.second == mode_cnt)cnt_mode++;
return mode_value;
}
int main(){
int n;
cin >> n;
vector<int>v(n);
int m = mode(n,v);
if(m==-1){
return 0;
OUTPUT
Q3--------->
ANS
#include<bits/stdc++.h>
using namespace std;
int main(){
float arr[181];
float cnt[181];
for(int i=0;i<181;i++){
arr[i] = 0;
cnt[i] = 0;
int n;
cin >> n;
for(int i =0;i<n;i++){
int a;
float b;
arr[a+90] = arr[a+90]*cnt[a+90] + b;
cnt[a+90]++;
arr[a+90] = arr[a+90]/cnt[a+90];
for(int i=-90;i<91;i++){
if(arr[i+90] == 0) cout << i << " " << "NO DATA" << endl;
else cout << i << " " << arr[i+90] << endl;
int cnt_s = 0;
int cnt_n = 0;
float avg_s = 0;
float avg_n = 0;
for(int i=-90;i<0;i++){
if(arr[i+90]!=0)cnt_s++;
avg_s += arr[i+90];
}
for(int i=1;i<91;i++){
if(arr[i+90]!=0)cnt_n++;
avg_n += arr[i+90];
if(cnt_s == 0)cnt_s ++ ;
avg_n /= cnt_n;
avg_s /= cnt_s;
cout << "Average of southern hemisphere is: " << avg_s << endl;
cout << "Average of northern hemisphere is: " << avg_n << endl;
avg_n = 0;
avg_s = 0;
cnt_n = 0;
cnt_s = 0;
for(int i=-90;i<=0;i++){
avg_n += arr[i+180];
avg_s += arr[i+90];
cnt_n++;
cnt_s++;
avg_n /= cnt_n;
avg_s /= cnt_s;
if(avg_n<avg_s){
}
OUTPUT
Q4------>
ANS
#include<bits/stdc++.h>
int main(){
//question-a
int a[100];
//question-b
int b[200];
//question-c
int c[10][20];
int d[10][20];
//question-e
int e[10][20];
//question-f
int f[10][20];
//question-g
int g[10][20];
//question-h
int h[10][20];
//question-i
int i[10][20];
return 0;
OUTPUT
Q5----->
ANS--->
#include<bits/stdc++.h>
struct realtype
int left;
int right;
};
int l = a;
int r = (a-l)*(1e9);
if(r<0)r*=-1;
struct realtype t;
t.left = l;
t.right = r;
return t;
}
long double to_real(struct realtype temp){
int l = temp.left;
int r = temp.right;
p = pow(10,p);
return ans;
return to_realtype(c);
long double c = a + b;
return to_realtype(c);
long double c = a - b;
return to_realtype(c);
int main(){
//question a:
long double n;
cin >> n;
//question b:
//question c:
cout << "Multiplication: " << multiply.left << " " << multiply.right << endl;
cout << "Addition: " << add.left << " " << add.right << endl;
cout << "Subtraction: " << subtract.left << " " << subtract.right << endl;
return 0;
OUTPUT
Q6--->
ANS--->
#include<bits/stdc++.h>
int main(){
struct student
string first_name;
string last_name;
float grade_ind;
};
struct employee
string first_name;
string last_name;
float salary;
};
int n;
cin >> n;
for(int i=0;i<n;i++){
cout << "Enter last name of student " << i+1 << ": ";
cout << "Enter first name of student " << i+1 << ": ";
cout << "Enter grade point index of student " << i+1 << ": ";
for(int i=0;i<n;i++){
cout << "Enter last name of employee " << i+1 << ": ";
cout << "Enter first name of employee " << i+1 << ": ";
cout << "Enter salary of employee " << i+1 << ": ";
}
for(int i=0;i<n;i++){
for(int j=0;j<n;j++){
}}}
for(int i=0;i<n;i++){
cout << emp[i].last_name << " " << emp[i].first_name << " " << emp[i].salary << endl;
return 0;
OUTPUT----