Check whether number is Gapful Number
Here given code implementation process.
// Java program for
// Check whether number is Gapful Number
public class Numbers
{
public int firstDigit(int num)
{
// Get number of digit - 1
int digit = (int) Math.log10(num);
// Return the value of first digit
return (int)(num / Math.pow(10, digit));
}
public int lastDigit(int num)
{
// Return last digit
return num % 10;
}
public void isGapFulNumber(int num)
{
System.out.print("\n Given number : " + num);
if (num <= 99)
{
System.out.print("\n No");
}
else
{
// Work with more than two digit
// Get first and last digit combination
int value = firstDigit(num) * 10 + lastDigit(num);
if (num % value == 0)
{
System.out.print("\n Yes ");
}
else
{
System.out.print("\n No ");
}
}
}
public static void main(String[] args)
{
Numbers task = new Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task.isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task.isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task.isGapFulNumber(248952);
}
}
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
// C Program
// Check whether number is Gapful Number
#include <stdio.h>
#include <math.h>
int absValue(int num)
{
if (num < 0)
{
return -num;
}
return num;
}
int firstDigit(int num)
{
// Get number of digit - 1
int digit = (int) log10(num);
// Return the value of first digit
return (int)(num / pow(10, digit));
}
int lastDigit(int num)
{
// Return last digit
return num % 10;
}
void isGapFulNumber(int num)
{
printf("\n Given number : %d", num);
if (num <= 99)
{
printf("\n No");
}
else
{
// Work with more than two digit
// Get first and last digit combination
int value = firstDigit(num) *10 + lastDigit(num);
if (num % value == 0)
{
printf("\n Yes ");
}
else
{
printf("\n No ");
}
}
}
int main()
{
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
isGapFulNumber(248952);
return 0;
}
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
// Include header file
#include <iostream>
#include <math.h>
using namespace std;
// C++ program for
// Check whether number is Gapful Number
class Numbers
{
public: int firstDigit(int num)
{
// Get number of digit - 1
int digit = (int) log10(num);
// Return the value of first digit
return (int)(num / pow(10, digit));
}
int lastDigit(int num)
{
// Return last digit
return num % 10;
}
void isGapFulNumber(int num)
{
cout << "\n Given number : " << num;
if (num <= 99)
{
cout << "\n No";
}
else
{
// Work with more than two digit
// Get first and last digit combination
int value = this->firstDigit(num) *10 + this->lastDigit(num);
if (num % value == 0)
{
cout << "\n Yes ";
}
else
{
cout << "\n No ";
}
}
}
};
int main()
{
Numbers *task = new Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task->isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task->isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task->isGapFulNumber(248952);
return 0;
}
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
package main
import "math"
import "fmt"
// Go program for
// Check whether number is Gapful Number
type Numbers struct {}
func getNumbers() * Numbers {
var me *Numbers = &Numbers {}
return me
}
func(this Numbers) firstDigit(num int) int {
// Get number of digit - 1
var digit int = int(math.Log10(float64(num)))
// Return the value of first digit
return int((float64(num) / math.Pow(10, float64(digit))))
}
func(this Numbers) lastDigit(num int) int {
// Return last digit
return num % 10
}
func(this Numbers) isGapFulNumber(num int) {
fmt.Print("\n Given number : ", num)
if num <= 99 {
fmt.Print("\n No")
} else {
// Work with more than two digit
// Get first and last digit combination
var value int = this.firstDigit(num) * 10 + this.lastDigit(num)
if num % value == 0 {
fmt.Print("\n Yes ")
} else {
fmt.Print("\n No ")
}
}
}
func main() {
var task * Numbers = getNumbers()
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task.isGapFulNumber(530)
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task.isGapFulNumber(7770)
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task.isGapFulNumber(248952)
}
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
// Include namespace system
using System;
// Csharp program for
// Check whether number is Gapful Number
public class Numbers
{
public int firstDigit(int num)
{
// Get number of digit - 1
int digit = (int) Math.Log10(num);
// Return the value of first digit
return (int)(num / Math.Pow(10, digit));
}
public int lastDigit(int num)
{
// Return last digit
return num % 10;
}
public void isGapFulNumber(int num)
{
Console.Write("\n Given number : " + num);
if (num <= 99)
{
Console.Write("\n No");
}
else
{
// Work with more than two digit
// Get first and last digit combination
int value = this.firstDigit(num) * 10 + this.lastDigit(num);
if (num % value == 0)
{
Console.Write("\n Yes ");
}
else
{
Console.Write("\n No ");
}
}
}
public static void Main(String[] args)
{
Numbers task = new Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task.isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task.isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task.isGapFulNumber(248952);
}
}
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
<?php
// Php program for
// Check whether number is Gapful Number
class Numbers
{
public function firstDigit($num)
{
// Get number of digit - 1
$digit = (int) log10($num);
// Return the value of first digit
return (int)($num / pow(10, $digit));
}
public function lastDigit($num)
{
// Return last digit
return $num % 10;
}
public function isGapFulNumber($num)
{
echo("\n Given number : ".$num);
if ($num <= 99)
{
echo("\n No");
}
else
{
// Work with more than two digit
// Get first and last digit combination
$value = $this->firstDigit($num) * 10 + $this->lastDigit($num);
if ($num % $value == 0)
{
echo("\n Yes ");
}
else
{
echo("\n No ");
}
}
}
}
function main()
{
$task = new Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
$task->isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
$task->isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
$task->isGapFulNumber(248952);
}
main();
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
// Node JS program for
// Check whether number is Gapful Number
class Numbers
{
firstDigit(num)
{
// Get number of digit - 1
var digit = parseInt(Math.log10(num));
// Return the value of first digit
return parseInt((num / Math.pow(10, digit)));
}
lastDigit(num)
{
// Return last digit
return num % 10;
}
isGapFulNumber(num)
{
process.stdout.write("\n Given number : " + num);
if (num <= 99)
{
process.stdout.write("\n No");
}
else
{
// Work with more than two digit
// Get first and last digit combination
var value = this.firstDigit(num) * 10 + this.lastDigit(num);
if (num % value == 0)
{
process.stdout.write("\n Yes ");
}
else
{
process.stdout.write("\n No ");
}
}
}
}
function main()
{
var task = new Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task.isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task.isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task.isGapFulNumber(248952);
}
main();
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
import math
# Python 3 program for
# Check whether number is Gapful Number
class Numbers :
def firstDigit(self, num) :
# Get number of digit - 1
digit = int(math.log10(num))
# Return the value of first digit
return int((num / 10 ** digit))
def lastDigit(self, num) :
# Return last digit
return num % 10
def isGapFulNumber(self, num) :
print("\n Given number : ", num, end = "")
if (num <= 99) :
print("\n No", end = "")
else :
# Work with more than two digit
# Get first and last digit combination
value = self.firstDigit(num) * 10 + self.lastDigit(num)
if (num % value == 0) :
print("\n Yes ", end = "")
else :
print("\n No ", end = "")
def main() :
task = Numbers()
# Test A
# num = 530
# first (5) and last digit (0)
# 530 % 50 != 0
# Output : No
task.isGapFulNumber(530)
# Test B
# num = 7770
# first (7) and last digit (0)
# 7770 % 70 == 0
# Output : Yes
task.isGapFulNumber(7770)
# Test C
# num = 248952
# first (2) and last digit (2)
# 248952 % 22 == 0
# Output : Yes
task.isGapFulNumber(248952)
if __name__ == "__main__": main()
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
# Ruby program for
# Check whether number is Gapful Number
class Numbers
def firstDigit(num)
# Get number of digit - 1
digit = Math.log10(num).to_i
# Return the value of first digit
return (num / 10 ** digit).to_i
end
def lastDigit(num)
# Return last digit
return num % 10
end
def isGapFulNumber(num)
print("\n Given number : ", num)
if (num <= 99)
print("\n No")
else
# Work with more than two digit
# Get first and last digit combination
value = self.firstDigit(num) * 10 + self.lastDigit(num)
if (num % value == 0)
print("\n Yes ")
else
print("\n No ")
end
end
end
end
def main()
task = Numbers.new()
# Test A
# num = 530
# first (5) and last digit (0)
# 530 % 50 != 0
# Output : No
task.isGapFulNumber(530)
# Test B
# num = 7770
# first (7) and last digit (0)
# 7770 % 70 == 0
# Output : Yes
task.isGapFulNumber(7770)
# Test C
# num = 248952
# first (2) and last digit (2)
# 248952 % 22 == 0
# Output : Yes
task.isGapFulNumber(248952)
end
main()
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
// Scala program for
// Check whether number is Gapful Number
class Numbers()
{
def firstDigit(num: Int): Int = {
// Get number of digit - 1
var digit: Int = Math.log10(num).toInt;
// Return the value of first digit
return (num / Math.pow(10, digit)).toInt;
}
def lastDigit(num: Int): Int = {
// Return last digit
return num % 10;
}
def isGapFulNumber(num: Int): Unit = {
print("\n Given number : " + num);
if (num <= 99)
{
print("\n No");
}
else
{
// Work with more than two digit
// Get first and last digit combination
var value: Int = firstDigit(num) * 10 + lastDigit(num);
if (num % value == 0)
{
print("\n Yes ");
}
else
{
print("\n No ");
}
}
}
}
object Main
{
def main(args: Array[String]): Unit = {
var task: Numbers = new Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task.isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task.isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task.isGapFulNumber(248952);
}
}
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
import Foundation;
// Swift 4 program for
// Check whether number is Gapful Number
class Numbers
{
func firstDigit(_ num: Int) -> Int
{
// Get number of digit - 1
let digit: Int = Int(log10(Double(num)));
// Return the value of first digit
return Int((Double(num) / pow(10, Double(digit))));
}
func lastDigit(_ num: Int) -> Int
{
// Return last digit
return num % 10;
}
func isGapFulNumber(_ num: Int)
{
print("\n Given number : ", num, terminator: "");
if (num <= 99)
{
print("\n No", terminator: "");
}
else
{
// Work with more than two digit
// Get first and last digit combination
let value: Int = self.firstDigit(num) * 10 + self.lastDigit(num);
if (num % value == 0)
{
print("\n Yes ", terminator: "");
}
else
{
print("\n No ", terminator: "");
}
}
}
}
func main()
{
let task: Numbers = Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task.isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task.isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task.isGapFulNumber(248952);
}
main();
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
// Kotlin program for
// Check whether number is Gapful Number
class Numbers
{
fun firstDigit(num: Int): Int
{
// Get number of digit - 1
val digit: Int = Math.log10(num.toDouble()).toInt();
// Return the value of first digit
return (num / Math.pow(10.0, digit.toDouble())).toInt();
}
fun lastDigit(num: Int): Int
{
// Return last digit
return num % 10;
}
fun isGapFulNumber(num: Int): Unit
{
print("\n Given number : " + num);
if (num <= 99)
{
print("\n No");
}
else
{
// Work with more than two digit
// Get first and last digit combination
val value: Int = this.firstDigit(num) * 10 + this.lastDigit(num);
if (num % value == 0)
{
print("\n Yes ");
}
else
{
print("\n No ");
}
}
}
}
fun main(args: Array < String > ): Unit
{
val task: Numbers = Numbers();
// Test A
// num = 530
// first (5) and last digit (0)
// 530 % 50 != 0
// Output : No
task.isGapFulNumber(530);
// Test B
// num = 7770
// first (7) and last digit (0)
// 7770 % 70 == 0
// Output : Yes
task.isGapFulNumber(7770);
// Test C
// num = 248952
// first (2) and last digit (2)
// 248952 % 22 == 0
// Output : Yes
task.isGapFulNumber(248952);
}
Output
Given number : 530
No
Given number : 7770
Yes
Given number : 248952
Yes
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