# Programming Questions for Practice

Write a function to test whether a given number is a Disarium number.

``````#include <stdio.h>
#include <stdlib.h>

int power(int number, int powerNumber) {
int result = number;
while(powerNumber > 1) {
result = result * number;
powerNumber--;
}
}

void isDisarium(int number) {
int length = 0, sum = 0, lastDigit;
int number_copy = number;

while(number > 0) {
length++;
number /= 10;
}

number = number_copy;
while(number > 0) {
lastDigit = number % 10;
sum = sum + power(lastDigit, length);
number = number / 10;
length--;
}

if(number_copy == sum)
printf("%d is a Disarium number", number_copy);
else
printf("%d is not a Disarium number", number_copy);

}
int main()
{
int number;
printf("Enter any number: ");
scanf("%d", &number);

isDisarium(number);

return 0;
}``````
``````import java.util.Scanner;

public class NumberTest {

static void isDisarium(int number) {
int number_length = String.valueOf(number).length();
int sum = 0;
int number_copy = number;
while(number_length > 0) {
int lastDigit = number % 10;
sum = sum + (int)Math.pow(lastDigit, number_length);
number_length--;
number = number / 10;
}
if(sum == number_copy)
System.out.println(number_copy + " is a Disarium number");
else
System.out.println(number_copy + " is not a Disarium number");
}

public static void main(String[] args) {
System.out.print("Enter any decimal number: ");

isDisarium(number);
}
}``````
``````def isDisarium(number):
number_copy = number
length = len(str(number))
sum = 0
while (length > 0):
digit = number % 10
sum = sum + digit ** length
length = length - 1
number = number // 10
if(sum == number_copy):
print(f"{number_copy} is Disarium number")
else:
print(f"{number_copy} is not Disarium number")

isDisarium(175)``````

#### List of programs that you may also intrested

Program Statement Code Available
Hello World program C, Java, Python
Write a function to test whether a given number is even or odd. C, Java, Python
Write a function to test whether a given number is prime or not. C, Java, Python
Write a function to find factorial of a given number. C, Java, Python
Write a function to convert decimal number to binary number. C, Java, Python
Write a function to test whether a given number is a Disarium number. C, Java, Python
Write a function to test whether a given number is happy number. C, Java, Python
Write a function to test whether a given number is Palindrome. C, Java, Python
Write a function to test whether a given number is Armstrong number. C, Java, Python
Write a function to return sum of digits of a given integer number. C, Java, Python
Write a function to print reverse of a given number. C, Java, Python
A company is transmitting data to another server. The data is in the form of numbers. To secure the data during transmission, they plan to obtain a security key that will be sent along with the data. The security key is identified as the count of the unique repeating digits in the data.
Write an algorithm to find the security key for the data.
C
Given an integer, if the number is prime, return 1. Otherwise return its smallest divisor greater than 1. Use the function isPrime(). C
Given an integer n, calculate the first n numbers in the Fibonacci sequence given starting elements of (0,1). Return an array of n integers, including the given (0, 1) in the sequence. Use the function fibonacci(). C
Given an integer num, return the number of steps to reduce it to zero. In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it. C, Java, Python
Given an integer array nums, return true if any value appears at least twice in the array, and return false if every element is distinct. C
Write a method that, given a positive integer number, returns the smallest number with the same number of digits.
For instance, given N=4751, the method returns 1000. Given N=100, the method should return 100. Given N=1, the method should return 0.
C, Java
Write a program to find the simple and compound interest. C
Write a program to swap two numbers without using third variable. C
Write a program to find the greatest of three numbers using conditional operator. C
Write a program to test whether given year is leap year or not. C
Write a function to check the grade of a student based on scores in 5 different subjects. C
Write a function to find the difference between minimum and maximum in given array of elements.
Input: array of elements, length of the array.
Output: difference between min and max.
C
Write a program that test a number is Even or Odd without using remainder operator. C
Write a program to find the difference between smallest and biggest prime number in a given range. Assume that both the inputs are positive. C
Write a function that display a given decimal number in binary number. C, Java, Python
Write a function to set the bit at given position (index) in a binary number. C
Write a function to clear the bit at given position (index) in a binary number. C
Write a function to flip the bit at given position (index) in a binary number. C
A combined Salsa Lesson is to be conducted for two different classes having 8 students each in a school. There are two queues of students, queue A and queue B. You are given a string A denoting the queue sequence of students in queue A and string B denoting the queue sequence of students in queue B. A good pair is a pair containing one boy and one girl. Pairing the students at Nth position of queue A with the student at Nth position of queue B is the only possible method of pairing. Write a program to help the organiser count the total number of good pairs that will be formed, when the students are paired according to the method above. Your task is to return the percentage of good pairs among the total number of pairs that will be formed. C
Write a program to rotate the given array towards left by specified number of places. C
Write a program to rotate the given array towards right by specified number of places. C
Write a program to shift the given array towards right by N number of places. Fill the ZERO in the right most N places. C
Write a program to shift the given array towards left by N number of places. Fill the ZERO in the right most N places. C
Write a program to reverse the given array. C
Write a program to perform addition of two matrices. C
Write a program to perform multiplication of two matrices. C
Write a program to perform transpose of a matrix. C
You are given with an array of integers, arr, of size array_length. Find the index, i, of the first integer num in array arr, that can be represented as a product of two integers A and B. A and B have indices j and k, respectively. If there is no such integer, return -1. C
You are given an array of positive integers, arr, of size array_length. How many elements in array arr are perfectly divisible by either the product or sum of their digits? C
Maximum possible difference of two elements of an array C
Write a program for array rotation by ‘k’ elements to the right. C
Find the minimum element in a sorted and rotated array. C
Find Second largest element in an array C
Find the largest K elements in an array C
Program Statement Code Available