Code:
#include<stdio.h>
#include<math.h>
int options();
int time_to_swap();
int get_hypote();
int get_sine_form();
int get_euclids (int argc, const char * argv[]);
int mid_point();
#define PI 3.14159265
int main()
{
int four; //fourth function
int second;
char choice; //option to end program
int begin;
int temp;
int five;
int third;
begin = options();
do{
second = mid_point(); //finds midpoint
third = time_to_swap(); //swaps
four = get_hypote(); //find hypotenuse
five = get_sine_form(); //calculates sine of a number
temp = get_euclids (int argc, const char * argv[]); //find the GCD
printf("\n To end this program please enter the letter 'n'.\n");
scanf("%c",&choice);
getchar();
}while(choice != 'n');
}
int options() //prints out what the overall program will do
{
printf("Throughout the program it will perform the following: \n");
printf("1. Linear Algebra.\n");
printf("2. Pointers.\n");
printf("3. Mathematical Functions\n");
printf("4. Statistics.\n");
printf("4. Finding GCD using Euclid's algorithm.\n\n\n");
return 0;
}
int mid_point() //solves midpoint of the coordinates
{
double midx,midy,x1,y1,x2,y2;
printf("Enter x1:\n");
scanf("%lf",x1);
printf("Enter x2:\n");
scanf("%d",x2);
printf("Enter y1:\n");
scanf("%lf",y1);
printf("Enter y1:\n");
scanf("%d",y1);
midx = (x1 + x2) / 2;
midy = (y1 + y2) / 2;
printf("\n");
printf("%d,%d,%d,%d",x1,x2,y1,y2);
printf("%d,%d",midx,midy);;
return 0;
}
/* Part 2-Pointers */ //where swapping three variables take place
int time_to_swap()
{
int x, y, z,temp;
printf("Enter the value of x and y and z\n");
scanf("%d%d%d", &x, &y, &z);
printf("Before Swapping\nx = %d\ny = %d\nz = %d\n",x,y,z);
temp = x;
x = z;
z = y;
y = temp;
printf("After Swapping\nx = %d\ny = %d\nz = %d\n",x,y,z);
return 0;
}
/* Part 3- Mathematical Functions */ //Calculates hypotenuse
int get_hypote()
{
float side1, side2, ansa, hypote;
int i = side1;
printf("\nThis part of the program will calculate the hypotenuse of a right triangle(Part 1 of 3).\n\n");
printf("Enter side one of the triangle:\n");
scanf("%f",&side1); //Asks user for side 1
printf("Enter side two of the triangle:\n");
scanf("%f",&side2); //Asks user for side 2
ansa = (side1 * side1 + side2 * side2);
hypote = sqrt(ansa); //does the square root of ansa
printf("The lenth of the hypotenuse is: %f \n", hypote);
/* Done with part 1 of part 3 */
printf("Part 2 of 3, Uses the given sides and raises one number to the power of the other\n");
printf("%.2f\n", pow(i, side2));
/* Done with part 2 of part 3 */
printf("Part 3 of 3, Uses any number given and places it into the sine formula and calculates answer.\n");
}
int get_sine_form() //calculates the sine formula
{
double degree, answer;
printf("Please enter a degree of your choice:\n");
scanf("%lf",degree);
answer = sin (degree*PI/180);
printf ("The sine of %lf degrees is %lf.\n", degree, answer );
return 0;
}
/* Done with part 3 of part 3 */
/* Part 4- Statistics *****************/
/*Extra Credit Part */
int get_euclids (int argc, const char * argv[])
{
int a, A, b, B, c, d, m, n, q, r = 1, t, x;
printf("This part of the program will help you find the Greatest Common Divisor of two numbers\n"); //calculates the GCD of two given numbers
printf("m = ");
scanf ("%d", &m);
printf("n = ");
scanf ("%d", &n);
printf("\n\nWorking numbers\n\n");
printf("A\t a\t B\t b\t c\t d\t q\t r\n"); //calculating the working numbers that would work for the GCF
printf(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>n");
A = b = 1;
a = B = 0;
c = m;
d = n;
while (r != 0)
{
q = (c / d);
r = (c % d);
printf("%d\t %d\t %d\t %d\t %d\t %d\t %d\t %d\n",
A, a, B, b, c, d, q, r);
x = d;
c = d;
d = r;
t = A;
A = a;
a = (t - (q * a));
t = B;
B = b;
b = (t - (q * b));
}
printf("<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<\n");
printf("From the numbers entered, the GCD of %d and %d is %d\n\n", m, n, x); //shows GCD
return 0
}