convert or translate this Java Code to ( C PROGRAMMING)(STDIO.H)     //import java util class import java.util.*; //import staement to import ThreadLocalRandom class import java.util.concurrent.ThreadLocalRandom;   //main class public class Main {     //main method             public static void main(String[] args) {                 //create a scanner class object                 Scanner sc = new Scanner(System.in);                 //declaring an integer variables                 int userInput = 0, i;                                 // create an array with a size of 10 elements         int[] IntArray = new int[10];           //initiating random class         ThreadLocalRandom NumRandom = ThreadLocalRandom.current();                 //using for loop to store the value in array created by random class         for(i = 0; i < 10; i++)         {             //assigning random values to array             IntArray[i] = NumRandom.nextInt(1, 31);         }                 //Display output Message:                 System.out.println("Please Enter your Choice");                                 /**while loop to continuos run the loop                 ***until user press 4.                 ***4 is to exit the program.*/                 while(userInput != 4)                 {                     //propmt user to enter the choice                     System.out.println("1: Enter 1 to see all array element.");                     System.out.println("2: Enter 2 to see all elemnts of an array less than 25.");                     System.out.println("3: Enter 3 to see all elemnts of an array greater than or equal to 25.");                     System.out.println("4: Enter 4 to exit.");                                         //getting input choice of user                     userInput = sc.nextInt();                     //switch statement                     switch(userInput)                     {                         //case 1 is used to display all the elements of the array.                         case 1:                             System.out.println("Random Generated Array's elements are: ");                             for(i = 0; i < 10; i++)                             {                                 //display the array elements                                 System.out.print(IntArray[i] + " ");                             }                             //for next line                             System.out.println();                             break;                                                 //case 2 is used to display all the elements of an array less than 25.                         case 2:                             System.out.println("Display element of array less than 25");                             for(i = 0; i < 10; i++)                             {                                 if(IntArray[i] < 25)                                 //display the array elements                                 System.out.print(IntArray[i] + " ");                             }                             //for next line                             System.out.println();                             break;                                                 //case 3 is used to display all the elements of an array greater than or equal to 25.                         case 3:                             System.out.println("Display element of array greater than or equal to 25");                             for(i = 0; i < 10; i++)                             {                                 if(IntArray[i] >= 25)                                 //display the array elements                                 System.out.print(IntArray[i] + " ");                             }                             //for next line                             System.out.println();                             break;                         //end program                         case 4:                             break;                        //when user not enter correct choice                         default:                             System.out.println("Please enter the correct choice.");                      }                   }                             } }

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

convert or translate this Java Code to ( C PROGRAMMING)(STDIO.H)

 

 

//import java util class

import java.util.*;

//import staement to import ThreadLocalRandom class

import java.util.concurrent.ThreadLocalRandom;

 

//main class

public class Main

{

    //main method

            public static void main(String[] args) {

                //create a scanner class object

                Scanner sc = new Scanner(System.in);

                //declaring an integer variables

                int userInput = 0, i;

               

                // create an array with a size of 10 elements

        int[] IntArray = new int[10];

 

        //initiating random class

        ThreadLocalRandom NumRandom = ThreadLocalRandom.current();

       

        //using for loop to store the value in array created by random class

        for(i = 0; i < 10; i++)

        {

            //assigning random values to array

            IntArray[i] = NumRandom.nextInt(1, 31);

        }

       

        //Display output Message:

                System.out.println("Please Enter your Choice");

               

                /**while loop to continuos run the loop

                ***until user press 4.

                ***4 is to exit the program.*/

                while(userInput != 4)

                {

                    //propmt user to enter the choice

                    System.out.println("1: Enter 1 to see all array element.");

                    System.out.println("2: Enter 2 to see all elemnts of an array less than 25.");

                    System.out.println("3: Enter 3 to see all elemnts of an array greater than or equal to 25.");

                    System.out.println("4: Enter 4 to exit.");

                   

                    //getting input choice of user

                    userInput = sc.nextInt();

                    //switch statement

                    switch(userInput)

                    {

                        //case 1 is used to display all the elements of the array.

                        case 1:

                            System.out.println("Random Generated Array's elements are: ");

                            for(i = 0; i < 10; i++)

                            {

                                //display the array elements

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

                            }

                            //for next line

                            System.out.println();

                            break;

                       

                        //case 2 is used to display all the elements of an array less than 25.

                        case 2:

                            System.out.println("Display element of array less than 25");

                            for(i = 0; i < 10; i++)

                            {

                                if(IntArray[i] < 25)

                                //display the array elements

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

                            }

                            //for next line

                            System.out.println();

                            break;

                       

                        //case 3 is used to display all the elements of an array greater than or equal to 25.

                        case 3:

                            System.out.println("Display element of array greater than or equal to 25");

                            for(i = 0; i < 10; i++)

                            {

                                if(IntArray[i] >= 25)

                                //display the array elements

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

                            }

                            //for next line

                            System.out.println();

                            break;

                        //end program

                        case 4:

                            break;

                       //when user not enter correct choice

                        default:

                            System.out.println("Please enter the correct choice.");

                     }

 

                }

               

            }

}

 

Expert Solution
Step 1
  • The code is given in java programming language.
  • The code given below is converted or translate to C programming.
Step 2

#include <stdio.h>

#include<stdlib.h>

int main()

{  

    //int *IntArray= new int[10];

    int arr[10],userInput=0;

    for(int i=0;i<10;i++)

       arr[i]=rand()%10;

   

    printf("Please enter your choice\n");

   

    while (userInput!=4){

    printf("1: Enter 1 to see all the elements\n");  

    printf("2: Enter 2 to see all elemnts of an array less than 25.\n");

    printf("3: Enter 3 to see all elemnts of an array greater than or equal to 25.\n");

    printf("4: Enter 4 to exit.\n");

   

      //getting input choice of user

 

                    scanf("%d",&userInput);

 

                    //switch statement

 

                    switch(userInput)

 

                    {

 

                        //case 1 is used to display all the elements of the array.

 

                        case 1:

 

                            printf("Random Generated Array's elements are: \n");

 

                            for(int i = 0; i < 10; i++)

 

                            {

 

                                //display the array elements

 

                                printf("%d",arr[i]);

                                printf(" ");

 

                            }

 

                            //for next line

 

                            printf("\n");

 

                            break;

 

                      

 

                        //case 2 is used to display all the elements of an array less than 25.

 

                        case 2:

 

                            printf("Display element of array less than 25\n");

 

                            for(int i = 0; i < 10; i++)

 

                            {

 

                                if(arr[i] < 25)

 

                                //display the array elements

 

                                printf("%d",arr[i]);

                                printf(" ");

 

                            }

 

                            //for next line

 

                            printf("\n");

 

                            break;

 

                      

 

                        //case 3 is used to display all the elements of an array greater than or equal to 25.

 

                        case 3:

 

                            printf("Display element of array greater than or equal to 25\n");

 

                            for(int i = 0; i < 10; i++)

 

                            {

 

                                if(arr[i] >= 25)

 

                                //display the array elements

 

                                printf("%d",arr[i]);

                                printf(" ");

 

                            }

 

                            //for next line

 

                            printf("\n");

 

                            break;

 

                        //end program

 

                        case 4:

 

                            break;

 

                       //when user not enter correct choice

 

                        default:

 

                            printf("Please enter the correct choice.\n");

 

                     }

 

 

 

                }

 

               

 

           

 

 

 

       

   

      

    //printf("%d",rand()%32);

 

    return 0;

}

 

steps

Step by step

Solved in 3 steps with 1 images

Blurred answer
Knowledge Booster
Computational Systems
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education