0% found this document useful (0 votes)
6 views4 pages

Question

The document contains Python, C++, and Java code snippets, each with errors. The Python code includes issues in the factorial, is_armstrong, and sum_even_digits functions, while the C++ code has problems in the pyramidPattern and diamondPattern functions. The Java code also has syntax errors related to class declaration and input handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Question

The document contains Python, C++, and Java code snippets, each with errors. The Python code includes issues in the factorial, is_armstrong, and sum_even_digits functions, while the C++ code has problems in the pyramidPattern and diamondPattern functions. The Java code also has syntax errors related to class declaration and input handling.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Python code with Error

def factorial(n):

fact = 1

for i in range(1, n):

fact *= i

return fact

def is_armstrong(n):

num_digits = len(str(n))

temp = n

sum = 0

while temp > 0:

digit = temp % 10

sum = digit ** num_digits

temp / 10

return sum == n

def sum_even_digits(n):

total = 0

while n > 0:

digit = n % 10

if digit % 2 == 0:

total + digit

n // 10

return total

num = input("Enter a number: ")

print(f"Factorial of {num} is {factorial(num)}")

if is_armstrong(num):

print(f"{num} is an Armstrong number.")


else:

print(f"{num} is not an Armstrong number.")

print(f"Sum of even digits in {num} is {sum_even_digits(num)}")

C++ Code With Error

#include <iostream>
using namespace std;
void pyramidPattern(int n) {
cout << "\nPyramid Pattern:\n";
for (int i = 1; i <= n; i--) {
for (int j = i; j < n; j++) {
cout << " ";
}
for (int k = 1; k <= (2 * i - 1); k++); {
cout << "* ";
}
cout << endl;
}
}
void diamondPattern(int n) {
cout << "\nDiamond Pattern:\n";

for (int i = 1; i <= n; i++) {


for (int j = i; j <= n; j++) {
cout << " ";
}
for (int k = 1; k <= (2 * i - 1); k++) {
cout << "* ";
}
cout << endl;
}
for (int i = n - 1; i >= 1; i--) {
for (int j = n; j >= i; j--) {
cout << " ";
}
for (int k = 1; k <= (2 * i - 1); k++) {
cout << "* ";
}

}
}
int main() {
int n;
cout << "Enter the number of rows: ";
cin >> n
pyramidPattern(n);
diamondPattern();
return 0;
}
Java code with Error

import [Link];

Public Class javaprogram

public static void main(string[] args)

[Link]("Enter the Number of Rows pyramid : ");

Scanner scanner=new Scanner([Link]);

int rows=[Link]();

for (int i = 1; i <= rows; i++)

for (int j = 1; j < i; j++)

[Link](" ");

for (int j = i; j >= rows; j++)

[Link](j+" ");

[Link]();

You might also like