Lab 6 - cps labs PDF

Title Lab 6 - cps labs
Author Salman Noman
Course Computer Science
Institution Ryerson University
Pages 4
File Size 32.5 KB
File Type PDF
Total Downloads 76
Total Views 158

Summary

cps labs...


Description

1.) #include int getnum();

int main() {

int input = 0; printf("Enter a number;", input); scanf("%d", &input);

while (!((input = 10))) { printf("The number entered is out of range, please enter a different number: ");

input = getnum(); }

printf("The number entered is %d", input); return 0; }

int getnum() { int number;

scanf("%d", &number); return (number); } #include

int getnum();

int main() {

int input = 0; printf("Enter a number;", input); scanf("%d", &input);

while (!((input = 10))) { printf("The number entered is out of range, please enter a different number: ");

input = getnum(); }

printf("The number entered is %d", input); return 0; }

int getnum() { int number;

scanf("%d", &number); return (number); }

2.) #include #include int main() { double a, b, c, discrim, rt1, rt2, complexroot, complexcalc; printf("Enter the variables a, b and c: "); scanf("%lf %lf %lf", &a, &b, &c);

discrim = b * b - 4 * a * c;

if (discrim > 0) { rt1 = (-b + sqrt(discrim)) / (2 * a); rt2 = (-b - sqrt(discrim)) / (2 * a); printf("Therefore root 1 = %.2lf and root 2 = %.2lf", rt1, rt2); }

else if (discrim == 0) { rt1 = rt2 = -b / (2 * a); printf("Therefore root1 = root2 = %.2lf;", rt1); }

else { complexroot = -b / (2 * a); complexcalc = sqrt(-discrim) / (2 * a); printf("therefore root1 = %.2lf+%.2lfi and root2 = %.2f-%.2fi", complexroot, complexcalc, complexroot, complexcalc);

}

return 0; }...


Similar Free PDFs