int originalNumber, remainder, result = 0, count = 0; originalNumber = n; // To get the number of digits while (originalNumber != 0) { originalNumber /= 10; ++count; } originalNumber = n; // Check if the number is an Armstrong number while (originalNumber != 0) { remainder = originalNumber % 10; result += pow(remainder, count); originalNumber /= 10; } if (result == n) return 1; else return result; } :36:1: error: expected identifier or ( before } token 44 | } showing this error
Question
int originalNumber, remainder, result = 0, count = 0;
originalNumber = n;
// To get the number of digits
while (originalNumber != 0) {
originalNumber /= 10;
++count;
}
originalNumber = n;
// Check if the number is an Armstrong number
while (originalNumber != 0) {
remainder = originalNumber % 10;
result += pow(remainder, count);
originalNumber /= 10;
}
if (result == n)
return 1;
else
return result;
} :36:1: error: expected identifier or ( before } token 44 | } showing this error
Solution
It seems like you're trying to write a function in C or C++ to check if a number is an Armstrong number. However, you're getting an error because your function declaration is missing.
Here's how you can fix it:
#include<math.h>
int checkArmstrongNumber(int n) {
int originalNumber, remainder, result = 0, count = 0;
originalNumber = n;
// To get the number of digits
while (originalNumber != 0) {
originalNumber /= 10;
++count;
}
originalNumber = n;
// Check if the number is an Armstrong number
while (originalNumber != 0) {
remainder = originalNumber % 10;
result += pow(remainder, count);
originalNumber /= 10;
}
if (result == n)
return 1;
else
return result;
}
In this corrected code, I've added the function declaration int checkArmstrongNumber(int n) at the beginning. This tells the compiler that we're defining a function named checkArmstrongNumber that takes an integer n as input and returns an integer.
Similar Questions
#include<math.h> int checkArmstrongNumber(int n) { int originalNumber, remainder, result = 0, count = 0; originalNumber = n; // To get the number of digits while (originalNumber != 0) { originalNumber /= 10; ++count; } originalNumber = n; // Check if the number is an Armstrong number while (originalNumber != 0) { remainder = originalNumber % 10; result += pow(remainder, count); originalNumber /= 10; } if (result == n) return 1; else return result; } Input Your Output Expected Output 371 970554640 1
Write a C program to determine if a given integer is an Armstrong number or not. An Armstrong number (also known as a narcissistic number or pluperfect digital invariant) is a number that is equal to the sum of its own digits raised to the power of the number of digits. For example, 153 is an Armstrong number because 13+53+33=15313+53+33=153.Design a function called isArmstrong that takes an integer num as input and returns 1 if num is an Armstrong number, and 0 otherwise. Your program should prompt the user to enter an integer, call the isArmstrong function to check if it is an Armstrong number, and display an appropriate message indicating whether the entered number is an Armstrong number or not.inputEnter a number: 153output153 is an Armstrong number.
Armstrong numbers? 6.5 marks Problem Statement Any number n having k digits is an Armstrong number, if the sum of the digits of n each raised to the power k is equal to n. If d1, d2, d3 ... dm be the digits of the number n, then n is an Armstrong number if, d1k + d2k + d3k ... dmk = n You are given a function, int DetectArmstrongNumber(int n); The function takes an integer n as input. You need to implement the function to detect if n is an Armstrong number or not. If n is an Armstrong number then return '1', else return the sum of digits, each digit raised to the power of the number of digits, i.e. d1k + d2k + d3k ... dmk Note: All calculation lie within integral range. Example: Input: 13 Output: 10 Explanation: 12 + 32 = 10, which is not equal to 13, hence 13 is not an Armstrong number. So the output is 10. The custom input format for the above case: 13 (The line represents 'n') Sample input 153 Sample Output 1 The custom input format for the above case: 153 (The line represents 'n') Instructions : This is a template based question, DO NOT write the "main" function. Your code is judged by an automated system, do not write any additional welcome/greeting messages. "Save and Test" only checks for basic test cases, more rigorous cases will be used to judge your code while scoring. Additional score will be given for writing optimized code both in terms of memory and execution time. Now let's start coding : Language: C (Gcc 11.3) Day Mode Read-only code below . . . 1 int DetectArmstrongNumber(int n); 2 int main() 3 { 4 //Input read from STDIN 5 int result = DetectArmstrongNumber(n); 6 //Value in result printed to STDOUT 7 return 0; 8 } 9 Write your code below . . . 10 int DetectArmstrongNumber(int n) 11 { 12 13 } 14 15
Write a C program to check whether a number is Armstrong number or not.
write a program to print armstrong numbers to n
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.