mirror of
https://github.com/TheAlgorithms/C-Plus-Plus.git
synced 2026-04-13 17:50:45 +08:00
feat: Modify search/text_search.cpp (#1662)
* Modified search/text_search.cpp * Added tests * Added a few test cases * Added a few more test cases and documentation * Minor fix * Minor fixes * Minor fixes * Minor output fixes * Minor output fixes * Minor readability fixes * clang-format and clang-tidy fixes fora01765a6* Restored original settings * clang-format and clang-tidy fixes for6a8f3a4eCo-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com> Co-authored-by: David Leal <halfpacho@gmail.com>
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
// Program to check whether a number is an armstrong number or not
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include <iostream>
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
|
||||
@@ -8,34 +8,32 @@ int main() {
|
||||
int n = 0, temp = 0, rem = 0, count = 0, sum = 0;
|
||||
cout << "Enter a number: ";
|
||||
cin >> n;
|
||||
|
||||
|
||||
temp = n;
|
||||
|
||||
|
||||
/* First Count the number of digits
|
||||
in the given number */
|
||||
while(temp != 0) {
|
||||
while (temp != 0) {
|
||||
temp /= 10;
|
||||
count++;
|
||||
}
|
||||
|
||||
/* Calaculation for checking of armstrongs number i.e.
|
||||
/* Calaculation for checking of armstrongs number i.e.
|
||||
in a n digit number sum of the digits raised to a power of n
|
||||
is equal to the original number */
|
||||
|
||||
|
||||
temp = n;
|
||||
while(temp!=0) {
|
||||
rem = temp%10;
|
||||
sum += (int) pow(rem,count);
|
||||
temp/=10;
|
||||
while (temp != 0) {
|
||||
rem = temp % 10;
|
||||
sum += static_cast<int>(pow(rem, count));
|
||||
temp /= 10;
|
||||
}
|
||||
|
||||
|
||||
if (sum == n) {
|
||||
cout << n << " is an armstrong number";
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
cout << n << " is not an armstrong number";
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user