HomewodA.cs109spr2017-1IRest-ontl Competi baky Model Word 3. Write a program tha
ID: 3805501 • Letter: H
Question
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);
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.