Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

The purpose of this project is to get familiar with the programming language C to be able to learn the next lectures. The following Java

The purpose of this project is to get familiar with the programming language C to be able to learn the next lectures. The following Java program makes a list of integers, divides the list into a number of segments, and displays each segment in reverse order. Convert the program to a C program. Use the built-in function: malloc to dynamically allocate locations for variables: a and b.

import java.util.Random;

public class Main {

public static void main(String[] args){

int[] a;

int[] b;

Random r = new Random(System.currentTimeMillis());

int alength = r.nextInt(10) + 90;//9;

int blength = r.nextInt(10) + 10;//2;

while(alength % blength != 0)

alength++;//Making alength divisible by blength

a = new int[alength];

b = new int[blength];

for(int i = 0; i < a.length; i++)

a[i] = r.nextInt(10);

printForward(a);

for(int index = 0; index < a.length; ){

for(int i = 0; i < b.length; i++)

b[i] = a[index+i];

printBackward(b);

index += b.length;

}

}

private static void printBackward(int[] x) {

for(int i = x.length - 1; i >= 0; i--)

System.out.print(x[i] + ", ");

System.out.println();

}

private static void printForward(int[] x) {

for(int i = 0;i < x.length; i++)

System.out.print(x[i] + ", ");

System.out.println();

}

}

Answer:

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions