1D Array
1D Array
IRC_CPP_Cod_1Darray
Attempt : 2
Total Mark : 50
Marks Obtained : 30
Section 1 : Coding
1. Problem Statement:
A source file can either be or not be in any of these two sequences. Your
task is to calculate two values: the number of source files of the project,
that are both tracked and ignored, and the number of source files of the
project, that are both untracked and unignored.
Answer
-
Status : Skipped Marks : 0/10
2. Problem Statement :
You are playing the PUBG game and you entered into the Bootcamp. There
you viewed the dropbox which was filled with guns. you have to choose the
biggest gun in the dropbox. Find the biggest gun and you will get the
chicken dinner.
Answer
// You are using GCC
#include<iostream>
using namespace std;
int main()
{
int N;
cin>>N;
int array[N];
for(int i=0;i<N;i++)
cin>>array[i];
int large;
large=array[0];
for(int i=1;i<N;i++)
{
if(array[i]>large)
large=array[i];
}
cout<<large<<" is the maximum element in the array.";
3. Problem Statement :
Array median
Write a program to find the median of the elements in the array. The
Median is the middle value in the sorted list. If there are an even number of
elements in the list, the median is the mean of the 2 middle values.
Answer
// You are using GCC
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n;
cin>>n;
int array[n];
for(int i=0;i<n;i++)
cin>>array[i];
sort(array,array+n);
float median;
if(n%2==0)
median=(array[n/2]+array[n/2-1])/2.0;
else
median =array[n/2];
cout<<fixed<<setprecision(1);
cout<<"Median = "<<median;
Answer
#include <iostream>
using namespace std;
int main()
{
int n;
cin>>n;
int array[n];
for(int i=0;i<n;i++)
cin>>array[i];
int visited[n]={0};
int count=0;
for(int i=0;i<n;i++)
{
if(visited[i]==0)
{
for(int j=i+1;j<n;j++)
{
if(array[i]==array[j])
{
visited[j]=1;
}
}
count++;
}
}
cout<<"There are "<<count<<" distinct element in the array.";
}
5. Problem Statement :
Array deletion
Answer
-
Status : Skipped Marks : 0/10