Deficient Number

Here given code implementation process.

//C Program
//Check if a given number is deficient or not
#include <stdio.h>

// Function which is calculate sum of divisors in given number  
int divisor_sum(int number) 
{ 
  //numbers are always on itself divide
  int result = number; 

  for (int i=1; i<= number/2; i++) 
  { 
    if (number%i==0) 
    { 
      //When number is divide by i
      result += i;
    } 
  } 

  return result; 
} 
//Function are show the result number is deficient or not
void is_deficient(int number) 
{ 
  //Check whether number divisor sum is less than twice given number?
  if(divisor_sum(number) < 2 * number)
  {
    //When Yes
    printf("%d Is an Deficient Number\n",number);
  } 
  else
  {
    //When No
    printf("%d Is not a Deficient Number\n",number);
  }
} 

int main() {
  //Test Cases
  is_deficient(15);
  is_deficient(20);
  is_deficient(12);
  is_deficient(17);
  is_deficient(23);
  return 0;
}

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
/*
 C++ Program
 Check if a given number is deficient or not
*/
#include<iostream>
using namespace std;

class MyNumber {
	public:

		// Function which is calculate sum of divisors in given number  
		int divisor_sum(int number) {
			//numbers are always on itself divide
			int result = number;
			for (int i = 1; i <= number / 2; i++) {
				if (number % i == 0) {
					//When number is divide by i
					result += i;
				}
			}
			return result;
		}
	//Function are show the result number is deficient or not
	void is_deficient(int number) {
		//Check whether number divisor sum is less than twice given number?

		if (this->divisor_sum(number) < 2 *number) {
			//When Yes

			cout << number << " Is an Deficient Number\n";
		} else {
			//When No

			cout << number << " Is not a Deficient Number\n";
		}
	}
};
int main() {
	MyNumber obj ;
	// Test Case
	obj.is_deficient(15);
	obj.is_deficient(20);
	obj.is_deficient(12);
	obj.is_deficient(17);
	obj.is_deficient(23);
	return 0;
}

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
/*
  Java Program
  Check if a given number is deficient or not
*/

public class MyNumber {

  // Function which is calculate sum of divisors in given number  
  public int divisor_sum(int number) 
  { 
    //numbers are always on itself divide
    int result = number; 

    for (int i=1; i<= number/2; i++) 
    { 
      if (number%i==0) 
      { 
        //When number is divide by i
        result += i;
      } 
    } 

    return result; 
  } 
  //Function are show the result number is deficient or not
  public void is_deficient(int number) 
  { 
    //Check whether number divisor sum is less than twice given number?
    if(divisor_sum(number) < 2 * number)
    {
      //When Yes
      System.out.print(number+" Is an Deficient Number\n");
    } 
    else
    {
      //When No
      System.out.print(number+" Is not a Deficient Number\n");
    }
  } 
  public static void main(String[] args) {

    MyNumber obj = new MyNumber();
    // Test Case
    obj.is_deficient(15);
    obj.is_deficient(20);
    obj.is_deficient(12);
    obj.is_deficient(17);
    obj.is_deficient(23);

  }
}

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
/*
  C# Program
  Check if a given number is deficient or not
*/
using System;
public class MyNumber {

	// Function which is calculate sum of divisors in given number  
	public int divisor_sum(int number) {
		//numbers are always on itself divide
		int result = number;

		for (int i = 1; i <= number / 2; i++) {
			if (number % i == 0) {
				//When number is divide by i
				result += i;
			}
		}

		return result;
	}
	//Function are show the result number is deficient or not
	public void is_deficient(int number) {
		//Check whether number divisor sum is less than twice given number?
		if (divisor_sum(number) < 2 * number) {
			//When Yes
			Console.Write(number + " Is an Deficient Number\n");
		} else {
			//When No
			Console.Write(number + " Is not a Deficient Number\n");
		}
	}
	public static void Main(String[] args) {

		MyNumber obj = new MyNumber();
		// Test Case
		obj.is_deficient(15);
		obj.is_deficient(20);
		obj.is_deficient(12);
		obj.is_deficient(17);
		obj.is_deficient(23);

	}
}

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
# Python 3 Program
# Check if a given number is deficient or not

class MyNumber :
	# Function which is calculate sum of divisors in given number  
	def divisor_sum(self, number) :
		#numbers are always on itself divide
		result = number
		i = 1
		while (i <= int(number / 2)) :
			if (number % i == 0) :
				#When number is divide by i
				result += i
			
			i += 1
		
		return result
	
	#Function are show the result number is deficient or not
	def is_deficient(self, number) :
		#Check whether number divisor sum is less than twice given number?

		if (self.divisor_sum(number) < 2 * number) :
			print(number ," Is an Deficient Number")
		else :
			print(number ," Is not a Deficient Number")
		
	

def main() :
	obj = MyNumber()
	#Test Case
	obj.is_deficient(15)
	obj.is_deficient(20)
	obj.is_deficient(12)
	obj.is_deficient(17)
	obj.is_deficient(23)


if __name__ == "__main__":
	main()

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
# Ruby Program 
# Check if a given number is deficient or not

class MyNumber 
	# Function which is calculate sum of divisors in given number  
	def divisor_sum(number) 
		#numbers are always on itself divide
		result = number
		i = 1
		while (i <= number / 2) 
			if (number % i == 0) 
				#When number is divide by i
				result += i
			end
			i += 1
		end
		return result
	end
	#Function are show the result number is deficient or not
	def is_deficient(number) 
		#Check whether number divisor sum is less than twice given number?

		if (self.divisor_sum(number) < 2 * number) 
			print(number ," Is an Deficient Number\n")
		else 
			print(number ," Is not a Deficient Number\n")
		end
	end
end
def main() 
	obj = MyNumber.new()
	#Test Case
	obj.is_deficient(15)
	obj.is_deficient(20)
	obj.is_deficient(12)
	obj.is_deficient(17)
	obj.is_deficient(23)
end
main()

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
/*
 Scala Program
 Check if a given number is deficient or not
*/
class MyNumber {
	// Function which is calculate sum of divisors in given number  
	def divisor_sum(number: Int): Int = {
		//numbers are always on itself divide
		var result: Int = number;
		var i: Int = 1;
		while (i <= number / 2) {
			if (number % i == 0) {
				//When number is divide by i
				result += i;
			}
			i += 1;
		}
		return result;
	}
	//Function are show the result number is deficient or not
	def is_deficient(number: Int): Unit = {
		//Check whether number divisor sum is less than twice given number?

		if (this.divisor_sum(number) < 2 * number) {
			print(s"$number Is an Deficient Number\n");
		} else {
			print(s"$number Is not a Deficient Number\n");
		}
	}
}
object Main {
	def main(args: Array[String]): Unit = {
		var obj: MyNumber = new MyNumber();
		//Test Case
		obj.is_deficient(15);
        obj.is_deficient(20);
        obj.is_deficient(12);
        obj.is_deficient(17);
        obj.is_deficient(23);
	}
}

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
/*
  Swift 4 Program
  Check if a given number is deficient or not
*/
class MyNumber {
	// Function which is calculate sum of divisors in given number  
	func divisor_sum(_ number: Int) -> Int {
		//numbers are always on itself divide
		var result: Int = number;
		var i: Int = 1;
		while (i <= number / 2) {
			if (number % i == 0) {
				//When number is divide by i
				result += i;
			}
			i += 1;
		}
		return result;
	}
	//Function are show the result number is deficient or not
	func is_deficient(_ number: Int) {
		//Check whether number divisor sum is less than twice given number?

		if (self.divisor_sum(number) < 2 * number) {
			print(number ," Is an Deficient Number");
		} else {
			print(number ," Is not a Deficient Number");
		}
	}
}
func main() {
	let obj: MyNumber = MyNumber();
	//Test Case
	obj.is_deficient(15);
	obj.is_deficient(20);
	obj.is_deficient(12);
	obj.is_deficient(17);
	obj.is_deficient(23);
}
main();

Output

15  Is an Deficient Number
20  Is not a Deficient Number
12  Is not a Deficient Number
17  Is an Deficient Number
23  Is an Deficient Number
<?php
/*
  Php Program
  Check if a given number is deficient or not
*/
class MyNumber {
	// Function which is calculate sum of divisors in given number  

	public 	function divisor_sum($number) {
		//numbers are always on itself divide
		$result = $number;
		for ($i = 1; $i <= intval($number / 2); $i++) {
			if ($number % $i == 0) {
				//When number is divide by i
				$result += $i;
			}
		}
		return $result;
	}
	//Function are show the result number is deficient or not

	public 	function is_deficient($number) {
		//Check whether number divisor sum is less than twice given number?

		if ($this->divisor_sum($number) < 2 *$number) {
			//When Yes

			echo($number ." Is an Deficient Number\n");
		} else {
			//When No

			echo($number ." Is not a Deficient Number\n");
		}
	}
};

function main() {
	$obj = new MyNumber();
	// Test Case

	$obj->is_deficient(15);
	$obj->is_deficient(20);
	$obj->is_deficient(12);
	$obj->is_deficient(17);
	$obj->is_deficient(23);
}
main();

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number
/*
 Node Js Program
 Check if a given number is deficient or not
*/
class MyNumber {
	// Function which is calculate sum of divisors in given number  
	divisor_sum(number) {
		//numbers are always on itself divide
		var result = number;
		for (var i = 1; i <= parseInt(number / 2); i++) {
			if (number % i == 0) {
				//When number is divide by i
				result += i;
			}
		}
		return result;
	}
	//Function are show the result number is deficient or not
	is_deficient(number) {
		//Check whether number divisor sum is less than twice given number?

		if (this.divisor_sum(number) < 2 *number) {
			//When Yes

			process.stdout.write(number + " Is an Deficient Number\n");
		} else {
			//When No

			process.stdout.write(number + " Is not a Deficient Number\n");
		}
	}
}

function main(args) {
	var obj = new MyNumber();
	// Test Case
	obj.is_deficient(15);
	obj.is_deficient(20);
	obj.is_deficient(12);
	obj.is_deficient(17);
	obj.is_deficient(23)
}
main();

Output

15 Is an Deficient Number
20 Is not a Deficient Number
12 Is not a Deficient Number
17 Is an Deficient Number
23 Is an Deficient Number


Please share your knowledge to improve code and content standard. Also submit your doubts, and test case. We improve by your feedback. We will try to resolve your query as soon as possible.

New Comment







© 2021, kalkicode.com, All rights reserved