top of page

Keep Reading !

You can also checkout more topics like...

peep-101_edited.png
EXPLORE COURSES (6).png
EXPLORE COURSES (9).png
EXPLORE COURSES (7)_edited.jpg

Hacker Rank Solutions - C++

Say "Hello, World!" With C++


Solution :



#include <iostream>
#include <cstdio>
using namespace std;

int main() {
    cout<<"Hello, World!";
    return 0;
}

Input and Output


Solution:


#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    int n1,n2,n3;
    cin>>n1>>n2>>n3;
     int n4 = n1+n2+n3;
     cout<< n4 ;
    return 0;
}

Basic Data Types


Solution:


#include <iostream>
#include <cstdio>
using namespace std;

int main() 
{
    // Complete the code.
 int a;
 long long int b;
 char c;
 float d;
 double e;

 scanf("%d %lld %c %f %lf",&a,&b,&c,&d,&e);

 printf("%d\n%lld\n%c\n%f\n%lf",a,b,c,d,e);

return 0;
}






Conditional Statements


Solution:

 
#include <iostream>

using namespace std;



int main()
{
    int n;
    cin >> n;
   if (n==9)
   {
       cout<<"nine"<<endl;
   }
else if (n==8)
   {
       cout<<"eight"<<endl;
   }
else if (n==7)
   {
       cout<<"seven"<<endl;
   }
else if (n==6)
   {
       cout<<"six"<<endl;
   }
else if (n==5)
   {
       cout<<"five"<<endl;
   }
else if (n==4)
   {
       cout<<"four"<<endl;
   }
else if (n==3)
   {
       cout<<"three"<<endl;
   }
else if (n==2)
   {
       cout<<"two"<<endl;
   }
else if (n==1)
   {
       cout<<"one"<<endl;
   }

else 
{
    cout<<"Greater than 9"<<endl;
}
    return 0;
}




For Loop


Solution:



#include<iostream>
using namespace std;
int main()
{
     int n,m;
     cin>>n>>m;
     for(int i=n;i<=m;i++)
     {
         if(i==1)
         {
             cout<<"one"<<endl;
         }
         if(i==2)
         {
             cout<<"two"<<endl;
         }
         if(i==3)
         {
             cout<<"three"<<endl;
         }
         if(i==4)
         {
             cout<<"four"<<endl;
         }
         if(i==5)
         {
             cout<<"five"<<endl;
         }
          if(i==6)
         {
             cout<<"six"<<endl;
         }
          if(i==7)
         {
             cout<<"seven"<<endl;
         }
         if(i==8)
         {
             cout<<"eight"<<endl;
         }
          if(i==9)
         {
             cout<<"nine"<<endl;
         }
          if(i>9)
         {
             if(i%2==1)
             {
                 cout<<"odd"<<endl;
             }
             else
             {
                 cout<<"even"<<endl;
             }
         }
     }
     return 0;
}


110 views0 comments

Commenti


bottom of page