Lab # 1

© Manzur Ashraf

 

Objective:

Learn the Problem Solving and Basics C Language

 

Scope:

The student should know the following:

       1.         Problem Solving

      2.         Declaring Variables

      3.         Standard Input and Output

      4.         Writing Complete Programs

 

Useful Concepts :

 

An useful  List of basic data type of C , number of bytes used to store these data types in memory of computer system  and conversion specifiers used in printf() and scanf() for handling data types is given below :

 

Data Type

Bytes

Format(Conversion Specifier Used)

Signed char

1

% c

unsigned char

1

% c

sort signed int

2

% d

short unsigned int

2

% u

song signed int

4

% ld

long unsigned int

4

% lu

float

4

% f

double

8

% lf

long double

10

% Lf

 

 

 

Discussion:

A sample application will be discussed.

 

 

 

 

Exercises:

1.      Write a program to compute area and circumference of a circle.

2.      Write a program converts a temperature from Celsius to Fahrenheit. Use the following formula:  F = 1.8 x C + 32

 

 

Evaluation:

Your grade will depend on your active participation and seriousness during the lab.

Home Work#1

 

  1. Write a  well documented program to find roots of an quadratic equation.
  2. Solve following problems :

  (i) Write program to take a depth (in kilometers) inside the Earth as input data; compute and print the temperature at this depth in degree Celsius and degrees Fahrenheit

(ii) The Pythagorean theorem states that the sum of the squares  of the sides of a right triangle is equal to the square of the hypotenuse. For example. if two sides of a right triangle have lengths of 3 and 4, then the hypotenuse must have a length of 5. Together the integers 3,4, and 5 from a Pythagorean triple. There are infinite number of such triples. Given two positive integers, m and n, where m>n, a Pythagorean triple can be generated by the following formulas:

 

side1=m*m-n*n;

side2-2*m*n;

hypotenuse=m*m + n*n;

 

The triple (3,4,5) is generated by this formula when m=2  and n=1.

 

Write a program that takes values of m and n as input and displays the values of the Pythagorean triple generated by the

preceding formulas.

 

(iii) Write a program that prompts the user for the Cartesian coordinates of two  points (x1, y1) and (x2, y2) and displays the distance between them.

Note:

·        Late submission of home work is not accepted.

·        In case of copying your grades will deducted.

·        Submit well documented printout ( hard copy with output) in next lab.