First of all lets number the code statements
public static boolean primeCheck(int num)
{
1 int temp;
2 boolean isPrime = true;
3,4,9 for (int i=2; i<=num/2 ; i++)
//for for loop 3 is for intializer statement
//int i=2; 4 for checking condition and at end 9 for i++
{
5 temp=num%i;
6 if(temp==0)
{
7 isPrime = false;
8 break;
}
}
10 return isPrime;
}
Code statements are numbered from 1-8 now lets create
control flow graph(CFG) of the code statement.

public static boolean primeCheck (int num) int temp; boolean isPrime-true: for(int i-2;i<=num/ 2 ; i++) temp-numsi...
Code to be written in Java public static boolean isPrime(int n) Checks whether the parameter integer n is a prime number. For this lab, it is sufficient to use the primality test algorithm that simply loops through all potential integer factors up to the square root of n and stops as soon as it finds one factor. (If an integer has any nontrivial factors, at least one of these factors has to be less than or equal to its square...
Consider the following function bubbleSort. int bubbleSort(int num[], int numel) { int i, j, temp, moves = 0; for (i = 0; i < (numel - 1); i++) { for (j = 1; j < numel; j++) { //missing code } } } A. Complete the missing code:- (4 Points) B. Assume that the array sort[] which has 8 elements, initially contains the values:- 22 5 67 98 45 32 101 99...
Given the following function: int fun1(int count){ int Num ; for (i = 0; i < count; ++i) { cin >> Value; if (i == 0) Num = Value; else if (Value > Num) Num = Value; } return Num ; } What is the output of the following C++ code segment if the following list is entered? (Input list: 5 -15 -90 -2 -60 -30) int Num = 0 , Value, numValues; cin >> numValues; if (numValues > 0) cout...
I am given an input file, P1input.txt and I have to write code to find the min and max, as well as prime and perfect numbers from the input file. P1input.txt contains a hundred integers. Why doesn't my code compile properly to show me all the numbers? It just stops and displays usage: C:\> java Project1 P1input.txt 1 30 import java.io.*; // BufferedReader import java.util.*; // Scanner to read from a text file public class Project1 { public static...
C programm , ´hello i need your help -Given the C program primes.c with the following main method: int main() { int num, res; char buffer[11]; bool finished = false; while (!finished) { printf("Enter n > 0 or quit\n"); scanf("%10s", buffer); if (strcmp(buffer, "quit") == 0) { finished = true; } else { // Convert input to number and compute n-th prime num = atoi(buffer); if (num > 0) { res = nth_prime(num); printf("Prime #%d is %d\n", num, res); }...
I am using python3.6 and i am getting an error on line 42 num = int(fin.readline()) #reading first value valueError: invalid literal, for int() with base 10 Any help is appreciated, here is the code. reads from txt file a few integers in an array and sorts them. thank you! # Function to do insertion sort def insertionSort(arr): # Traverse through 1 to len(arr) for i in range(1, len(arr)): key = arr[i] # Move elements of...
I am getting an error that the variable num was not declared in the scope on the line of code that has; while(num != 5). Do you know how to fixe this error? #include <iostream> #include <iomanip> #include <string> #include<fstream> #include <cstring> using namespace std; //Declare the structure struct Games { string visit_team; int home_score; int visit_score; }; // Function prototypes int readData(Games *&stats); int menu(); void pickGame(Games *&stats, int size); void inputValid (Games *&stats, int size); void homeTotal(Games *&stats,...
Please help me ONLY for the second method : public
static int[] runningGroups(String[] inputFileNames) throws
IOException.
The second method has an "array of files as a parameter". and
return int [ ]. Each element of the return array is the number of
group that can get from the first method.
I got an error Exception in thread "main"
java.lang.NullPointerException
Here my code:
import java.io.*;
import java.util.ArrayList;
import java.util.Scanner;
public class RunningGroups {
public static void main(String[] args) throws IOException...
Recursion Exercises These exercises provide practice with recursion in Java. Objectives Module: To write recursive solutions for basic problems that require iteration. To identify and address base cases in a recursive method. Reminders during development Each of your solutions to the problems below should be in their own method. If a method header is provided for a problem, then your solution should have that exact method header. Any changes to the method header will receive a zero for that problem....