Saturday, 25 March 2017

Hackerrank Solution For Day 3: Intro to Conditional Statements

Problem:- Write a Hackerrank Solution For Day 3: Intro to Conditional Statements or Hacker Rank Solution Program In C++ For " Day 3: Intro to Conditional Statements " or Hackerrank 30 days of code Java Solution: Day 3 Intro to Conditional Statements or Hackerrank solution for 30 Days of Code Challenges.


Hackerrank Solution For Day 3: Intro to Conditional Statements

Task:- According to Hacker Rank program should follow these four given conditions.

1. If n is odd, print Weird.
2. If n is even and in the inclusive range of 2 to 5, print Not Weird.
3. If n is even and in the inclusive range of 6 to 20, print Weird.
4. If n is even and greater than 20, print Not Weird.

Logic:- Let's start, so we have a number n and we need to write a program that follows the above four condition as we can see that our first condition is if n is odd that program will print number "Weird" so for this first condition we divide a number by 2 if a number is divisible by 2 then number is even and if number is not divisible by 2 then it will print number is "Weird'. Now come to the second condition if the number is even and range of 2 to 5 the program will print number "Not Weird", for that again each number we divide by 2 if number is even and number is between range(2 to 5) the program will print Number is "Not  Weird". Now comes to the third condition if the number is between 6 to 20 then program will print number is " Weird". same as the second condition. Again check for the fourth condition if the number is greater than 20 then the program will print number is " Weird".

If you want to 30 days solution from Day 0 please check the below link. And also you can find more program in below of this post. 

1. Hackerrank Solution For Day 0: Hello, World.

2. Hackerrank Solution For Day 1: Data Types. 

3. Hackerrank Solution For Day 2: Operators.


Submit Your Solution Here:- Click Here

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:-


Hackerrank Solution For Day 3: Intro to Conditional Statements

You May Also Like:-









9. Hackerrank Solution For Day 12: Inheritance

10. Hackerrank Solution For Day 13: Abstract Classes

Extreme Recommended:- Like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date. If you have any Query or Question you can ask in the group, I will Try To Solve your Query and try to answers of your Questions withing 24 Hours, You can also Email me or comment below Please suggest to your Friends to join and like our page and don't forget to Subscribe. Enter your Email and click to subscribe.

Ghanendra Yadav

Ghanendra Yadav

Hello, I Am Ghanendra Yadav Owner of This Blog, I am professional Blogger and Programmer. I Love Programming, Logo Making, And Banner Designing. My Highest Qualification is MCA From NIT Warangal. You Can Find Me On Social Media Through Below Link And If You Have Any Query Related To Programming And Other Subject Comment Below or You Can Mail Me I Will Try To Answer Within 24 Hours Email:- yghanendra@student.nitw.ac.in

Find me on Social Media

Facebook | Twitter | Google+ | RSS Feed

No comments:

Post a Comment