TheBulgarianWolf

Interfaces Hackerrank

May 25th, 2021
809
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using System;
  2. public interface AdvancedArithmetic{
  3.     int divisorSum(int n);
  4. }
  5.  
  6. public class Calculator : AdvancedArithmetic
  7. {
  8.     public int divisorSum(int n)
  9.     {
  10.         int sum = 0;
  11.         for(int i = n;i>0;i--){
  12.             if(n % i == 0){
  13.                 sum += i;
  14.             }
  15.         }
  16.         return sum;
  17.     }
  18. }
  19.  
  20. class Solution{
  21.     static void Main(string[] args){
  22.         int n = Int32.Parse(Console.ReadLine());
  23.         AdvancedArithmetic myCalculator = new Calculator();
  24.         int sum = myCalculator.divisorSum(n);
  25.         Console.WriteLine("I implemented: AdvancedArithmetic\n" + sum);
  26.     }
  27. }
RAW Paste Data