



Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!




Spring 2008 – Midterm — March 10, 2008
Name:……………………… Score: ……./ Sequence number:………….
int a = 3, b = 6, c = 4;
c = a + -b / 3 - b / sqrt(b + a) + a / 2 * b;
printf("New value of c = %d \n", c);
Step-by- step show how you compute:
output: (^) New value of c = 5
Name:………………
#include <stdio.h>
int main(void) { /* Declare variables. If needed, you can declare more*/ double p1, p2, total;
printf("Enter the original prices of item1 and item2:”); scanf("%lf %lf", &p1, &p2);
/* Compute the total amount including 8% tax Note: 25% off discount is applied to the lowest-cost item */
total = p1 + p2;
if( p1 > p2 ) { total = total - 0.25 * p2; } else { total = total - 0.25 * p1; }
total = total + total * 0.08;
printf("Total = %lf \n", total);
system("pause");
/* Exit program. */ return 0; }
if( p1 > p2 ) { total = p1 + 0.75 * p2; } else { total = p2 + 0.75 * p1; }
n
#include <stdio.h> #include <math.h> int main(void) { /* Declare variables, If needed, you can declare more*/ int i, n; double x, cosx;
double powx, fact;
printf("Enter the value of x and n : "); scanf("%lf %d",&x, &n);
/* Write a loop to compute cosx using the above formula */
cosx=1.0; fact=1.0; powx=1.0;
for(i=1; i<=n; i++){
powx = powx * x * x; / OR powx = pow(x, 2i); /*
fact = fact * (2i-1) * (2i);**
if (i%2==0) cosx = cosx + powx / fact; else cosx = cosx - powx / fact; }
printf("Approximate cosx is %lf when n=%d \n", cosx, n); printf("cos(x) in math lib returns %lf \n”, cos(x));
system("pause"); return 0; /* Exit program. */ }
Name:………………….
For instance, your program should process the following input.txt and generate the corresponding z1z2same.txt and z1z2different.txt as follows:
Here is the logical circuit.
input.txt
z1z2same.txt prog
AND gate
OR gate
NOT gate
1 1 1 0 0 z1z2different.txt