fork download
  1. program RandomIntegers;
  2.  
  3. uses
  4. SysUtils;
  5.  
  6. var
  7. n, M, i, x, y: Integer;
  8.  
  9. begin
  10. // Input for number of random integers and the maximum limit M
  11. Write('Enter the number of random integers (n): ');
  12. ReadLn(n);
  13. Write('Enter the maximum value (M): ');
  14. ReadLn(M);
  15.  
  16. Randomize; // Initialize random number generator
  17.  
  18. for i := 1 to n do
  19. begin
  20. x := Random(M + 1); // Generate a random integer between 0 and M
  21.  
  22. // Apply the function based on whether x is odd or even
  23. if x mod 2 = 0 then
  24. y := x * x * x // Cube for even x
  25. else
  26. y := x; // Same value for odd x
  27.  
  28. // Display x and corresponding y
  29. WriteLn('x = ', x, ', y = ', y);
  30. end;
  31. end.
  32.  
Success #stdin #stdout 0s 5292KB
stdin
Standard input is empty
stdout
Enter the number of random integers (n): Enter the maximum value (M):