Sunday, January 20, 2013
Saturday, January 19, 2013
CZ1007 Soln To lab1
Q1. #include stdio .h int main() { float celsiusTemp, fahrenheitTemp; printf("Enter the temperature in degree F: "); scanf("%f", &fahrenheitTemp); celsiusTemp = (fahrenheitTemp - 32)*5/9; printf("Converted degree in C: %f", celsiusTemp); return 0; }
**************************************************************************Q2. #include stdio .h #define _USE_MATH_DEFINES #include math .h main() { double radius, height, volume, surfaceArea; printf("Enter the radius: "); scanf("%lf", &radius); printf("Enter the height: "); scanf("%lf", &height); volume = M_PI * radius * radius * height; surfaceArea = 2*M_PI * radius * height + 2 * M_PI * radius * radius; printf("The volume is: %f \n", volume); printf("The surface area is: %f", surfaceArea); return 0; }
***************************************************************************Q3. #include stdio .h int main() { float a1, b1, c1, a2, b2, c2, x, y, ans; printf("Enter the values for a1, b1, c1, a2, b2, c2: "); scanf("%f %f %f %f %f %f", &a1, &b1, &c1, &a2, &b2, &c2); if (a1*b2-a2*b1 != 0) { x = (b2 * c1 - b1 * c2)/ (a1 * b2 - a2 * b1); y = (a1 * c2 - a2 * c1)/ (a1 * b2 - a2 * b1); printf("x = %f and y = %f", x, y); } else { printf("Invalid inputs"); } return 0; }
******************************************************************************Q4. #include stdio .h #define _USE_MATH_DEFINES #include math .h int main() { float x1, y1, x2, y2, distance; printf("Enter the first point x1 y1: "); scanf("%f %f", &x1, &y1); printf("Enter the second point x2 y2: "); scanf("%f %f", &x2, &y2); distance = sqrt((x1-x2) * (x1 - x2) + (y1 - y2) * (y1-y2)); printf("The distance is %f", distance); return 0; }
*****************************************************************************