Lab 6
Lab 6
Lab 6
Lab 6
Name : Matthew Gomez [Section 1(3:45) ] 2 (12:45)
Spring 2015
Anywhere that I ask you to observe what happens, write down your observations in the space
provided. Before entering code, finish reading the instructions for that part!
Experimenting with functions.
In this lab you will be using 3 functions in several different ways.
Part A) In this section you will need to organize a program with some functions that I am giving
you.
1. Make a c file called Lab6.c. Copy and paste this "program" into Lab6.c
/* Lab6.c*/
#include <stdio.h>
/* function PROTOTYPES go here */
int main()
{
/* declarations */
int m, n, p;
double x, y;
char a;
/* Part B */
/* comment 1 */
/* comment 2 */
/* comment 3 */
/* Part C */
/* comment 4 */
/* comment 5 */
/* comment 6 */
/* Part D */
/* comment 7 */
/* comment 8 */
/* comment 9 */
/* Part E */
return(0);
}
/* function DEFINITIONS go here */
/* print the parameter 5 times. Note, no new line at end.*/
void rewriter(char let)
{
printf("%c%c%c%c%c",let,let,let,let,let);
}
/* triple the number n. Note, no printed output. */
double triple(double n)
{
double answer;
answer = 3.0 * n;
return(answer);
}
/* prints num/div, returns num%div */
int divAndMod(int num, int div)
{
int quotient;
int remainder;
quotient = num / div;
remainder = num % div;
printf("The quotient is %d\n",quotient);
return(remainder);
}
/* end of Lab6.c */
2. The program already contains the function definitions but we need to add the function
prototypes.
Copy the header line of each function definition and paste just below the comment
/* function PROTOTYPES go here */
You will then need to add a semicolon (;).
Example:
void rewriter(char let);
Repeat this for all three functions.
If you did this part correctly, you only had one active function call each time you ran the program.
This let us concentrate on what that function call does. In the next several parts of this lab we will
continue to have only one active function call each time we run a program.
4) Comment out the previous function call.
When the function was assigned a value while being called the variable put out the remainder and
the quotient was stilled displayed simply by calling the function. The functions return also has it set
to display the remainder, which we called by creating the variable for the return.
was the remainder, which is shown in the original function. 23/10= 2R3 and m=3 in the output.
n=23 and p=10 were displayed, because of the printf statement to display their values.
The
The
The
The
quotient is 2
remainder is 3
quotient is 3
remainder is 0
*****$$$$$NNNNN
When I triple some number I get 33.3.
eeeee
ccccc
sssss
Print out your program and hand it in together with this lab packet. Make sure your name
and section number are on the lab.