Programming Articles

Page 663 of 2544

Check if a number is divisible by 23 or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 247 Views

Here we will see one program, that can check whether a number is divisible by 23 or not. Suppose a number 1191216 is given. This is divisible by 23.To check the divisibility, we have to follow this rule −Extract the last digit of the number/truncated number every timeadd 7 * (last digit of the number calculated previous) to the truncated numberRepeat these steps as long as necessary.17043, so 1704 + 7*3 = 1725 1725, so 172 + 7 * 5 = 207 207, this is 9 * 23, so 17043 is divisible by 23.Example#include #include using namespace std; ...

Read More

What is ArrayStoreException in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 683 Views

When you have created an array of a particular data type with fixed size and populate it if you store a value other than its datatype an ArrayStoreException is thrown at the run time.ExampleIn the following Java program, we are creating an Integer array and trying to store a double value in it.import java.util.Arrays; public class ArrayStoreExceptionExample {    public static void main(String args[]) {       Number integerArray[] = new Integer[3];       integerArray[0] = 12548;       integerArray[1] = 36987;       integerArray[2] = 555.50;       integerArray[3] = 12548;       ...

Read More

Check if a number is divisible by 41 or not in C++

Arnab Chakraborty
Arnab Chakraborty
Updated on 11-Mar-2026 224 Views

Here we will see one program, that can check whether a number is divisible by 41 or not. Suppose a number 104413920565933 is given. This is divisible by 41.To check the divisibility, we have to follow this rule −Extract the last digit of the number/truncated number every timesubtract 4 * (last digit of the number calculated previous) to the truncated numberRepeat these steps as long as necessary.30873, so 3087 - 4*3 = 3075 3075, so 307 - 4 * 5 = 287 287, so 28 – 4 * 7 = 0 So, 30873 is divisible by 41.Example#include #include ...

Read More

What is meant by re-throwing exceptions in Java?

Maruthi Krishna
Maruthi Krishna
Updated on 11-Mar-2026 5K+ Views

When an exception is cached in a catch block, you can re-throw it using the throw keyword (which is used to throw the exception objects).While re-throwing exceptions you can throw the same exception as it is without adjusting it as −try {    int result = (arr[a])/(arr[b]);    System.out.println("Result of "+arr[a]+"/"+arr[b]+": "+result); } catch(ArithmeticException e) {    throw e; }Or, wrap it within a new exception and throw it. When you wrap a cached exception within another exception and throw it, it is known as exception chaining or, exception wrapping, by doing this you can adjust your exception, throwing a ...

Read More

C/C++ Program for Greedy Algorithm to find Minimum number of Coins

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 6K+ Views

A greedy algorithm is an algorithm used to find an optimal solution for the given problem. greedy algorithm works by finding locally optimal solutions ( optimal solution for a part of the problem) of each part so show the Global optimal solution could be found.In this problem, we will use a greedy algorithm to find the minimum number of coins/ notes that could makeup to the given sum. For this we will take under consideration all the valid coins or notes i.e. denominations of { 1, 2, 5, 10, 20, 50 , 100, 200 , 500 ,2000 }. And we ...

Read More

C Program to check Plus Perfect Number

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 368 Views

Given a number x with n number of digits, our task is to check whether the given number’s Plus Perfect number or not. In order to check that the number is Plus Perfect Number we find the nth power of every digit d (d^n) and then sum all the digits, if the sum is equal to n then the number is Plus Perfect Number. Plus Perfect number is similar like finding an Armstrong of any number.Like In the given example below −ExampleInput: 163 Output: Number is not a perfect_number Explanation: 1^3 + 6^3 + 3^3 is not equal to 163 ...

Read More

C/C++ Tricky Programs

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 6K+ Views

Here are 10 tricky programs that will test your programming basics.1. Program to print “ ” in C++In C++ programming language, we use quotes to denote the start and end of the text is to be printed. So, printing quotes “ needs a special escape sequence. So, we will use the \” to print quotes in c++.Example#include using namespace std; int main() {    cout

Read More

Add two numbers represented by two arrays in C Program

sudhir sharma
sudhir sharma
Updated on 11-Mar-2026 2K+ Views

A number represented by the array is stored in such a form that each digit of the number is represented by an element of the array. For example, Number 234 in array is {2, 3, 4}.To add to such numbers we will first add number at the least significant digit and if the sum is greater than 10 propagate the carry. After this, we will go for the next consecutive digits of the array doing the same procedure and finding the sum.Let’s take an example to add two numbers −a = {2, 9, 6} b = {6, 3, 8} Output: ...

Read More

C Program to check if an Array is Palindrome or not

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 15K+ Views

Given an array arr[] of any size n, our task is to find out that the array is palindrome or not. Palindrome is a sequence which can be read backwards and forward as same, like: MADAM, NAMAN, etc.So to check an array is palindrome or not so we can traverse an array from back and forward like −ExampleInput: arr[] = {1, 0, 0, 1} Output: Array is palindrome Input: arr[] = {1, 2, 3, 4, 5} Output: Array is not palindromeApproach used below is as follows −We will traverse the array from starting as well as from the end until ...

Read More

C Program for Reversed String Pattern

Sunidhi Bansal
Sunidhi Bansal
Updated on 11-Mar-2026 832 Views

Given a string str, our task is to print its reversed pattern. The Pattern will be incremental in reversed order, and when the string is completed fill ‘*’ in the remaining places.Like we enter a string “abcd”, now in first line we have to print “a” then in next line we have to print “cb” and then in third line we will print “**d”.ExampleInput: str[] = { “abcd” } Output: a c b * * dExplanation −In first line print 1 characterIn second line print 2 characters in reverse orderIn third line Print 3 characters in reverse order, if the ...

Read More
Showing 6621–6630 of 25,433 articles
« Prev 1 661 662 663 664 665 2544 Next »
Advertisements