Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

write a c code using onlinegdb.com, and the following code that I started please help me get the required output. Please show proof of SCREENSHOTS

write a c code using onlinegdb.com, and the following code that I started please help me get the required output. Please show proof of SCREENSHOTS of the OUTPUT working!
#include
#include
#include
#include
#include
volatile int largest_prime =2;
volatile int quit_flag =0;
// Function to check if a number is prime
int is_prime(int num){
if (num =1) return 0;
if (num =3) return 1;
if (num %2==0|| num %3==0) return 0;
for (int i =5; i * i = num; i +=6){
if (num % i ==0|| num %(i +2)==0) return 0;
}
return 1;
}
// Signal handler for SIGINT
void handle_sigint(int sig){
printf("
%d Quit [y/n]?", largest_prime);
char choice;
struct termios oldt, newt;
tcgetattr(STDIN_FILENO, &oldt);
newt = oldt;
newt.c_lflag &= ~(ICANON | ECHO);
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
choice = getchar();
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
if (choice =='y'|| choice =='Y'){
quit_flag =1;
}
}
// Main function
int main(){
signal(SIGINT, handle_sigint);
int num =2;
while (!quit_flag){
if (is_prime(num)){
largest_prime = num;
}
num++;
}
printf("
");
return 0;
}
image text in transcribed

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

Introduction To Data Mining

Authors: Pang Ning Tan, Michael Steinbach, Vipin Kumar

1st Edition

321321367, 978-0321321367

More Books

Students also viewed these Databases questions

Question

Do you remember who said And away we go?

Answered: 1 week ago