0% found this document useful (0 votes)
11 views5 pages

Lab 1

Uploaded by

mahmudereza43024
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)
11 views5 pages

Lab 1

Uploaded by

mahmudereza43024
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/ 5

“Heaven’s Light is Our Guide”

Department of Computer Science & Engineering

RAJSHAHI UNIVERSITY OF ENGINEERING & TECHNOLOGY

Lab Manual

Programming in C

Lab 1

Fundamental of Programming

Index

Lab Objectives

Background

Some Examples

Exercises
Lab Objectives:
 Explain the component of a Program code,

 To study about the pre processor library, data type, identifiers and operators,

 Design a good programming style.

Background:
The types of header files:

Header File Explanation

<stdio.h> Contains functions prototypes for the standard input output library function
and the information to use them

<stdlib.h> Contains function prototypes for conversions of numbers to text and text to
numbers, memory allocation, random number, and other utility functions

<string.h> Contains function prototypes for string processing functions

<time.h> Contains function prototypes and types for manipulating the time and date

<math.h> Contains function prototypes for math library functions

Some basic Data types used in C:

Name Description Size* Range*


signed: -128 to 127
char Character or small integer. 1byte
unsigned: 0 to 255
short int signed: -32768 to 32767
Short Integer. 2bytes
(short) unsigned: 0 to 65535
signed: -2147483648 to
int Integer. 4bytes 2147483647
unsigned: 0 to 4294967295
signed: -2147483648 to
long int
Long integer. 4bytes 2147483647
(long)
unsigned: 0 to 4294967295
Boolean value. It can take one of two values:
bool 1byte true or false
true or false.
float Floating point number. 4bytes +/- 3.4e +/- 38 (~7 digits)
double Double precision floating point number. 8bytes +/- 1.7e +/- 308 (~15 digits)
long double Long double precision floating point number. 10bytes +/- 1.7e +/- 4932 (~19 digits)
Some Examples:
1. Write a program that prints “Hello World”.
Program Code:
#include<stdio.h>
int main()
{
printf("Hello World ");
return 0;
}

2. Write a program that read an integer/ floating point/ long number and display
that number.
Program Code:
#include<stdio.h>
int main()
{
int i;
float f;
double d;
long l;
//for integer number
printf("Enter a integer: ");
scanf("%d",&i);
printf("\n your integer is %d ",i);
//for floating point
printf("\nEnter a floating point number: ");
scanf("%f",&f);
printf("\n your floating point number is %f ",f);
//for double
printf("\nEnter a double number: ");
scanf("%lf",&d);
printf("\n your double number is %lf ",d);
//for long
printf("\nEnter a long number: ");
scanf("%ld",&l);
printf("\n your long number is %ld ",l);
return 0;
}

3. Write a program that read two integers and display their sum/ subtract/
product.
Program Code:
#include<stdio.h>
int main()
{
int a,b;
printf("Enter first integer:\n");
scanf("%d",&a);
printf("\nEnter second integer:\n");
scanf("%d",&b);
printf("\nSum is %d",a+b); //for summation
printf("\nSubtract is %d",a-b); //for subtraction
printf("\nproduct is %d",a*b); //for production
return 0;
}

4. Write a program that read any upper case character and display in lower.
Program Code:
#include<stdio.h>
int main()
{
char u;
//upper to lower
printf("\nEnter upper character: ");
scanf("%c",&u);
printf("\n your lower character is %c ",u+32);
return 0;
}

Exercise:
1. Write a program that read temperature in Celsius and display in Fahrenheit.
To convert temperature the equation is-

C/5 = (f-32)/9
Here, C is in Celsius and f is in Fahrenheit.

2. Write a program that read radius of a circle and display its area.
To calculate area of a circle the equation is-

Area= pi*r*r
Here, r is the radius of a circle and pi=3.1416.

You might also like