Hackerrank's Problem Solving solutions( Solve Me First, Simple Array Sum, Compare the Triplets ) :

Problem 1: Solve Me First

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include <bits/stdc++.h>
using namespace std;
int solveMeFirst(int a, int b)
{
return a+b;
}
int main()
{
int num1,num2;
cin>>num1>>num2;
int sum;
sum = solveMeFirst(num1,num2);
cout<<sum;
}

This code is simple. There's no need for any explanation.
 

 

 

 

Problem 2: Simple Array Sum

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,i,j,sum;
cin>>n;
int a[n];
for(i=0;i<n;i++)
cin>>a[i];
sum=0;
for(j=0;j<n;j++)
{
sum=sum+a[j];
}
cout<<sum;
}

This code is simple. There's no need for any explanation.
 

 

 

 

Problem 3: Compare the Triplets

Solution: (in c++)


( please guys before moving to the solution try it yourself at least 3-4 times , if you really wanna become a good coder)

#include<bits/stdc++.h>
using namespace std;
int main()
{
int c1=0,c2=0;
int a[3];
int b[3];
for(int i=0;i<3;i++)
{
cin>>a[i];
}
for(int k=0;k<3;k++)
{
cin>>b[k];
}
for(int j=0;j<3;j++)
{
if(a[j]>b[j])
{
c1++;
}
else if(a[j]==b[j])
{
c1=c1+0;
c2=c2+0;
}
else
{
c2++;
}
}
cout<<c1<<" "<<c2;
}

This code is simple. There's no need for any explanation.
 

 

 

Guys , if you have any queries related to a question or need more explanation , comment below!

Comments

Post a Comment

Popular posts from this blog

Coursera's Algorithmic toolbox assignment solutions( Sum of Two Digits, Maximum Pairwise Product ) :

HackerEarth's basic programming solutions( Seating Arrangement, Zoos, Anagrams ) :

HackerEarth's basic programming solutions( Minimize Cost, Magical Word, Best Index ) :