#include <unistd.h>
#include <poll.h>
#include <stdio.h>
#include <stdlib.h>
int main()
{
int total;
int randnumber()
{
int fnumber,snumber,tnumber;
fnumber = rand()%10;
snumber = rand()%10;
tnumber = rand()%10;
printf("First number: %d\nSecond Number: %d\nThird number%d\n", fnumber,snumber,tnumber);
printf("enter the total of 3 number in 10 seconds\n");
return fnumber+snumber+tnumber;
}
int answer=randnumber();
struct pollfd mypoll = { STDIN_FILENO, POLLIN|POLLPRI };
if( poll(&mypoll, 1, 10000) )
{
scanf("%d", &total);
if(total==answer){
printf("correct answer - %d\n", total);
}
else{
printf("you have entered incorrect answer, try again\n");
if( poll(&mypoll, 1, 5000) )
{
scanf("%d",&total);
if(total==answer){
printf("correct answer - %d\n", total);
}
else {
printf("You have tried two attempts and both got wrong.\ncorrect answer is %d",answer);
}
}
else{
printf("Too slow response\n");
}
}
}
else
{
printf("Too slow response\n");
}
return 0;
}
output:
cc version 4.6.3 First number: 3 Second Number: 6 Third number7 enter the total of 3 number in 10 seconds 6 you have entered incorrect answer, try again 16 correct answer - 16
output2
gcc version 4.6.3 First number: 3 Second Number: 6 Third number7 enter the total of 3 number in 10 seconds Too slow response
output3:
gcc version 4.6.3 First number: 3 Second Number: 6 Third number7 enter the total of 3 number in 10 seconds 16 correct answer - 16
output4:
First number: 3 Second Number: 6 Third number7 enter the total of 3 number in 10 seconds 5 you have entered incorrect answer, try again 5 You have tried two attempts and both got wrong. correct answer is 16
in c Q3) Write a program to generate three random numbers between 1 and 9 and...
06) Write a C program to perform matrix operations based of threads. The program accepts from the user a positive integer N. A menu is given to the user: 1. generate matrices: generates three NxN matrices A, B, C with random integer numbers between 0 and 9 2. add: matrix D- A+B+C 3. subtract: matrix D A-B-C 4. display matrices: A, B, C, D 5. display count of result values more than 8. 6. exit: terminate the program When the...
Questions: 1) Write a simple program to create three processes using fork() commands. Use any three of the six system calls to show how each child process executes new sub-programs using exec’s minions. Show the output of each of the child process with different data samples. 2) Write a simple program in your Linux environment using C++ to identify PID, PPID and GID for the processes created in Question 1 and display the real and effective user ID. 3) Modify...
Write a C program that should run on Linux platform using gcc compiler. You are required to simulate threads creation and termination behavior by using POSIX threads library. Input: In the main program, first take the value for total number of threads and then ask user to provide the arrival time and CPU time (i.e. running time) for each thread. Output: Simulate the behavior of threads arrival, working and termination at a specific time interval (i.e. 500ms). Requirements: i. Name...
(c++) Write a program that generates a random number between 1 and 100 and asks the user to guess what the number is. If the user’s guess is higher than the random number, the program should display “Too high, try again.” If the user’s guess is lower than the random number, the program should display “Too low, try again.” The program should use a loop that repeats until the user correctly guesses the random number. Be sure that your program...
To write a C program (not C++) that converts numbers between Decimal and IEEE-754 format and vice versa. Inputs: Number in Decimal format (including special case of 0) Number in IEEE-754 format (including special cases) Output: Equivalent number in IEEE-754 format Equivalent number in Decimal Specification: The program converts a number based on choosing from a menu of choices, where each choice calls the appropriate procedure, where the choices are: Decimal to IEEE-754 conversion IEEE-754 to Decimal conversion Quit program...