Sunday, 26 March 2017

Hacker Rank Solution Program In C++ For " Day 5: Loops "

Problem :- Day 5: Loops

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

Solution :-

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>

using namespace std;

int main(){
    int n,i;
    cin >> n;
    for(i=1;i<=10;i++)
        {
        cout<<n<<" x "<<i<<" = "<<n*i<<endl;
    }cout<<endl;
    return 0;
}

Output :-

Hacker Rank Solution Program In C++ For " Day 5: Loops "

Saturday, 25 March 2017

Hacker Rank Solution Program In C++ For " Day 4: Class vs. Instance "

Problem :- Day 4: Class vs. Instance

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

Solution :-

using namespace std;
#include <iostream>

class Person{
    public:
        int age;
        Person(int initialAge);
        void amIOld();
        void yearPasses();
    };

    Person::Person(int initialAge){
        // Add some more code to run some checks on initialAge
        age=initialAge;
        if(age<0)
            {
            cout<<"Age is not valid, setting age to 0."<<endl;
            age=0;
        }

    }

    void Person::amIOld(){
        // Do some computations in here and print out the correct statement to the console 
        if(age<13)
            cout<<"You are young."<<endl;
        else if(age>=13 && age<=17)
            cout<<"You are a teenager."<<endl ;
        else
            cout<<"You are old."<<endl;
    }

    void Person::yearPasses(){
        // Increment the age of the person in here
             age++;
    }

int main(){
    int t;
int age;
    cin >> t;
    for(int i=0; i < t; i++) {
    cin >> age;
        Person p(age);
        p.amIOld();
        for(int j=0; j < 3; j++) {
        p.yearPasses(); 
        }
        p.amIOld();
      
cout << '\n';
    }

    return 0;
}

Output :-

Hacker Rank Solution Program In C++ For " Day 4: Class vs. Instance "

Hacker Rank Solution Program In C++ For " Day 3: Intro to Conditional Statements "

Problem :- Day 3: Intro to Conditional Statements

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

Solution :-

#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
using namespace std;


int main(){
    int N;
    cin >> N;
    if(N%2==0)
        {
        if(N>=2 && N<=5)
            cout<<"Not Weird";
        else if(N>=6 && N<=20)
            cout<<"Weird";
            else
            cout<<"Not Weird";
    }
    else
        cout<<"Weird";
    return 0;
}

Output :-

Hacker Rank Solution Program In C++ For " Day 3: Intro to Conditional Statements "

Hacker Rank Solution Program In C++ For " Day 2: Operators "

Problem :- Day 2: Operators

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

Solution :-

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

int main() {
    double meal;
    int tipp,taxp,total;
    cin>>meal>>tipp>>taxp;
    tipp=round(meal*tipp/100);
    taxp=(meal*taxp/100);
    total=meal+tipp+taxp;
    cout<<"The total meal cost is "<<total+1<<" dollars.";
    return 0;
}


Output :-

Hacker Rank Solution Program In C++ For " Day 2: Operators "

Hacker Rank Solution Program In C++ For " Day 1: Data Types "

Problem :- Day 1: Data Types

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

Solution :-

#include <iostream>
#include <iomanip>
#include <limits>

using namespace std;

int main() {
    int i = 4;
    double d = 4.0;
    string s = "HackerRank ";

    int j;
    double e;
    string t;
    cin>>j;
    cin>>e;
    cin.ignore();  
    getline(cin,t);
    cout<<i+j<<endl;
    d=d+e;
    cout<<fixed<<setprecision(1)<<d<<endl;
    cout<<s<<t;

    return 0;
}

Output :-


Hacker Rank Solution Program In C++ For " Day 1: Data Types "

Wednesday, 22 March 2017

Hacker Rank Solution Program In C++ For " Day 0: Hello, World. "

Problem :- Day 0: Hello, World. 

Submit Your Solution Here :- Click Here

Copy The Color Code and paste it into hackerrank Editor .

Solution :-

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


int main() {
    // Declare a variable named 'input_string' to hold our input.
    string input_string; 
    
    // Read a full line of input from stdin (cin) and save it to our variable, input_string.
    getline(cin, input_string); 
    
    // Print a string literal saying "Hello, World." to stdout using cout.
    cout << "Hello, World." << endl;

    // TODO: Write a line of code here that prints the contents of input_string to stdout.
    cout<<input_string;
    return 0;
}

Output :-


Hacker Rank Solution Program In C++ For " Day 0: Hello, World. "

Hacker Rank Solution Program In C++ For " Multi Level Inheritance "

Problem :- Suppose we have a class A which is the base class and we have a class B which is derived from class A and we have a class C which is derived from class B, we can access the functions of both class A and class B by creating an object for class C. This is called Multi-Level inheritance. (B inherits A and C inherits B.)


Submit Your Solution Here :- Click Here

Solution :-

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

class Triangle{
   public:
      void triangle(){
         cout<<"I am a triangle\n";
      }
};

class Isosceles : public Triangle{
     public:
        void isosceles(){
          cout<<"I am an isosceles triangle\n";
        }
};
   
class Equilateral:public Isosceles{
   public:
        void equilateral(){
            cout<<"I am an equilateral triangle\n";
        }
};
int main(){
  
    Equilateral eqr;
    eqr.equilateral();
    eqr.isosceles();
    eqr.triangle();
    return 0;
}


Output :-

Hacker Rank Solution Program In C++ For " Multi Level Inheritance "

Saturday, 18 March 2017

Geeksforgeeks Solution For " Sum of array elements "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Given an integer array, find sum of elements in it.

Submit Your Solution :- Click Here 


Solution :- 

#include <iostream>
using namespace std;
int main()
{
    int t;
    cin>>t;
    while(t--)
    {
       int i,n,sum=0;
       cin>>n;
       int arr[n];
       for(i=0;i<n;i++)
       cin>>arr[i];
       for(i=0;i<n;i++)
       sum+=arr[i];
       cout<<sum<<endl;
       
    }
    return 0;
}

Output:-

Geeksforgeeks Solution For " Sum of array elements "

Geeksforgeeks Solution For " Search an Element in an array "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- Given an integer array and an element x, find if element is present in array or not. If element is present, then print index of its first occurrence. Else print -1.

Submit Your Solution :- Click Here 


Solution :- 

#include<stdio.h>
int main() 
{
    int t;
    scanf("%d",&t);
    while(t--)
    {
   int a[100], ele, num, i;
   scanf("%d", &num);
   for (i = 0; i < num; i++) 
   {
      scanf("%d", &a[i]);
   }
   scanf("%d", &ele);
   i = 0;
   while (i <num) 
   {
       if(a[i]==ele)
       {
           printf("%d",i);
           break;
       }
       i++;
   }
   if (i==num) 
   {
      printf("-1");
   } 
   printf("\n");
    }
   return (0);
}

Output:-


Geeksforgeeks Solution For " Search an Element in an array "

Geeksforgeeks Solution For " Alone in couple "

GeeksforGeeks Solution For School Domain .Below You Can Find The Solution Of Basic ,Easy ,Medium ,Hard .You Can Also Direct Submit Your Solution to Geeksforgeeks Same Problem .You Need to login then you can submit you answers 

Problem :- In a party everyone is in couple except one. People who are in couple have same numbers. Find out the person who is not in couple.

Submit Your Solution :- Click Here 


Solution :- 

#include<bits/stdc++.h>
using namespace std;

int main()
{
int t;
cin>>t;
while(t--)
{
    long long int n,i,x=0;
    cin>>n;
    int a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
        x=x^a[i];
    }
        cout<<x<<endl;
}
return 0;
}

Output:-


Geeksforgeeks Solution For " Alone in couple "