
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 7197 Articles for C++

210 Views
Here we will see how to check a number is divisible by 75 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 75, when the number is divisible by 3 and also divisible by 25. if the sum of digits is divisible by 3, then the number is divisible by 3, and if last two digits are divisible by 25, then the number is divisible by 25.Example Live Demo#include using namespace std; bool isDiv75(string num){ int n = num.length(); long sum = accumulate(begin(num), end(num), ... Read More

598 Views
Here we will see how to check a number is divisible by 5 or not. In this case the number is very large number. So we put the number as string.To check whether a number is divisible by 5, So to check divisibility by 5, we have to see the last number is 0 or 5.Example Live Demo#include using namespace std; bool isDiv5(string num){ int n = num.length(); if(num[n - 1] != '5' && num[n - 1] != '0') return false; return true; } int main() { string num = "154484585745184258458158245285265"; if(isDiv5(num)){ cout

470 Views
Here we will see how to check a number is divisible by 3 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 3, if the sum of digits is divisible by 3.Example Live Demo#include using namespace std; bool isDiv3(string num){ int n = num.length(); long sum = accumulate(begin(num), end(num), 0) - '0' * n; if(sum % 3 == 0) return true; return false; } int main() { string num = "3635883959606670431112222"; if(isDiv3(num)){ cout

210 Views
Here we will see how to check a number is divisible by 25 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 25, when the last two digits are 00, or they are divisible by 25.Example Live Demo#include using namespace std; bool isDiv25(string num){ int n = num.length(); int last_two_digit_val = (num[n-2] - '0') * 10 + ((num[n-1] - '0')); if(last_two_digit_val % 25 == 0) return true; return false; } int main() { string num = "451851549333150"; if(isDiv25(num)){ cout

211 Views
Here we will see how to check a number is divisible by 20 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 20, when that is divisible by 10, and after dividing 10, the remaining number is divisible by 2. So the case is simple. If the last digit is 0, then it is divisible by 10, and when it is divisible by 10, then the second last element is divisible by 2, the number is divisible by 20.Example Live Demo#include using namespace std; bool isDiv20(string ... Read More

262 Views
Here we will see how to check a number is divisible by 2, 3 and 5 or not. In this case the number is very large number. So we put the number as string.A number will be divisible by 2, 3 and 5 if that number is divisible by LCM of 2, 3 and 5. So the LCM of 2, 3, 5 is 30. We have to check the number is divisible by 30 or not. A number is divisible by 30 when it is divisible by 10 (last digit is 0) and divisible by 3 (sum of all digits ... Read More

613 Views
In this article, we are given a larger number and we need to check whether it is divisible by 11 or not using the C++ program. To handle large numbers, we treat the number as a string and apply a divisibility rule to check if it's divisible by 11. Rule of Divisibility by 11 A number is divisible by 11 if the difference between the sum of its digits at odd positions and the sum of its digits at even positions is divisible by 11. Consider the following example scenarios to understand the divisibility of a large number ... Read More

178 Views
Here we will see how to check a number is divisible by 15 or not. In this case the number is very large number. So we put the number as string.To check whether a number is divisible by 15, if the number is divisible by 5, and divisible by 3. So to check divisibility by 5, we have to see the last number is 0 or 5. To check divisibility by 3, we will see the sum of digits are divisible by 3 or not.Example Live Demo#include using namespace std; bool isDiv15(string num){ int n = num.length(); if(num[n ... Read More

429 Views
Here we will see how to check a string is made up of alternating characters or not. If a string is like XYXYXY, it is valid, if a string is like ABCD, that is invalid.The approach is simple. We will check whether all ith character and i+2 th character are same or not. if they are not same, then return false, otherwise return true.Example Live Demo#include using namespace std; bool hasAlternateChars(string str){ for (int i = 0; i < str.length() - 2; i++) { if (str[i] != str[i + 2]) { return ... Read More

377 Views
Given an input string with vowels and consonants. Rearrange the string such a way that vowels and consonants occupies alternate position in final string. As we are arranging vowels and consonants at alternate position the input string must satisfy either of the following conditions −Number of vowels and consonants must be same e.g. string "individual" has 5 vowels and 5 consonants.If number of vowels are more, then difference between number of vowels and number of consonants must be 1 e.g. string "noe" has 2 vowels and 1 consonant.If number of consonants are more, then difference between number of consonants and ... Read More