Click on "C/C++ Build", you will see this
view, then click on "GCC C Linker->Libraries"
Now on your right you can see two blank area
named "Libraries" and "Library
search Path", click on "+" button for "Libraries" and put "m" in the
poped up
dialog box.
Click "Ok" to save what you have done. Now
you can go ahead and do the lab using math functions such as "fabs".
Print out this page and fill in the blanks to answer the following
questions. Hand in this assignment at the beginning of Lab 8.
You should use the material found in Lecture 12 and 13/14 of the course
notes and/or the course C book Chapters 3.6 , 6.3 & 3.7 -
3.10, 7.5
As with all prelabs/labs, if you are not sure of the answer you may go
to any EWS lab on campus and check your results by using the gcc
compiler, or you can ask anyone of the CS101 staff for help.
The following exercises should help prepare you for the in-lab
activities and MP2.
You will use the C selection statements (if and if-else) along
with C loop statements (while, do-while,for).
#include <stdio.h>
void main(void)
{
int i = 13.99; /* i holds ONLY integer values */
double x;
printf(" %i ", i );
x = 8 / 3; /* 8 and 3 are integers */
printf("%lf ",x);
x = 8 / 3.0; /* 8 is an integer 3.0 is a real (double) */
printf("%lf ",x);
x = 8.0 / 3;
printf("%lf ",x);
x = 8.0/3.0;
printf("%lf ",x);
printf("\n");
}
_______________________________
#include <stdio.h>
void main(void)
{
int x ;
if (5) /* any non-zero value in C means TRUE */
printf("A ");
if (0) /* 0 means FALSE */
printf("B ");
x = 0;
if (x == -1)
printf("C ");
else
if (x != 0) /* != means "not equal" */
printf("D ");
else
printf("E ");
if (x == -1); /* BAD place for a ; as discussed in lecture */
printf("F ");
if (x = 0) /* oops!, forgot == */
printf("G ");
printf("\n");
}
_________________________________________________________________________
The following C program compiles without errors. Write the output produced by this program.
#include
<stdio.h>
void main(void)
{
int x = 5;
int y = 4;
if ((x < 1) || ( y > 3)) /* || means OR */
printf("H ");
if ((x > 4) && (y < 3)) /* && means AND */
printf("I ");
else
printf("J ");
if ( !(x < 2)) /* ! means NOT */
printf("K ");
printf("\n");
}
_________________________________________________________________
#include <stdio.h>
void main(void)
{
int y = 2;
while (y > 0) /* while condition is TRUE execute code in block { } */
{
y = y - 1;
}
printf("y = %i ",y);
printf("\n");
}
_________________________________________________________________________
#include <stdio.h>
void main(void)
{
int y = 2;
while (y > 0) /* how many statements below are part of the while loop? */
y = y - 1;
printf("M ");
printf("\n");
}
_________________________________________________________________________
#include <stdio.h>
void main(void)
{
int y = 3;
while (y > 0) /* how many statements below are part of the while loop? */
{
y = y - 1;
printf("N ");
}
printf("\n");
}
________________________________________________________________________
#include <stdio.h>
void main(void)
{
int i;
for(i=0; i < 3; i=i+1)
{
printf("%i ",i);
}
printf("\n");
}
_______________________________________________________________________
#include <stdio.h>
void main(void)
{
int i;
for(i=0; i < 4; i=(2*i)+1)
{
printf("%i ",i);
}
printf("\n");
}
_____________________________________________________________
int a=2;
int b=8;
while(1) /* 0 means False any other value means True */
{
if(a > b)
break; /* the break statement "breaks out" of loops and switch statements */
if (a == 100)
a = 1;
else /* else matches with the closest if (unless {} are used) */
b = b - 1;
}
#include <stdio.h>
void main(void)
{
int i = -1;
do
{
printf("%i ",i);
i = i - 2;
} while( i > 0);
printf("\n");
}
____________________________________________________________
0 2 4 6 8 ... 100
int i;
for(i = 0; _____________________; ________________)
{
printf("%i ", ___________________ );
}