Question: Write the Pep/9 equivalent of this java program. Your program must use a function and pass information to and from the function using the stack.
Write the Pep/9 equivalent of this java program. Your program must use a function and pass information to and from the function using the stack. import java.util.Scanner; public class Q2 { public static int multiply(int a, int b) { int sum; sum=0; while (b>0) { sum=sum+a; b=b-1; } return sum; }
public static void main(String s[]) { Scanner scanner = new Scanner(System.in); int x,y,result; System.out.print("Enter two integers:"); x=scanner.nextInt(); y=scanner.nextInt(); result=multiply(x,y); System.out.println("result is "+result); } } --------------------------- C Code ----------------------------------- int multiply(int a, int b) { int sum; sum = 0; while (b > 0) { sum = sum + a; b = b - 1; } return sum; }
void main() { int x, y, result; printf("Enter two integers:"); scanf("%d %d", &x, &y); result = multiply(x, y); printf("result is %d ", result); scanf("%d %d", &x, &y); }
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
