0% found this document useful (0 votes)
2 views6 pages

Lab 6-Variables, Format Identifiers and Math Functions

Lab 6 focuses on practicing variables, arithmetic operations, formatted placeholders, and math functions in C programming. It consists of two parts: the first part includes practice exercises and the second part consists of assignments that must be submitted by the due date. Students are required to correct code errors, document their work, and follow specific submission guidelines.

Uploaded by

Akalugo Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views6 pages

Lab 6-Variables, Format Identifiers and Math Functions

Lab 6 focuses on practicing variables, arithmetic operations, formatted placeholders, and math functions in C programming. It consists of two parts: the first part includes practice exercises and the second part consists of assignments that must be submitted by the due date. Students are required to correct code errors, document their work, and follow specific submission guidelines.

Uploaded by

Akalugo Daniel
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

LAB 6: C PROGRAMMING LAB

VARIABLE, FORMAT IDENTIFIERS AND MATH


FUNCTIONS

ABOUT LAB 6

Objective: In this lab, we practice variables, arithmetic operations, and formatted


placeholders. Also we will work on math functions. It is strongly recommended to keep
look over the lectures while working on the lab. Practice part is very important!

Lab Description: This lab has two parts: part 1 has some codes and examples to
practice. Part 2 includes Assignments that students should work on and submit the
report by the due date.

Note 1: Your name must be on top of every single code, printed in the code.

Note 2: If the test case given, do not hardcode values, and your screenshot should be
based on the test case only!

Note 3: You should provide comments for your code.

Submission: Students must submit the lab report for Part2- Assignments (A1-A4) as a
Word doc (based on the instruction in file InstructionsforLabsByfarnazDerakhshan.pdf).
Please double check all the items, before submitting the report and make sure to not miss
the due date, late submissions will not be accepted.

1|Page
PART 1- PRACTICE AND LEARN:

P1-

Complete the code, correct it and run the program, how many issues you have found?

incld<stio.h

Int Main
Int var;
printf(HUMBER is my second home /n ”)
Printf(How old are you??\n)
Scanf(: %d”, var1;
Printf( %d Var); Return(0)

P2-

We have a C program that has variables with the following values:


int a,b , c,d ;
double w, x, y ,z ;
a=8 ; b=6 ; c=2 ; d=10 ; w=4.5 ; x=-5.0 ;y=5.5 ; z=1.0 ;
printf ("%-4d", 5-c/d);
printf ("%6.3lf", y/z);
printf ("%4.3lf", z+a*3+z);
printf ("%7.2lf", d/z-2);
printf ("%5.3lf", d-1/z*c);
printf ("%07d", 8+a%b);
printf ("4%09d", a/(int)w);
printf ("%5.2lf\n", x/a);
printf ("%4d*$*$\n", 8-c/a);
printf ("%4.2lf\n", z+a*2+z/a+4);
printf ("%7.2lf\n", d/z);
printf ("%-5d\n", 7+a%b);
printf ("b/(int)-x\n");
printf ("%4d\n", b%a-a+c+1);
printf ("%3d%1d%3.1lf\n", c,d,w);
printf ("%6.1lf\n", w+-x*c/z);

2|Page
printf ("%5.2lf\n", (double)a/b);
printf ("%5.2lf\n", (double)b/a);

Write down your expected output before running the code, then compare your expected
output with the observed outputs. Indicate spaces (blanks) with the pound character #. For
example, printf ("%2d", c); is #1
P3-

You can calculate the squre root of a number using the function call
Z = sqrt(m). The sqrt() function is also defined in the math.h header file. The result of
this calculation will be double.
Example: Calculate and print the square root of 9 and 15.

3|Page
PART 2- ASSIGNMENTS

A1

Write a program that calculates the sum of two integers.


o DECLARE THE VARIABLES!
o The first integer n1. The second integer m1. keep the names the same as it is given
here.
o Get two integer values from the user, (scan the values, i.e., prompt the user and read
values from user input).
o Find the addition of two given values by user and place it in another variable which you
call it as sum1.
o The addition will look as follows:
sum1 = n1 + m1; //write comments beside each single code
o Print the sum1 with a default place holder and then also formatted placeholder which
accepts at least 8 spaces.
TEST CASE:
n1=2 and m1= 3, print the result as follows on the screen:
The first value is 2 + the second value is 3 makes the sum which is 5.
// This is an example of what your output should look like, when you scan n1 with 2 and scan
m1 with 3.
//Do not hardcode values, it means scan the values and not initial the variables inside the code.

A2

I- Complete the code, in here there are errors, you should fix the errors line by line, and add
the error in your report.
For each line in your report, you should add the original line of the code here, and then write
down the missing parts, or mistakes, by adding #1, #2, numbering format. Do not use the same
numbers, and each number is unique for an error, and by the end, the last # shows the whole
number of errors on this code.
Example:
Include <stdio. #1- I should be lower case for include

4|Page
II- After finishing all the errors, then copy the code, and then complete the code, correct it
(debug it), and run the program, take a screenshot for the report.
III- Based on the following given test case, take the last screenshot for the report.

Test case, and entered values from the keyboard (users’ input):
num1=900 num2=99 value100=100 numb200= -2

includ<stdio.h
int main
{ INT num1;num2, sum
Double Value100, numb200, product printf(\n“This
is a practice to learn variables\n ”);

pritf(“Enter values for num1 and num2”\n\n )

Scanf; (“ %d %d”, &num1, Num2)

printf( ; you entered these values “)

Print( “ num1: %d num2:%d “, Num1, num2);

Sum=Num1+num2;

/* in here add a line of code which prints the value of sum*/

Pritf(“Enter values for value100 and numb200”\n\n )

scanf (“ %lf %lf”, Value100, &numb200)

Printf( ; you entered these values “)

print( “ value100: % numb200:% “, value100 ; numb200);

product= value100* numb200;

/* in here add a line of code which prints the value of product*/

Retur(0);;

5|Page
A3

Write a program use the given codes in your program, then run it. The \t is the Escape
Sequence that tabs the output several spaces.

A4

In this question you should code only one single program.


The area of a circle is given by the formula Pi R2 .
You should use the math functions in this code. Use <math.h> library. Math functions’ results
will be double.
o Calculate the area of a circle with a radius 1.1 initiated in the code and show the area with a
default placeholder.
o Then, calculate it with a given value entered by the user for the radius and show the area
with 3 decimal digits.
Set Pi to be equal to 3.14159 with constant micro. Use this code
#define PI_NUM 3.14159

Test Case: The user input is 4.567

6|Page

You might also like