Title | Lab 3 - cps labs |
---|---|
Author | Salman Noman |
Course | Computer Science |
Institution | Ryerson University |
Pages | 11 |
File Size | 48.8 KB |
File Type | |
Total Downloads | 84 |
Total Views | 156 |
cps labs...
1.) #include
int main (void) { /* declarations */ double x, y, a, b, d;
/* executable statements */ printf ("Enter four real numbers: "); scanf ("%lf %lf %lf %lf", &x, &y,&a,&b); d = x + y + a + b; printf ("\nThe sum of %lf, %lf, %lf and %lfis %lf.\n", x, y, a, b, d);
return (0); }
2.) #include
int main (void) { /* declarations */ double x, y, a, b, d;
/* executable statements */ printf ("Enter four real numbers: ");
scanf ("%lf %lf %lf %lf", &x, &y,&a,&b); d = (x + y) - (a + b); printf ("\nThe sum of %18.2lf, %18.2lf, %18.2lf and %18.2lf is %18.2lf.\n", x, y, a, b, d);
return (0); } 3.) #include
int main (void) { /* declarations */ double x, y, a, b, d;
/* executable statements */ printf ("Enter four real numbers: "); scanf ("%lf %lf %lf %lf", &x, &y,&a,&b); d = x*x + y*y + a*a + b*b; printf ("\nThe sum of %18.2lf, %18.2lf, %18.2lf and %18.2lf is %18.2lf.\n", x, y, a, b, d);
return (0); } 4.) #include
int main (void) {
/* declarations */ double x, y, a, b, d, v;
/* executable statements */ printf ("Enter four real numbers: "); scanf ("%lf %lf %lf %lf", &x, &y,&a,&b); d = x*x + y*y + a*a + b*b; v= (sqrt(d))/(x+y+a+b); printf ("\nThe sum of %18.2lf, %18.2lf, %18.2lf and %18.2lf is %18.2lf.\n", x, y, a, b,v);
return (0); } 5.) #include #define PI 3.1416
int main (void) { /* declarations */ double x, v;
/* executable statements */ printf ("Enter the radius: "); scanf ("%lf", &x);
v = 0.75 * PI * x;
printf ("\nThe volume of sphere is %3.1lf.\n",v);
return (0); } 6.) #include #define PI 3.1416
int main (void) { /* declarations */ double x, y, v;
/* executable statements */ printf ("Enter two angles: "); scanf ("%lf %lf", &x, &y);
v = 180-(x+y);
printf ("\nThe missing angle is %3.1lf.\n",v);
return (0); }
6.) #include #define PI 3.1416
int
main (void) { /* declarations */ double x, y, v;
/* executable statements */ printf ("Enter two digits: "); scanf ("%lf %lf", &x, &y);
if (x==y) { printf ("the tripled number is.\n", 3*(x+y))
} else { printf ("The sum is.\n", x+y)
}
return (0); }
7
#include
#include
int main (void) { /* declarations */ int x,y,v,d;
/* executable statements */ printf ("Enter two digits: "); scanf ("%lf %lf", &x, &y);
if (x==y) { v=3*(x+y) ; printf ("the tripled number is.\n %ln",v);
} else { d=x+y printf ("The sum is.\n %ln",d);
}
return (0);
}
7.) #include
int main (void) { float h;
printf("\nPut in a floating number: "); scanf("%f", &h);
if (h=0) { printf("\nThe absolute value of %f is: %f", h, h); }
return (0); }
8.) #include #include
#define PI 3.14159265358979323846
int main(void) { int a, r, h;
printf("\nEnter the a value of the cube: "); scanf("%d", &a);
printf("\nEnter the radius and height (in that order) of the Cone: "); scanf("%d%d",&r,&h);
//cube area int CA = 6*a^2; printf("\n The Area of the Cube is: %d", CA);
//cube area int vol = a*a*a; printf("\n The volume of the Cube is: %d", vol);
//cones area float x = PI*r; float y = (sqrt(pow(r, 2)+pow(h, 2))); float CD = x*y; printf("\n The Area of the Cone is: %f", CD);
//cones volume float CV = (1.0/3)*M_PI*pow(r, 2)*h;
printf("\n The Volume of the Cone is: %f", CV);
return (0); } 9.) #include #include
int main(void) { int num1, num2, add, sub, multi, rem; double div; char inp, cent = '%';
printf("\nEnter 2 valid number and one of the following operators (+, -, *, /, %c): ", cent); scanf("%d %d %c", &num1, &num2, &inp);
if(inp=='+') { add =(num1 + num2); printf("%d + %d = %d", num1, num2, add); } else if(inp=='-') //Substraction { sub=(num1 - num2); printf("%d - %d = %d", num1, num2, sub);
} else if(inp=='*') //Multiplication { multi=(num1 * num2); printf("%d * %d = %d", num1, num2, multi); } else if(inp=='/') //Division { div=((double)num1 / (double)num2); printf("%d / %d = %.3f", num1, num2, div); } else if(inp =='%') { rem=(num1 % num2); printf("%d %c %d = %d", num1, cent, num2, rem); } else { printf("\nSorry entry not valid please try again"); }
return(0); }
10.) #include #include #define PI 3.14 int
main(void) { double n; double partial; double sqroot; double n_fact;
//inputing integer printf("\nEnter a positive integer: "); scanf("%lf", &n);
//Calculate for Gosper's Formula partial = (2 * n) + (1 / 3); sqroot = sqrt(partial * PI); n_fact = pow(n,n) * exp(-n) * sqroot; printf("%.0f! equals approximately %.5f \n", n, n_fact);
return(0); }...