You are given an array arr[ ] of size N. Your task is to perform "OR" operation of the consecutive elements of the array and store them in a different array and print that new array.
INPUT:
First line of input contains the value of T for test cases.
For each test case the second line contains a single integer value indicating the value of N.
For each test case next line contains N space separated integers.
OUTPUT:
Containing N space separated integers indicating the values of new array.
Test Case: 1
INPUT:
1
4
8 9 5 6
OUTPUT:
9 13 7 6
Explanation:
At index 0, arr[0] OR arr[1] = 9
At index 1, arr[1] OR arr[2] = 13
At index 2, arr[2] OR arr[3] = 7
At index 3, no element is left so the last element remain as it is.
#include
using namespace std;
int* game_with_number(int arr[], int n);
int main()
{
int t;cin>> t;
while(t--)
{
int n;
cin >> n;
int arr[n];
for(int i=0;i>arr[i];
int *arr2;
arr2 = game_with_number(arr, n);
for(int i = 0;i < n; i++)
cout << arr2[i] << " ";
cout << endl;
}
}
int* game_with_number(int arr[], int n)
{
for(int i = 0; i < n-1; ++i)
{
arr[i] = arr[i] | arr[i+1];
}
return arr;
}
You are given an integer as the height of a triangle. Your task is to print a palindromic triangle pattern of the given height. A Palindromic number is a number that remains the same when its digits are reversed. In other words, it has reflectional symmetry across a vertical axis. In the same way, a palindromic triangle is also symmetric along its vertical axis.
INPUT:
Contains an integer indicating the value of the height of the triangle.
OUTPUT:
Contains a pattern of the given height.
Test Case: 1
INPUT:
5
OUTPUT:
1
212
32123
4321234
543212345
#include
using namespace std;
int main()
{
int h,j;
cin>>h;
for(int i=1; i<=h; i++)
{
int k=i;
for(j=1;j<=(h-i);j++)
{
cout<<" ";
}
for(; j<=h;j++)
{
cout< < k < <" ";
k- - ;
}
k=1;
for(; j<(h+i);j++)
{
k++;
cout< < k < <"";
}
for(; j<=(2*h-1);j++)
{
cout<<" ";
}
cout< < endl;
}
return 0;
}
You are given the height of the triangle as h. Your task is to print a pascal's triangle of a given height. A pascal's triangle is a triangular array of binomial coefficients.
INPUT:
Contains a single integer as input denoting the height of the triangle.
OUTPUT:
Contains a pattern of a given height.
Test Case: 1
INPUT:
5
OUTPUT:
1
1 1
1 2 1
1 3 3 1
1 4 6 4 1
#include
using namespace std;
int main()
{
int h;
cin>>h;
int num=1;
for(int i=0; i< h;i++)
{
for (int space=1; space<=h-i; space++)
{
cout< <" ";
}
for (int j=0; j<=i; j++)
{
if(j==0 || i==0)
{
num=1;
}
else
{
num=num*(i-j+1)/j;
}
cout << num<<" ";
}
cout<< endl;
}
return 0;
}
You are given a pizza on your table. Your task is to cut the pizza into the maximum pieces you can in the given N number of straight cuts. You have to print the number of pieces formed after the N cuts.
INPUT:
The First Line of input contains T test cases.
For each test case, the next line contains an integer denoting the value of N.
OUTPUT:
For each test case, the output contains a single integer denoting the number of pieces.
Test Case: 1
INPUT:
1
3
OUTPUT:
7
Explanation: 7 pieces can be formed from 3 cuts
Test Case: 2
INPUT:
1
5
OUTPUT:
Explanation: 16 Pieces can be formed using 5 cuts
16
#include
using namespace std;
class Solution{
public:
int maximum_Cuts(int n){
int sum=2;
if(n==1)
{
return 2;
}
else
{
for(int i=2;i<=n; i++)
{
sum = sum + i;
}
return sum;
}
}
};
int main(){
int T;
cin >> T;
while(T--){
int n;
cin >> n;
Solution ob;
int ans = ob.maximum_Cuts(n);
cout < < ans < < endl;
}
return 0;
}
You are given an integer N. Your task is to check whether the number is prime or not.
INPUT:
First line contains the T test cases
Second line contains the Value of N.
OUTPUT:
Contains a string that is either Prime or Non-Prime.
Test Case: 1
INPUT:
1
23
OUTPUT:
Prime
#include
using namespace std;
int main()
{
int T;
cin >> T;
while(T--)
{
int N;
int flag=0;
cin>>N;
for(int i=2; i<(N/2); i++)
{
if(N%i==0)
{
cout<<"Non-Prime"< < endl;
flag=1;
break;
}
}
if(flag==0)
{
cout<<"Prime"<< endl;
}
}
return 0;
}