Part 1: Write a C program that takes an integer command line
argument n, spawns n processes that will each generate a random
numbers between -100 and 100, and then computes and prints out the
sum of these random numbers. Each process needs to print out the
random number it generates.
name the program 003_2.c
#include <stdio.h>
#include <stdlib.h>
int randomNumbers(n) //Function to generate and sum the 2 random numbers between -100 and 100 taking "n" as a parameter which will be taken as an input from command line arguement
{
int upper = 100;//upper limit for the rand() function
int lower = -100;//lower limit for the rand() function.
int i;//variable for the "for loop" iterations
if(n==0)//if there are no spawns or the user given value is zero process will be exited
return 0;
for(i=0;i<=n;i++)//for loop to print the random numbers and their sum for number of iterations i.e. spawns given by user
{
int num1 = (rand() % (upper - lower + 1)) + lower;//generating first random number between -100 and 100
printf("Random Number1 for %d iteration : %d\n",i,num1);//Printing the first random number
int num2 = (rand() % (upper - lower + 1)) + lower;//generating second random number between -100 and 100
printf("Random Number2 for %d iteration : %d\n",i,num2);//Printing second random number
printf("Sum of 2 Random Numbers for %d iteration : %d\n",i,num1+num2);//Printing sum of two random numbers
}
}
int main()//main function
{
long int n;
printf("Enter number of spawns :");
scanf("%d",&n);//taking the input from the user through command line
randomNumbers(n);//calling the function randomNumbers() by passing the user input
return 0;
}
Part 1: Write a C program that takes an integer command line argument n, spawns n...
Write a C program called test that takes one command line argument, an integer N. When we run test: ./test N the program will do this: the parent process forks N child processes each child process prints its process ID, exits the parent process waits for all child processes to exit, then exits
Using java write a program that takes a single, positive integer, n as a command-line argument. The program should then plot n evenly spaced points around a circle
How do I write a C program called binary that takes a single command line argument, and integer, in decimal, and prints out the binary representation of the number with 64 bits. The argument must be stored as a long. Use atol to convert the command line argument. Include a function char *binary(long n, char *b) { ... } that stores the binary representation in the string b with '0's and '1's. It is the responsibility of the calling program...
Write Java program that takes an integer N from the command line and creates N by N boolean array a[][] such that a[i][j] is true if i and j are relatively prime (have no common factors) and false otherwise. print the output using * to represent true and a space to represent false and include row and column numbers. (use sieving)
Write a program in C that takes a file name as the only argument on the command line, and prints out the number of 0-bits and 1-bits in the file int main ( int argc , char * argv [] ) { // Check if the user gave an argument , otherwise print " ERROR : no argument " // Check if the file can be read , otherwise print " ERROR : can ’t read " // Otherwise ,...
Write a C++ program that accepts one command line argument which is an integer n between 2 and 4 inclusive. Generate 60 random integers between 1 and 49 inclusive and store them in a 5 by 12 two dimensional integer array (e.g.,int a[5][12];). Use pthread to create n threads to square all 60 array elements. You should divide this update task among the n threads as evenly as possible. Print the array both before and after the update separately as...
Problem: Write a program that behaves as described below.If the first command-line argument after the program name (argv[1]) is “--help”, print the usage information for the program. If that argument is not “--help”, you are to expectargv[1]and subsequent arguments to be real numbers(C, integer, float, or double types)in formats acceptable to the sscanf()function of the C library or strings of ASCII chars that are not readable as real numbers. You are to read the numbers, count them and calculate the...
Write a C or C++ program A6p1.c(pp) that accepts one command line argument which is an integer n between 2 and 6 inclusive. Generate a string of 60 random upper case English characters and store them somewhere (e.g. in a char array). Use pthread to create n threads to convert the string into a complementary string (‘A’<->’Z’, ‘B’<->’Y’, ‘C’<->’X’, etc). You should divide this conversion task among the n threads as evenly as possible. Print out the string both before...
In C write a program that must accept one argument from the command line. The argument is the name of the file containing the processes (for example: processes.csv).This file is comma-separated with three columns (process ID, arrival time and burst time) with each row for an individual process. You can assume that this file will have a maximum of 10 processes. For example Input: processes.csv ProcessID,Arrival Time,Burst Time 0,1,3 1,0,5 2,9,8 3,10,6 Where the first element is processes, the second...
Java!!! Write a program that takes a file name as its command line argument. It assumes the file is a binary data file and checks the first 4 bytes of the file to see whether they contain the integer −889275714. It outputs “yes” or “no” or an error message if there was an IOException generated. (Trivia question: Why test for that particular value? Hint: Try it on several .class files.)