I need a C program for the following which I cannot figure out. 3. In mathematic
ID: 3800675 • Letter: I
Question
I need a C program for the following which I cannot figure out. 3. In mathematics, two prime numbers are considered sexy if they have a difference of 6 ("sex" is the Latin word for "six."). In other words, pairs of primes of the form (p, p 6). Given two integer numbers, write a C program to determine if the numbers are both prime and have a difference of 6. Input the smaller number fist. Check for positive values 1-30000. A user-defined function must be used. Do not list out all the sexy numbers-the values must be algorithmically calculated. Refer to the sample output below. Sample Runs (2): Enter two numbers (1-30000) 2 8 The numbers are not sexy primes. Enter two numbers (1-30000) 641 647 The numbers are sexy primes.Explanation / Answer
Here is the code to check.
#include <stdio.h>
int main()
{
int first, second, subtract;
int flag,flag2,i = 0;
printf("Enter two numbers 1-30000 ");
scanf("%d%d", &first, &second);
for(i=2; i<=first/2; ++i)
{
// condition for nonprime number
if(first%i==0)
{
flag=1;
break;
}
}
for(i=2; i<=second/2; ++i)
{
// condition for nonprime number
if(second%i==0)
{
flag2=1;
break;
}
}
if (flag2==0 && flag ==0)
{
subtract = second - first;
if(subtract == 6){
printf("The numbers are sexy primes.");
}
else{
printf("The numbers are not sexy primes.");
}
}
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.