

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Material Type: Lab; Class: Introduction to Computer Programming; Subject: Computational Science; University: Syracuse University; Term: Unknown 1989;
Typology: Lab Reports
1 / 2
This page cannot be seen from the preview
Don't miss anything!


Todayโs lab has us playing with functions.
Problem 0:
Given the following function declarations give the return type and list the parameters:
(1) void f u n c t i o n ( ) ;
Return type:
Parameters:
(2) int f u n c t i o n 1 ( ) ;
Return type:
Parameters:
(3) f l o a t f u n c t i o n 2 ( int number ) ;
Return type:
Parameters:
(4) f l o a t f u n c t i o n 3 ( int number , double doub , char c ) ;
Return type:
Parameters:
Problem 1: Write a program that has two functions: odd even The return type of the functions should be void and both should take a single int as a parameter. Function odd should display a message only if the number that was passed in as a parameter is odd. Function even should only display a message if the number was odd. Your program should accept an integer, n, from the user via scanf and then count up to n from 1 calling both functions on each number (use a loop). Problem 2: Write a program that accepts a quadratic formula from the user one term at a time. Your program should have the following functions: f l o a t pow ( f l o a t x , f l o a t y ) ; Consider using a loop to compute pow. Remember that x^0 = 1. f l o a t evaluateTerm ( f l o a t x ) ; This function will prompt the user for the coefficient and expo- nent of the term in this polynomial. The function will use the value of x passed in as a parameter to evaluate this term and then return the resulting value to evaluateExpression (where it was called from). e v a l u a t e E x p r e s s i o n ( ) ; This function prompts the user for the value of x and contin- uously loops calling evaluteTerm. The user is done entering in data when they have entered an exponent of 0. Use a global variable to keep track of whether or not the user has entered
CPS 196: Introduction to C (Summer 2009) Page 1
in 0 for the exponent. Update this variable from evaluate term and check its value in evaluateExpression(). All main has to do is call evaluateExpression(); The program should work as follows: Sample display
โโโโโโโโโโโโโ What value of x should I use: 5 What is the coefficient for this term: 1 What is the exponent for this term: 2 What is the coefficient for this term: - What is the exponent for this term: 1 What is the coefficient for this term: 12 What is the exponent for this term: 0 Your result is : 22
โโโโโโโโโโโโโ
The user entered the following expression: 1 x^2 โ 3 x + 12
Evaluating this expression at 5 we get:
1 ยท 52 โ 3 ยท 5 + 12 25 โ 15 + 12 = 22
CPS 196: Introduction to C (Summer 2009) Page 2