Wednesday, 4 October 2017

Hacker Rank solution For Day 19: Interfaces

Problem:- Write a Hackerrank Solution For Day 19: Interfaces or Hacker Rank Solution Program In C++ For " Day 19: Interfaces " or Hackerrank 30 days of code Java Solution:Day 19: Interfaces solution or Hackerrank solution for 30 Days of Code Challenges or Hackerrank 30 days of code Java Solution, Day 19: Interfaces solution, or C/C++ Logic & Problem Solving: Day 19: Interfaces or Hacker Rank Solution For Day 19: Interfaces.

Check This:- Hacker rank solution for Strings, Classes, STL, Inheritance in C++.

Explanation:- This is a very simple problem(Interfaces) we have to just calculate divisor sum and print the sum of the divisor. we can do this by run the loop(started with 1 and end with N) and put the condition if number N is divided by I(where I = 1 to N) than the sum of the divisor is added each time when if N%I==0. Let's take an example and try to understand the problem step by step.

Example:- Let's assume Number N is 24 and we have to calculate the Divisor sum so we divide the number by I=1 to I=24 with the help of "For Loop" Take a look at step by step.

Step 1: If(N % I ==0) then Sum or total is Sum = Sum + I Or Total = Total + I.

Step 2: Print the total outside the "For Loop". Here Divisor of 24 = 1 + 2 + 3 + 4 + 6 + 8 + 12 + 24 = 60.

Also Check:- Geeksforgeeks solution for School, Basic, Easy, Medium, Hard in C++.

Extreme Recommended:- If this post is beneficial for you and you want Updates for New post then please like our Facebook Page or Join our Facebook Group and Google plus Community for up-to-date for a new post or if you have any Query you can ask there with lots of coders also suggest to your Friends to join and like our page, so we can help our community, and don't forget to Subscribe. Enter your Email and click to subscribe.


Tip:- Copy the colored code or full code(According to Requirement) and paste it into hacker rank editor.All solution provided here are in C++ (CPP) if any reader wants these solutions in C, and Java comments below or Email me with your query like " day n solution in C / C++ / Java. Check the end of the post solutions with the full explanation

Submit Your Solution Here:- Click Here

Solution:-

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
class AdvancedArithmetic
{
    public:
        virtual int divisorSum(int n)=0;
};

struct Calculator : public AdvancedArithmetic
{
    int divisorSum(int n)
    {
    int total=0,i;
        for(i=1; i<=n; i++)
        { 
            if(n%i == 0)
            { 
            total+=i; 
            }
        }
        return total;
    }
};

int main()
{
    int n;
    cin >> n;
    AdvancedArithmetic *myCalculator = new Calculator(); 
    int sum = myCalculator->divisorSum(n);
    cout << "I implemented: AdvancedArithmetic\n" << sum;
    return 0;
}

Output:-


Hacker Rank solution For Day 19: Interfaces

You May Also Like:-

1. Hackerrank Solution For Day 12: Inheritance

2. Hackerrank Solution For Day 13: Abstract Classes

3. Hackerrank Solution For Day 14: Scope

4. Hackerrank Solution For Day 15: Linked List

5. Hackerrank Solution For Day 20: Sorting

6. Hackerrank Solution For Day 21: Generics

7. Hackerrank Solution For Day 22: Binary Search Trees

8. Hackerrank Solution For Day 23: BST Level-Order Traversal

9. Hackerrank Solution For Day 24: More Linked Lists

10. Hackerrank Solution For Day 25: Running Time and Complexity

Ghanendra Yadav
Ghanendra Yadav

I Am Ghanendra Yadav Owner Of This Website. I Love Programming, Web Developing, Logo Making, Banner And Website designing. Currently I Am Studying In NIT Warangal And Also Working With WSDC( As Web Application Developer ) In NIT Warangal For Any Query Mail Me I Will 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