0% found this document useful (0 votes)
33 views

C Practicals Ishrat

Ishrat, a first year student of DAE (CIT) at Govt Monotechnic Institute in Orangi Town, Karachi, is taking practical classes in C programming. Her project file documents 20 programming labs covering topics like data types, input/output, operators, decision making, loops and functions. The labs involve writing and running code to demonstrate concepts and solve simple problems.

Uploaded by

asifmak
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views

C Practicals Ishrat

Ishrat, a first year student of DAE (CIT) at Govt Monotechnic Institute in Orangi Town, Karachi, is taking practical classes in C programming. Her project file documents 20 programming labs covering topics like data types, input/output, operators, decision making, loops and functions. The labs involve writing and running code to demonstrate concepts and solve simple problems.

Uploaded by

asifmak
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 27

Project File

C-Language
Practical(s)

Ishrat
D/o Muhammad Mubeen ul Haq

First Year DAE (CIT)


Ishrat
DAE (CIT)
First Year
1
INFORMATION
TECHNOLOGY

Institute:
Govt Monotechnic Institute,
Orangi 7, Karachi

2
Index

3
S# Practical Objective Date Sign
01 To learn Turbo-C Programming environment.
02 To print our name on screen
03 To study three data types of C language:
04 To study the use of format specifiers:

05 To study the use of format specifiers by using a variable:


06 To make marks sheet of exam:

07 To declare multiple variables and show them on screen:


To take age of a user in years as input and find out the
08 number of days :
Write a program that takes input from user and display on
09 screen.

10 To find out the percentage of marks in exam by user input.


11(a) Write a program which uses field specifiers.
11(b) Write a program which uses field specifiers.
11(c ) Write a program which uses field specifiers.
Write a program which counts the total number of
12 characters typed.
Write a program which takes user input as characters and
13 for character ‘Y’ it displays a message.

14 Modify the program of lab#13 by using if-else condition.


Write a program to avoid unnecessary repetition by using
15 for loop.
Write a program that uses for loop and a function to print
16 a text a
Write inprogram
a box. which can calculate minimum and
maximum of the two numbers by passing parameters in
17 functions.
Write a program which can calculate factorial of a given
18 number.
Write a program which shows at different locations of an
19 array.
Write a program which shows at different locations of an
20 array.

4
Lab 1

Objective:
To learn Turbo-C Programming environment.

Theory:
C Program consists of functions the main() function is the one which controls is passed when the is executed.

Code:
#include<stdio.h> //header file
#include<conio.h> //header file

void main(void) //main function


{
clrscr(); //clear scree
printf("Hello World");
getche(); //get character with echo wait
}

Practical Output:

Hello World

5
Lab 2

Objective:
To print our name on screen

Theory:
The printf function is a versatile and powerful function.

Syntax:
printf(“ some string ”);

Code:
#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();
printf("Ishrat”);
getche();
}

Practical Output:

Ishrat

6
Lab 3
Objective:
To study three data types of C language:

Code:

#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();
int int1; //declaring integer variable
char ch1; //declaring character variable
float fl1; //declaring float variable
//initializing variables
int1=10;
ch1='g';
fl1=0.1;
//printing variable values
printf("Value of int1 is %d\n",int1);
printf("Value of ch1 is %c\n",ch1);
printf("Value of int1 is %f\n",fl1);
getche();
}

Practical Output:

7
Lab 4
Objective:
To study the use of format specifiers:

Code:
#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();
printf("This is number %d",20);
getche();
}

Practical Output:

8
Lab 5
Objective:
To study the use of format specifiers by using a variable:

Code:
#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();
int a; // variable declaration
a=2;

printf("Value of a is %d",a); //variable call


printf("\nMy name is %s”,”Ishrat”);

getche();
}

Practical Output:

9
Lab 6
Objective:
To make marks sheet of exam:

Code:

#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int math,eng,urdu,islamiat,science; //declaration of variables

math=70;
eng=60;
urdu=20;
islamiat=80;
science=90;

printf("Math=%d\nEnglish=%d\nUrdu=%d\nIslamiat=%d\nScience=
%d\n",math,eng,urdu,islamiat,science);
getche();
}

Practical Output:

10
Lab 7
Objective:
To declare multiple variables and show them on screen:

Code:

#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int num1, num2;
char option1, option2;
float point1,point2;
num1=10;
num2=20;
option1='y';
option2='n';
point1=20.2;
point2=30.2;
printf("Option 1=%c\nNumber 1= %d\nPoint 1=%f",option1,num1,point1);
printf("\nOption 2=%c\nNumber 2= %d\nPoint 2=%f",option2,num2,point2);
getche();
}

Practical Output:

11
Lab 8
Objective:
To take age of a user in years as input and find out the number of days :

Code:

#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();

float years, days;


printf("Please type your age in years:");
scanf("%f",&years);
days=years*365;
printf("You are %.2f days old!\n",days);

getche();
}

Practical Output:

12
Lab 9
Objective:
Write a program that takes input from user and display on screen.

Code:

#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();

int age;
float height;
char gender;
printf("Type your age, gender(m/f), and height.\n");
scanf("%d %c %f",&age,&gender,&height);
printf("You are %d years old, your height is %f feet, your gender is
%c",age,height,gender);
getche();
}

Practical Output:

13
Lab 10
Objective:
To find out the percentage of marks in exam by user input.

Code:

#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int cp,as,isl,math,phy;
float sum, perc;
printf("Enter marks of Computer Programming.\n");
scanf("%d",&cp);
printf("Enter marks of Application Software.\n");
scanf("%d",&as);
printf("Enter marks of Islamiat.\n");
scanf("%d",&isl);
printf("Enter marks of Mathematics.\n");
scanf("%d",&math);
printf("Enter marks of Physics.\n");
scanf("%d",&phy);
sum=cp+as+isl+math+phy;
perc=sum*100/500;
printf("Your percentage is %.2f",perc);
getche();
}

Practical Output:

14
15
Lab 11(a)
Objective:
Write a program which uses field specifiers.

Code:
#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();

float event=27.25;
printf("event %.2f\n",event);
printf("event %.1f\n",event);
printf("event %f",event);
getche();
}

Practical Output:

16
Lab 11(b)
Objective:
Write a program which uses field specifiers.

Code:

#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();

float event=27.25;
printf("%8.1f %8.1f %8.1f\n",3.0,12.5,523.3);
printf("%8.1f %8.1f %8.1f\n",300.0,1200.5,5300.3);
getche();
}

Practical Output:

17
Lab 11(c)
Objective:
Write a program which uses field specifiers.

Code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
float event=27.25;
printf("%-8.1f %-8.1f %-8.1f\n",3.0,12.5,523.3);
getche();
}

Practical Output:

18
Lab 12
Objective:
Write a program which counts the total number of characters typed.

Code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();

int charcnt=0;
int wordcnt=0;
char ch;
printf("Type in a phrase: \n");
while(ch=getche()!='\r')
{ charcnt++; }

printf("Total characters typed are: %d",charcnt);


getche();
}

Practical Output:

19
Lab 13
Objective:
Write a program which takes user input as characters and for character ‘Y’ it displays a
message.

Code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
char ch;
printf("Type any character.\n");
ch=getche();
if(ch=='Y')
{
printf("\nYou typed Y.\n");
printf("You did it\n");
}
printf("\nTry again :-( please.");
getche();
}

Practical Output:

20
Lab 14
Objective:
Modify the program of lab#13 by using if-else condition.

Code:

#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
char ch;
printf("Type any character.\n");
ch=getche();
if(ch=='Y')
{
printf("\nYou typed Y.\n");
}
else
{
printf("\nYou did not type Y\n");
}
getche();
}

Practical Output:

21
Lab 15
Objective:
Write a program to avoid unnecessary repetition by using for loop.

Code:
#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
int i;
for(i=0;i<10;i++)
printf("\n\t Count = %d",i);
getche();
}

Practical Output:

22
Lab 16
Objective:
Write a program that uses for loop and a function to print a text in a box.

Code:

#include<stdio.h>
#include<conio.h>
void line(void);

// Function prototype is defined here and semicolon at end


void main(void)
{
clrscr();
line(); //Function is called
printf("\xDBIntro to Programming\xDB\n");

// \xDB is the ASCII code for a box


line();
getche();
}
void line(void) //Function definition
{
int i;
for(i=1;i<=22;i++)
printf("\xDB");

//variable i is visible or known only to line function


printf("\n");
}

Practical Output:

23
Lab 17
Objective:
Write a program which can calculate minimum and maximum of the two numbers by
passing parameters in functions.

Code:

#include<stdio.h>
#include<conio.h>
double minimum(double a, double b);
double maximum(double a,double b);

void main(void)
{
clrscr();
printf("Minimum of 11 and 23 is = %f\n",minimum(11, 23));
printf("Maximum of 10 and 20 is = %f",maximum(01, 20));
getche();
}
double minimum(double a, double b)
{
return a < b ? a : b;
}
double maximum(double a,double b)
{
return a > b ? a : b;
}

Practical Output:

24
Lab 18
Objective:
Write a program which can calculate factorial of a given number.

Code:

#include<stdio.h>
#include<conio.h>
int factorial(unsigned int number)
{
if(number <= 1)
return 1;
return number * factorial(number - 1);
}
void main()
{
clrscr();
int x = 5;
printf("factorial of %d is %d",x,factorial(x));
getche();
}

Practical Output:

25
Lab 19
Objective:
Write a program which shows at different locations of an array.

Code:

#include<stdio.h>
#include<conio.h>

void main(void)
{
clrscr();
short age[4]; // array declaration
age[0]=23; //array elemets index wise assignment
age[1]=34;
age[2]=65;
age[3]=74;

//printing array elements

for(int i=0; i<4;i++)


{
printf("Age at index %d = %d\n",i, age[i]);
}
getche();
}

Practical Output:

26
Lab 20
Objective:
Write a program which shows at different locations of an array.

Code:

#include<stdio.h>
#include<conio.h>
void main(void)
{
clrscr();
short mat[3][3],i,j;

for(i = 0 ; i < 3 ; i++)


for(j = 0 ; j < 3 ; j++)
{
mat[i][j] = i*10 + j;
}
printf(" Initialized data to: ");
for(i = 0 ; i < 3 ; i++)
{
printf("\n");
for(j = 0 ; j < 3 ; j++)
{
printf("%5.2d", mat[i][j]);
}
}
getche();
}

Practical Output:

27

You might also like