solutions 2

Upload: irfan-maulana

Post on 07-Oct-2015

5 views

Category:

Documents


0 download

DESCRIPTION

dsddsfsdfdsfdsf

TRANSCRIPT

/*********************** Question 1 source file ********************//* File licenseplate.c Read and write license plates Programmer: Muhammad Irfan Maulana Date: 16/09/2014*/#include #include int main(void){char c1;char c2;char c3;char c4;char c5;char c6;printf("Enter a license plate number (3 letters and 3 digits): ");scanf("%c", &c1);scanf("%c", &c2);scanf("%c", &c3);scanf("%c", &c4);scanf("%c", &c5);scanf("%c", &c6);printf("You entered: %c%c%c%c%c%c", c1, c2, c3, c4, c5, c6);return 0;}/*********************** Question 1 output ************************/Enter a license plate number (3 letters and 3 digits): MYT549You entered: MYT549/*********************** Question 2 source file ********************//* File quadraticfloat.cUse the quadratic formula with float values*/#include #include #include int main(void){float a;float b;float c;float d;float root1;float root2;printf("Enter a value for a: ");scanf("%f", &a);printf("Enter a value for b: ");scanf("%f", &b);printf("Enter a value for c: ");scanf("%f", &c);d = sqrt((b * b) - (4 * a * c));root1 = (-b + d) / (2 * a);root2 = (-b-d) / (2 * a);printf("Value for first root: %f \n", root1);printf("Value for second root: %f", root2);}/*********************** Question 2 output ************************/Enter a value for a: 1.0Enter a value for b: -5.0Enter a value for c: 6.0Value for first root: 3.000000Value for second root: 2.000000Enter a value for a: 1.0Enter a value for b: -10.0001Enter a value for c: 25.0005Value for first root: 5.001431Value for second root: 4.998669/*********************** Question 3 source file ********************//* File quadraticfloat.cUse the quadratic formula with float values*/#include #include #include int main(void){double a;double b;double c;double d;double root1;double root2;printf("Enter a value for a: ");scanf("%e", &a);printf("Enter a value for b: ");scanf("%e", &b);printf("Enter a value for c: ");scanf("%e", &c);d = sqrt((b * b) - (4 * a * c));root1 = (-b + d) / (2 * a);root2 = (-b-d) / (2 * a);printf("Value for first root: %e \n", root1);printf("Value for second root: %e", root2);}/*********************** Question 3 output ************************/Enter a value for a: 1.0Enter a value for b: -5.0Enter a value for c: 6.0Value for first root: 3.000000Value for second root: 2.000000Enter a value for a: 1.0Enter a value for b: -10.0001Enter a value for c: 25.0005Value for first root: 5.000100Value for second root: 5.000000/*********************** Question 4 source file ********************//* File approx.cApproximate the function sqrt(1+x)*/#include #include #include int main(void){float actual;float approx;float x;float error;printf("Enter a value for x: ");scanf("%f", &x);printf("\nx: %f", x);actual = sqrt(1 + x);approx = 1 + ((0.5 * x)) - ((1.0 / 8.0) * (x * x)) + ((1.0 / 16.0) * (x * x * x)) - ((5.0 / 128.0) * (x * x * x * x));error = fabs(((approx - actual) / (actual)) * 100.0);printf("\nApproximate value: %lf", approx);printf("\nActual value: %lf", actual);printf("\nError: %lf", error);return 0;}/*********************** Question 4 output ************************/Enter a value for x: 0.5x: 0.500000Approximate value: 1.224121Actual value: 1.224745Error: 0.050935Enter a value for x: 0.99x: 0.990000Approximate value: 1.395608Actual value: 1.410674Error: 1.067977