234k views
4 votes
WHAT IS THE PYHTON CODE AND C CODE FOR THE PSEUDOCODE BELOW?

START
DELCARE num, count = 1, product AS INTEGER
DO
PRINT "Please enter number"
READ num
IF num < 1 OR num > 12 THEN
PRINT " Sorry invalid number…"
ENDIF
WHILE num < 1 OR num > 12
WHILE count <= 12
product = num* count
PRINT count , "*" , num, "=", product
ENDWHILE
STOP

User Rnk Jangir
by
8.7k points

1 Answer

6 votes

Final answer:

The student's question pertains to converting pseudocode to actual Python and C code. The pseudocode is for generating a multiplication table for a number within a range of 1 to 12.

Step-by-step explanation:

The given pseudocode can be implemented both in Python and C. The program is designed to compute the multiplication table for a number input by the user, ensuring the number is within the range from 1 to 12.



Python Code

while True:
num = int(input("Please enter a number: "))
if 1 <= num <= 12:
break
print("Sorry invalid number...")

for count in range(1, 13):
product = num * count
print(f"{count} * {num} = {product}")



C Code

#include
int main() {
int num, count, product;
do
printf("Please enter a number: ");
scanf("%d", &num);
if(num < 1 while(num < 1 || num > 12);

for(count = 1; count <= 12; count++) {
product = num * count;
printf("%d * %d = %d\\", count, num, product);
}
return 0;
}
User Yoan Arnaudov
by
8.5k points