Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

HomewodA.cs109spr2017-1IRest-ontl Competi baky Model Word 3. Write a program tha

ID: 3805501 • Letter: H

Question



HomewodA.cs109spr2017-1IRest-ontl Competi baky Model Word 3. Write a program that can be used to display all the prime numbers between two integers m and n (m must be less than e). In order to do that, you can call a function Labinadintx) which is defined as below.This function retums true (l) or false (0) depending on ifan integer x is prime or not. The function definition of IsPrime is given as below: bool prime true, prime false; Call this function suitably for all integers between m and s and display all the numbers for which this function returns true In the main declare m n, and then get their values as user input Make sure to check they both are positive integers and also n m. Then write a loop starting count m, count -n, countH and inside this loop check if count is a prime, then das play that This will display all the primes between m and

Explanation / Answer

Program 1:

#include <stdio.h>

int checkPrimeNumber(int n);
int main()
{
int n1, n2, i, flag;

printf("Enter two positive integers: ");
scanf("%d %d", &n1, &n2);
printf("Prime numbers between %d and %d are: ", n1, n2);

for(i=n1+1; i<n2; ++i)
{
// i is a prime number, flag will be equal to 1
flag = checkPrimeNumber(i);

if(flag == 1)
printf("%d ",i);
}
return 0;
}

// user-defined function to check prime number
int checkPrimeNumber(int n)
{
int j, flag = 1;

for(j=2; j <= n/2; ++j)
{
if (n%j == 0)
{
flag =0;
break;
}
}
return flag;
}

Program 2:


#include<stdio.h>
void translate(int X,int Y);
void reflecty(int Y,int X);
void reflectx(int X,int Y);
void rotateAntiC(int X,int Y);
void rotateClock(int X,int Y);
void main()
{
int x,y;

printf("Enter X and Y");
scanf("%d",&x);
scanf("%d",&y);

translate(x,y);
reflecty(y,x);
reflectx(x,y);
rotateAntiC(x,y);
rotateClock(x,y);
}
void translate(int x,int y)
{
int a,b;
int m,n;
m=x;
n=y;
  
printf("Enter a and b");
scanf("%d,%d",&a);
scanf("%d",&b);
printf(" Translated values of x and y are %d %d",m+a, n+b);
  
}
void reflecty(int y,int x)
{
int y1,y2;
y1=y;
y1=-y1;
printf(" reflected values of x and y along x-axis are %d %d",x,y1);
}
void reflectx(int x,int y)
{
int x1,x2;
x1=x;
x1=-x1;
printf(" reflected values of x and y along y-axis are %d %d",x1,y);
}

void rotateAntiC(int x,int y)
{
int oldx,oldy;
oldy=y;
y=x;
x=-oldy;
printf(" rotated values of x and y along 90 degress are %d %d",x,y);
}

void rotateClock(int x,int y)
{
int oldx,oldy,newy,newx;
oldy=y;
y=x;
x=oldy;
printf(" rotated values of x and y along 90 degress clockwise are %d %d",x,y);
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote