Documente Academic
Documente Profesional
Documente Cultură
Name : ________________________________
Reg # : ________________________________
Degree : ________________________________
Semester : ________________________________
_______________
Faculty Signature
Index
S.no Objective of Experiment Remarks Date Signature
Students Feedback :
Getting familiar with the IDE and working with Turbo C &Microsoft Visual
9. Studio. Installing and copying the compiler, changing directory settings.
Making first program in C. Saving / copying files to USB or other storage
devices.
Students Feedback :
10. Understanding and Using format specifier and escape sequences with printf.
Students Feedback :
Taking Input from the user at console screen using scanf and getche
12.
commands.
Students Feedback :
Studying loops. For loops, nested for loops, while loops, nested while loops,
14.
do while loops, nested do while loops. Studying loops with cross combination.
Students Feedback :
Note: Students are advised to write their comments about whether the objective of the lab was achieved or not in
Student Feedback section.
Experiment 1
Objective: Introduction to Computer Hardware
The following pictures have some slight differences from the instructions. The instructions are for
the standard workstation. The pictures are for a computer that Tanja Lange and I assembled on
2006.01.11, with the following differences from the standard workstation:
Opening the case. Unpack the computer case. Discard its plastic wrap. Put on an antistatic wrist
strap, and attach it to ground (for example, to the screw on a typical light-switch plate).
http://cr.yp.to/hardware/build-20060107.html
Remove the side of the case by pulling the two side latches towards the front of the
case and then away from the case:
Look for power supply and the proper power cord latches:
Look for processor and Ram Slots. Ram is placed vertically in thin straight slots shown in
above image on left. Whereas processor is a square shaped chip.
Processor
Fan
Heat
Sink
Heat sink is first placed over processor then a fan is placed above it:
Then place the mother board inside the casing with a plastic sheet coating at the
back fixed using screw drivers
Look for proper power cables to power up the motherboard which in turn will provide
power to RAM and Processor (Power Cable used above is suitable for motherboard):
Plug the reset-switch, power-switch, HDD-LED (also known as IDE-LED) and PC
Speaker connectors into the motherboard, all labels facing upwards:
Plug the front Panel USB Port cable into the motherboard:
Plug the video card into the motherboard:
Slide the DVD drive into the case from the front until the drive rails snap into
place. Plug the UATA cable into the blue connector on the motherboard:
Plug a 4-pin power cable into the DVD drive
Experiment 2-a
Objective : Every student should individually install MS windows XP on the personal computer.
PROCEDURE:
1. Keep on press the delete button and go to advanced BIOS feature. [ BIOS- Basic Input
Output System ].
2. And go to boot sequence. Select first boot drivers. CD ROM and press F10 to save the
bios feature. Yes and then enter. Press any key to boot from CD. Press enter to setup
windows XP. F8 = To agree the license.
3. Press ESC to don’t repair the windows XP setup.
4. Press ‘p’ to delete the previous partitions. Then press enter.
5. Press ‘L’ to delete the partition.
6. Press ‘C’ to create the partition in the un partition space.
7. Press enter to setup windows XP on the selected items.
BASIC FILE SYSTEMS:
FAT: File Allocation Table.
NTFS: New Technology File System.
Format the create using NTFS partition
Collecting information.
Dynamic update.
Preparing installation
Installing windows.
Tracking installation.
Select the language as English (united states), then ok.
Installation process
Installing Windows XP can take up to two hours. To make the process more manageable, it has been
broken up into several sections. When you are ready, install Windows XP:
Insert the Windows XP CD into your computer and restart your computer.
If prompted to start from the CD, press SPACEBAR. If you miss the prompt (it only appears
for a few seconds), restart your computer to try again.
Windows XP Setup begins. During this portion of setup, your mouse will not work, so you must use
the keyboard. On the Welcome to Setup page, press ENTER.
Windows XP Setup begins. During this portion of setup, your mouse will not work, so you must use
the
This page enables you to select the hard disk drive on which Windows XP will be installed. Once you
complete this step, all data on your hard disk drive will be removed and cannot be recovered. It is
extremely important that you have a recent backup copy of your files before continuing. When you have
a backup copy, press D, and then press L when prompted. This deletes your existing data.
Windows XP erases your hard disk drive using a process called formatting and then copies the setup
files. You can leave your computer and return in 20 to 30 minutes.
Windows XP restarts and then continues with the installation process. From this point forward, you can
use your mouse. Eventually, the Regional and Language Options page appears. Click Next to accept the
default settings. If you are multilingual or prefer a language other than English, you can change language
settings after setup is complete.
Part 2: Continue the installation
Windows XP restarts and then continues with the installation process. From this point forward, you can
use your mouse. Eventually, the Regional and Language Options page appears. Click Next to accept the
default settings. If you are multilingual or prefer a language other than English, you can change
language settings after setup is complete.
On the Personalize Your Software page, type your name and your organization name. Some
programs use this information to automatically fill in your name when required. Then, click
Next.
On the Your Product Key page, type your product key as it appears on your Windows XP CD case.
The product key is unique for every Windows XP installation. Then, click nex
Part 3: Complete the installation
A list of disks will appear in a text format. You will return to the diskpart prompt. Step
one verified that Disk 1 is the 3TB drive. Warning: Diskpart Erase/Clean will
permanently erase/destroy all data on the selected drive. Please be certain that you
are erasing the correct disk.
5. From the diskpart prompt you will need to select a disk disk number (for instance,
if the 3TB+ drive is Disk 1, you would type select disk 1) and press Enter.Warning:
Diskpart Erase/Clean will permanently erase/destroy all data on the selected drive.
Please be certain that you are erasing the correct disk.
6. A message appears saying that the disk is selected. You will return to the diskpart
prompt. Warning: Diskpart Erase/Clean will permanently erase/destroy all data on
the selected drive. Please be certain that you are erasing the correct disk.
7. From the diskpart prompt, type clean and press Enter. The drive's partition, data,
and signature is now removed. You will return to the diskpart prompt. Warning: Once
you type clean and hit enter the drive will be erased. No warning will be provided.
8. The Command Prompt window will display the message "DiskPart succeeded in
cleaning the disk". Close out of the Command Prompt window by clicking thered X in
the upper right hand corner.
INTRODUCTION TO MS-OFFICE
Microsoft office is a set of inter related desk top applications ,servers and services, collectively refers to
as an office suit for the micro soft windows and MAC OSX operating systems .
MS WORD:
Microsoft Word is a word processing software package. we can use it to type letters, reports, and other
documents. In Word 2007, how a window displays depends on the size of your window, the size of Your
monitor and the resolution to which your monitor is set. Resolution determines how much information
your computer monitor can display.
STARTING MS WORD:-
The Ribbon
We use the Ribbon to issue commands. The Ribbon is located near the top of the screen, below the
Quick Access toolbar. At the top of the Ribbon are several tabs; clicking a tab displays several related
command groups. Within each group are related command buttons. You click buttons to issue
commands or to access menus and dialog boxes
The Ruler
We can use the ruler to change the format of your document quickly
Assignment :
Make your Curriculum Vitae using MS Word which includes objective, academic qualification, skills,
field of interest, projects and two references and also insert a picture in it.
Experiment 4
Objective : Creating project abstract Features to be covered:-Formatting Styles, Inserting table,
Bullets and Numbering, Changing Text Direction, Cell alignment, Footnote, Hyperlink, Symbols,
Spell Check, Track Changes.
THEORY:
Cell Alignment:
Aligns contents written in a table in the top left corner or top right corner or in the center etc.
Foot Note:
Foot notes are used to comments on, or provide references for text in a document.
Hyperlink:
It is a colored and underlined text or a graphic that you click to go to a file, a location in a file , an
HTML page on the world wide web, or an HTML page in an intranet.
Symbols:
You may not be able to enter certain symbols into your word document, as there is a limitation on
the keys on the key board. Creating these new symbols especially when working with mathematical
terms it becomes very difficult .For example we can insert symbols such as,,,
Spell check:
It automatically checks for spelling and grammatical errors
Formatting Style:
A style is a set of rules to be followed for the effective document. Style can be applied to text,
paragraph, table or a list.
Track changes:
Track changes is a an excellent feature of Microsoft word as it enables a user or reviewer to keep
track of the changes that have taken a period. Changes like insertion, deletion or formatting changes
can be kept track of.
Procedure:
Click the drawing object or table cell that contains the text you want to change.
On the Format menu, click Text Direction.
Click the orientation you want.
Table:
Click where you want to create a table.
On the Table menu, point to Insert, and then click Table.
Under Table size, select the number of columns and rows.
Under AutoFit behavior, choose options to adjust table size.
To use a built-in table format, click AutoFormat.
Cell Alignment:
Foot Note:
1. In print layout view, click where you want to insert the note reference mark.
2. On the Insert menu, point to Reference, and then click Footnote.
3. Click Footnotes or Endnotes.
By default, Word places footnotes at the end of each page and endnotes at the end of the
document. You can change the placement of footnotes and endnotes by making a selection in the
Footnotes or Endnotes box.
Word inserts the note number and places the insertion point next to the note number.
Hyper link:
Select the text or picture you want to display as the hyperlink, and then click Insert Hyperlink on the
Standard toolbar
An e-mail address:
1. Select the text or picture you want to display as the hyperlink, and then click Insert Hyperlink
on the Standard toolbar
2. Under Link to, click E-mail Address.
3. Either type the e-mail address you want in the E-mail address box, or select an e-mail address
in the recently used e-mail addresses box.
4. In the Subject box, type the subject of the e-mail message
A specific location in another document
Symbol:
1. When Word finds a possible spelling or grammatical problem, make your changes in the
Spelling and Grammar dialog box.
1. Type 1.to start a numbered list or * (asterisk) to start a bulleted list, and then press
SPACEBAR or TAB.
2. Type any text you want.
3. Press ENTER to add the next list item. Word automatically inserts the next number or bullet.
4. To finish the list, press ENTER twice, or press BACKSPACE to delete the last bullet or number
in the list
Formatting Styles:
Track Changes:
Assignment :
Make a Student’s Schedule using tables and text box in MS Word. Mention the student’s ID, name,
semester, degree, name of registered courses, Faculty name, class timing, days and location.
Experiment 5
Objective : Introduction MS Excel working Environment, Modifying an spread sheet, working with
Formulas and designing chart
Step 2. Writing an addition equation If you were to state the process for
adding the numbers in column B it would be "six plus three." The
equation could be written exactly like that (=6+3) and Excel would
display the expected answer, 9. However that equation would be
useless if the numbers in either B2 or B3 were changed. When
writing your own equation, use cell addresses.
=B2+B3
When writing the equation, clicking in cell B2 displays B2 in the equation. If you have written the
equation correctly you may accept it by pressing the Enter/Return key or by clicking on the green
check mark. If you change your mind, click on the red X to cancel the operation.
Step 4. Task Prepare a worksheet with the data displayed under Step 1. Enter the proper equation
under each set of two numbers. Do not look at step 5.
Scenario: Bill took three tests scoring 88, 76, and 58. The average of his tests counts as half of Bill's
grade. What number value has Bill achieved toward his term grade?
Assignment
Make a Sheet on excel as given below and fill the empty cells by using given information .
Name Basic salary House Rent Transport Allownce Gross salary PF Contribution Income Tax Net Salary
Ali 34100
Sami 33205
Eshal 78428
Farhan 48004
Faiza 64452
Salman 60977
Step 1. Review percent Before showing how to calculate percent with Excel, let's review how to
calculate percent.
A number divided by a second number and multiplied by 100 expresses what percent the first
number is of the second number. If you do not multiply by 100 you have the decimal
equivalent of percent.
Step 2. Writing a percent equation for only two numbers
Solve the following: 2 is what percent of 8?
Now that you are sure you remember the process for calculating percent, use an Excel worksheet to
perform the calculations.
Step 5. Absolute Cell Reference You tell Excel to use one specific cell,
and never move to another relative location in the
calculations by using "absolute cell reference." To specify the
cell, place a dollar sign before the column letter and before
the row number. Thus, $B$10 says always use cell B10. Lets
go back to the worksheet and re-write the equation in C2.
Notice the answer has not changed. If we were writing only this one
equation, we wasted time using absolute cell reference. The real
benefit of this equation will be seen when you fill down into cells C3
through C10.
Step 6. Fill the equation down into the cells below As soon as you fill this equation with an absolute
cell reference down into cells C3 through C10, the percentages are instantly calculated. Only
one more task remains.
Step 7. Format the cells Unless you need five decimal places, I suggest formatting cells C2 through
C10, the highlighted range above, so that one decimal place is displayed.
Right-click on the highlighted range of cells, and select Format Cells...
In the category list select Number, and in the Decimal places: box
use the down arrow to choose 1.
Step 3. Highlight data to be graphed. Do not include the row with heading titles, only the
names of fruit and the numbers. If your worksheet looks like the one above; put
your cursor in call A2, click hold the mouse button down and drag to cell B7.
Highlighted data should look like the image below:
Note: Cell A2 is selected, the select color extends around the cell
Step 4. Select the Chart Wizard. That is done by going to the Insert menu and selecting Chart. You
can also click on the Chart Wizard button on the Standard toolbar.
Step 5. From the Chart Wizard box that opens select Chart type. For this activity, I selected pie.
After you have selected the Chart type, click and hold your mouse pointer down on the Press and Hold...
button to see what your data looks like in the chart type you selected. If you do not like the look, select
another chart type. After you have selected the chart type you will have two options:
Select Next and let Chart Wizard show you a series of options to make changes to your chart.
The second step taken by Chart Wizard is to verify the range of data being used for this chart. The
Data range displayed below is read "all cells from A2 to B7."
Notice where the cursor is located in the dialog box above. It is pointing to the small box at the end of
the line where the Data range is displayed. If the data range should be changed, click on the box the
cursor is pointing to.
Select Next to go to the dialog box below. This box allows you to add a title to the chart, make
changes on the legend, or make changes on the data labels.
Select Finish and Chart Wizard puts your completed chart on the spreadsheet.
Select Next to move to the final dialog box which allows you to see the chart as a new sheet or place it
on one of the sheets in your workbook.
If you let the Chart Wizard finish your chart after the first dialog box, or work through each of the four
steps, your chart will look something like the one Below
Assignment :
Course Credit Hrs. Total Marks Obtained Marks Percentage Grade GPA
ICS Theory 3 100
ICS lab 1 100
App. Physics 3 100
Calculus 3 100
English 2 100
(a) Find GPA and Grade in each course if the following grading system will be followed.
(c) By using conditional formatting, If student got below 60% marks then the grade and GPA cell
should turn red otherwise green.
Tables
A table is a collection of data about a specific topic, such as students or contacts. Using a separate
table for each topic means that you store that data only once, which makes your database more
efficient, and reduces data-entry errors.
Tables organize data into columns (called fields) and rows (called records).
Create a Table from scratch in Design view
1. If you haven't already done so, switch to the Database Window You can press F11 to switch to the
Database window from any other window.
Primary Key
One or more fields (columns) whose value or values uniquely identify each record in a table.
A primary key does not allow Null values and must always have a unique value. A primary key
is used to relate a table to foreign keys in other tables.
NOTE: You do not have to define a primary key, but it's usually a good idea. If you don't define
a primary key, Microsoft Access asks you if you would like to create one when you save the
table.
o For our tutorial, make the Soc Sec # field the primary key, meaning that every student has a
social security number and no 2 are the same.
o To do this, simply select the Soc Sec # field and select the primary key button
Entering Data
Click on the Datasheet View and simply start "chugging" away by entering the data into each field.
NOTE: Before starting a new record, the Soc Sec # field must have something in it, because it is the
Primary Key. If you did not set a Primary Key then it is OK.
Experiment 8
Objectives : To demonstrate the ability to create a database with multiple tables, execute different queries,
and produce reports.
Problem
An auto repair shop needs to maintain information on its jobs and customers. The shop specialises in repair
jobs for local car dealers. The database it uses consists of two tables. The Jobs table contains data on jobs the
repair shop either has started or has completed for each customer. The Customers table contains pertinent
data about the auto repair shop’s customers.
Instructions:
1. Create a new database to store the two tables related to the auto repair shop. Call the database Repair
Shop.
2. Import the Jobs data from the excel spreadsheet provided on eLearn. Make the Job ID the primary key, no
duplicates. Call the table Jobs. Configure the table using the structure shown in Table 1.1.
3. Import the Customers data from the excel spreadsheet provided on eLearn. Make the Customer ID the
primary key, no duplicates. Call the table Customers. Configure the table using the structure shown in Table
2.1.
4. Create a report using the Jobs table that consists of the Job ID, Job Description, Completion Date, and
Quote. Title the report Job Summary Report. The beginning of your report should be similar to the on shown
in Figure 4.1.
5. Using query, generate the list of incomplete and complete jobs using the Jobs table. The results should be
similar to those shown in Figure 5.1 and 5.2.
Figure 5.1: List of complete jobs.
6. Using query, generate the list of customers who owe the company money (assuming that they will only pay
you after the jobs have completed). The results should be similar to the one shown in Figure 6.1.
7. Using query, generate the list of customers (with their contact details) whose their jobs have completed.
The results should be similar to the one shown in Figure 7.1.
Figure 7.1: The list of customers (with their contact details) whose their jobs have completed.
8. Using query, generate the list of customers (with their contact details) whose their jobs are incomplete, and
show the expected completion date. The results should be similar to the one shown in Figure 8.1.
Figure 8.1: The list of customers (with their contact details) whose their jobs are incomplete.
9. Generate invoice for each completed job for each customer. The invoice (report) should be similar to those
shown in Figure 9.1 and 9.2. [Hint: You will have to modify the report template to achieve this. If you have
done it correctly, you should be able to observe in Print Preview that the invoice for each customer is
separated.]
Assignment :
You have been asked to create a small information system to administer the records of a small educational
institution using MS Access. The following details need to be stored: students' surname, first name, date of
birth, the date they enrolled in the institution, papers available for study, including the paper code and paper
title, the enrolments of students in particular papers, including date of enrolment, mark gained, and fee
charged.
Create a database with the appropriate number of tables to store the above data and establish appropriate
relationships between them.
Experiment 9
Objective
Getting familiar with the IDE and working with Turbo C &Microsoft Visual Studio. Installing and copying the compiler,
changing directory settings. Making first program in C. Saving / copying files to USB or other storage devices.
Theory
IDE
An integrated development environment (IDE) is a software suite that consolidates the basic tools developers need
to write and test software. Typically, an IDE contains a code editor, a compiler or interpreter and a debugger that the
developer accesses through a single graphical user interface (GUI). An IDE may be a standalone application, or it
may be included as part of one or more existing and compatible applications.
There are different IDE‟s to write C program. Following are the two most common;
1. Turbo C
2. Microsoft Visual Studio
1. Turbo C
Turbo C is a discontinued Integrated Development Environment and compiler for the C programming language from
Borland. First introduced in 1987, it was noted for its integrated development environment, small size, fast compile
speed, comprehensive manuals and low price.In May 1990, Borland replaced Turbo C with Turbo C++.
The use of this IDE on latest OS has become very difficult as a lot of libraries are not supported any more. The use of
this IDE is depreciated.
A new window will open. From there right click on the folder named as TC3 and select copy. Now Paste in it in your C
or D partition or your USB drive. As a good approach C drive is normally not recommended for C compiler as C drive is a
windows system partition.
Assuming that the folder has been copied in the root of D drive, open D: p artition - TC3 folde r - BIN –
Double click and open any one of the two TC.exe icons (as shown on right).
The window that opens is the known as the IDE of Turbo C (as shown bel
Setting Directory Paths (to be checked each time the Turbo IDE is opened)
Once you have opened and saved a new file some directories need to be changed according to the location of your
compiler in your computer otherwise the compiler make not work properly.
On the standard toolbar click on options then directories. Set the first letter of the first two paths (i.e. Include Directories
and Library Directories) according to the location of the compiler or say the letter of the directory where you copied your
compiler. The other two paths (i.e. Output Directories and Source Directories) will remain blank. e.g.
Visual Studio includes a code editor supporting IntelliSense as well as code refactoring. The integrated debugger works
both as a source-level debugger and a machine-level debugger. Visual Studio supports different programming
languages and allows the code editor and debugger to support nearly any programming language. Built-in languages
include C, C++, VB.NET, C# and F#.
Open Microsoft Visual Studio by double clicking on the Icon. The icon similar to the following (depending upon the version)
should be available on your desktop.
We first have to create a project. To create a new project, click on “New Project” option present on the left side. A
Window similar to the one shown below will appear. Expand the template option present on left side of the window.
Select “Visual C++” and under this, select “General” option. Select first option “Empty Project” from the middle
section. Provide name for the project as “Lab1” and press OK.
Figure 1.6: Create new project
After you click OK, following screen will be displayed which has a Solution Explorer on the right hand side. This panel will be used to
access all the files of the project.
Now right click on your project “Lab1, and go to Add and then select New item, refer to the screenshot below.
Figure 1.8: Add new item
A window similar to one given below will appear. Select Visual C++ and code from the left panel. Select C++ f ile from
the middle panel. Give a name to your source file. This will by default create a file with .cpp extension which
represents(C++) but we have to create a C file. Change the extension to .c and click Add.
Now you can simply add a C program and execute the file.
First C Program
#include<stdio.h>
#include<conio.h>
The first line of this program is #include<stdio.h> . Here #include tells the compiler to include something and stdio means
Standard Input/Output where as .h means that it is a header file or in short we are including standard input/output header
file. In the same way the next line is similar to the first one but it has conio.h in it where conio means the black colour
console screen where we see our output and .h tells us that this is a header file. In other words we tell the compiler that
we are including two files and the code we will write will be of c language as the compiler also supports C++ code.
void main(void)
This is third line. The first word in this is void which means any thing that has no value or is useless. The next word is
main which is the brain function and is the only function readable in most programming languages. All the other functions
are called within the main function. The third word within brackets is also void. The first void means that the main function
won‟t return any value while the second void means that the main function is not going to accept any value. This complete
line means that we have declared the main function here. For example a simple calculator takes two or more numbers
from you and returns the result like addition, subtraction, multiplication etc. It may be confusing at this time to understand
the void functionality but in experiment 11 we will discuss it in detail.
{
Following the main function line is a curly bracket which marks the starting of mains body. Always remember that if any
bracket is opened in C language it needs to be closed hence the last line of the above program marks the ending of main
function.
clrscr();
This is the first function called inside the main body. All functions will always have a round brac ket closing „)‟ and a
semicolon „;‟ at their end. In that way we easily recognize the number of functions in a program. According to this rule we
can identify 3 functions in this program. However other properties in different functions may differ but this identity will be
common in all functions. clrscr is short form of clear screen. It clears the screen of any previous output. If not used wont
create any error but output will show all previous compilation result.
getch();
This is the last function of this program. Its name is short form of get character. Its purpose is to get a character. Its used
in last to stop the program until a character is entered. If not used wont show any error but the output will not stop after
compilation. In this case the output is checked manually by pressing Alt+F5 key.
The C program given above will give some compile time errors in Visual Studio. Write following code in the .c file.
#include<conio.h>
#include<stdio.h>
void main()
{
system("cls");
printf("My First Program");
_getch();
}
Save this file (Ctrl + s). Click on the green play icon present on top of the screen to compile and execute your first program.
Note: There are few functions of old C which is no more available in latest IDEs like clrscr(). Replace clrscr() with
system("cls") and getch() with _getch().
Example
Program
Output
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{ My First Program
system(“cls”);
printf("My First Program");
_getch();
}
Exercise
Carefully look at the following programs and write the output.
Program Output
#include<stdio.h> Write the output for the program on left
#include<conio.h>
void main(void)
{
printf("My First Program");
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
void main(void)
{
_getch();
printf("My First Program");
}
#include<stdio.h> Write the output for the program on left
#include<conio.>
void main(void)
{
_getch();
printf("My First Program");
_getch();
}
#include<stdio.h> Write the output for the program on left
#include<conio.h
#include<stdlib.h>
void main(void)
{
_getch();
system(“cls”);
printf("My First Program");
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
_getch();
printf("My First Program");
system(“cls”);
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
_getch();
system(“cls”
printf("My First Program");
_getch();
}
Program Output
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
_getch();
printf("My First Program");
_getch();
system(“cls”);
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
_getch();
printf("My First Program");
_getch();
}
#include<conio.h> Write the output for the program on left
#include<stdio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
printf("My First Program");
_getch();
}
#include”conio.h” Write the output for the program on left
#include”stdio.h”
#include”stdlib.h”
void main(void)
{
system(“cls”);
printf("My First Program");
_getch();
}
#include<conio.h> Write the output for the program on left
#include<stdio.h>
#include<stdlib.h>
main()
{
system(“cls”);
printf("My First Program");
_getch();
}
#include<CONIO.H> Write the output for the program on left
#include<STDIO.H>
#include<STDLIB.H>
void main(void)
{
system(“cls”);
printf("My First Program");
_getch();
}
Assignment :
Write a C program using commands described in this lab to make a resume showing your
complete details.
Assignment:
Using the program below, make a resume showing your complete details.
Program:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
printf("\n****************************RESUME****************************");
printf("\n******************************CV******************************");
printf("\n**************************************************************");
printf("\n==============================================================");
printf("\nName : Abc");
printf("\nFathers Name : Xyz");
printf("\nDate of Birth : dd-mm-yyyy");
printf("\nAddress : Engineering Department, Main Campus, Iqra University,");
printf("\n Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCNIC : XXXXX-XXXXXXX-X");
printf("\nGender : Male");
printf("\nHSC (College\\Board) : Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : August 2005 ");
printf("\nSSC (School\\Board) : Science, Iqra School, Karachi Board");
printf("\nSSC Year : August 2003 ");
_getch();
}
Experiment 10
Objective
Understanding and Using format specifier and escape sequences with printf.
Theory
The C library function printf() sends formatted output to stdout.Following is the declaration for printf() function.
int printf(const char *format, ...)
format − This is the string that contains the text to be written to stdout. It can optionally contain embedded format tags that are
replaced by the values specified in subsequent additional arguments and formatted as requested.
Format specifiers are used to substitute and print values inside a printf or scanf statement which are further applicable on
variables. Below is a chart of format specifier examples using printf.
Escape Sequences are used to adjust spacing between lines or characters or the characters themselves.
Example
Program Output
#include<stdio.h>
#include<conio.h>
void main(void)
{ a
Iqra University
printf("\n%c",'a'); 20
printf("\n%s","Iqra University"); 35.500000
printf("\n%d",20); 1234567
printf("\n%f",35.5);
pri ntf("\n%ld", 1234567);
_getch();
}
#include<stdio.h>
#include<conio.h>
void main(void)
{
Assignment:
Use the program below to make your resume with format specifiers and escape sequences showing your
complete details.
Program:
#include<stdio.h>
#include<conio.h>
void main(void)
{
printf("\t\t\t\n****************************RESUME****************************");
printf("\t\t\t\n******************************CV******************************");
printf("\t\t\t\n**************************************************************");
printf("\t\t\t\n==============================================================");
printf("\nName : %s","Abc");
printf("\nFathers Name : %s","Xyz");
printf("\nDate of Birth : %d-%d-%d",11,11,1989);
printf("\nAddress : %s","Engineering Department, Main Campus, Iqra University,");
printf("\n %s","Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCell Phone : 0%d-%ld",300,1234567);
printf("\nCNIC : %d-%ld-%d",12345,1234567,1);
printf("\nGender : %s","Male");
printf("\nHSC (College\\Board) : %s","Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : %s %d","August",2005);
printf("\nSSC (School\\Board) : %s","Science, Iqra School, Karachi Board");
printf("\nSSC Year : %s %d","August",2003);
_getch();
}
Experiment 11
Objective
Studying different data types, variables, variable names, variable declaration, variable definitionand variable initia lization.
Theory
Variables are declared by first writing
data types followed by a variable name, e.g.
int a=10;
Here
Supported Example
No. Data Type Syntax format Specifier Value
1 Single Character char %c One character within single quotes char a=‟a‟;
2 Decimal Integer int %d Any whole number between -32,768 to 32,767 int a=10;
3 Long Integer long int %ld Any number between -2,147,483,648 to 2,147,483,647 long int a=12345;
-38 38
4 Float float %f Any decimal point number between 10 to 10 float a=1234.567;
0-308 308
5 Double double %lf Any decimal point number between 1 to 10 double a=1 23456;
Variable Names
Variable names will always start with an alphabet.
Variable names can contain numbers (1,2,45,66) and underscores (_) but no other special characters (!@#$%^&*).
Variable names cannot resemble to any predefined word e.g. include, printf, getch, scanf etc..
A variable name cannot be used for multiple declarations.
Example
Program Output
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{ a
system(“cls”); 12
char a='a'; 1234567
12.5000
int b=12; 00
float c=12.5;
double d=1234567;
printf("%c %d %f %lf",a,b,c,d);
_getch();
}
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
char a='a',a1=’b’;
int b=12,b1=13;
float c=12.5,c1=13.5;
double d=1234567,d1=1234568;
printf("\n%c %d %f %lf",a,b,c,d);
printf("\n%c %d %f %lf",a1 ,b1 ,c1,d1);
_getch();
}
Write the output for following programs.
Program Output
#include<stdio.h> Write the output for the program on left
#include<conio.h>
#include<stdlib.h>
void main(void)
{
system(“cls”);
char a=97;
int b=’A’;
float c=12.5;
double d=1234567;
printf("%c %d %f %lf",a,b,c,d);
_getch();
}
Assignment:
Using the program below, make a resume with format variables showing your complete details.
Program
#include<stdio.h>
#include<conio.h>
void main(void)
{
int dd,mm,yyyy,cell1,cnic3;
long int cnic1,cnic2,cell2;
dd=11;
mm=11;
yyyy=1989;
cell1=300;
cell2=1234567;
cnic1=12345;
cnic2=1234567;
cnic3=1;
printf("\n****************************RESUME****************************");
printf("\n******************************CV******************************");
printf("\n**************************************************************");
printf("\n==============================================================");
printf("\nName : %s","Abc");
printf("\nFathers Name : %s","Xyz");
printf("\nDate of Birth : %d-%d-%d",dd,mm,yyyy);
printf("\nAddress : %s","Engineering Department, Main Campus, Iqra University,");
printf("\n %s","Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCell Phone : 0%d-%ld",cell1,cell2);
printf("\nCNIC : %ld-%ld-%d",cnic1,cnic2,cnic3);
printf("\nGender : %s","Male");
printf("\nHSC (College\\Board) : %s","Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : %s %d","August",2005);
printf("\nSSC (School\\Board) : %s","Science, Iqra School, Karachi Board");
printf("\nSSC Year : %s %d","August",2003);
_getch();
}
[Type text]
Experiment 12
Objective
Taking Input from the user at console screen using scanf and getche commands.
Theory
Scanf command can take input of different data types at a time.
Getche command can take only one character input.
Example
Write the output after supplying appropriate input on console screen.
Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
char a;
int b;
float c;
double d;
printf("\nEnter character ");
scanf_s("%c",&a);
printf("\nEnter integer ");
scanf_s("%d",&b);
printf("\nEnter float ");
scanf_s("%f",&c);
printf("\nEnter double ");
scanf_s("%lf",&d);
printf("\n%c %d %f %lf",a,b,c,d);
_getch();
}
Program
#include<stdio.h>
#include<conio.h>
void main(void)
{
int dd,mm,yyyy,cell1,cnic3;
long int cnic1,cnic2,cell2;
dd=11;
mm=11;
yyyy=1989;
cell1=300;
cell2=1234567;
cnic1=12345;
cnic2=1234567;
cnic3=1;
printf("\n****************************RESUME****************************");
printf("\n******************************CV******************************");
printf("\n**************************************************************");
printf("\n==============================================================");
printf("\nName : %s","Abc");
printf("\nFathers Name : %s","Xyz");
printf("\nDate of Birth : %d-%d-%d",dd,mm,yyyy);
printf("\nAddress : %s","Engineering Department, Main Campus, Iqra University,");
printf("\n %s","Shaheed-e-Millat Road, Defence View Karachi");
printf("\nCell Phone : 0%d-%ld",cell1,cell2);
printf("\nCNIC : %ld-%ld-%d",cnic1,cnic2,cnic3);
printf("\nGender : %s","Male");
printf("\nHSC (College\\Board) : %s","Science (Pre Engg), Iqra College, Karachi Board");
printf("\nHSC Year : %s %d","August",2005);
printf("\nSSC (School\\Board) : %s","Science, Iqra School, Karachi Board");
printf("\nSSC Year : %s %d","August",2003);
_getch();
}
Experiment 13
Objective
Arithmetic operators, conditional operators, assignment operators, Increment/decrement operators.Studying Math
functions.
Theory
Math.h header file is included for the definitions of math functions listed below. It is written as #include<math.h>.
Example
The program below shows the result for math and trigonometric functions. The functions pass the values to variables
which are further used for printing in printf.
Program Output
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void)
{
float a=45,b=1,sn,cs,tn,snh,csh,tnh;
sn=sin(a);
Hyperbolic Functions
printf("\n\n\n Trignometric Functions"); sinh 1 = 1.18
printf("\nsin 45 = %.2f",sn); cosh 1 = 1.54
printf("\ncos 45 = %.2f",cs); tanh 1 = 0.76
printf("\ntan 45 = %.2f",tn);
printf("\nsinh 1 = %.2f",snh);
printf("\ncosh 1 = %.2f",csh);
printf("\ntanh 1 = %.2f",tnh);
_getch();
}
The program below shows the result for math and trigonometric functions. It also demonstrates that some functions may
be called within the body of another function. For example here all the trigonometric functions are called inside printf
function.
Program Output
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main(void) Trignometric Functions
{ sin 45 = 0.85
printf("\n\n\n Trignometric Functions"); cos 45 = 0.53
tan 45 = 1.62
printf("\nsin 45 = %.2f",sin(45));
printf("\ncos 45 = %.2f",cos(45)); Hyperbolic Functions
printf("\ntan 45 = %.2f",tan(45)); sinh 1 =1.18
cosh 1 = 1.54
printf("\n\n\n Hyperbolic Functions"); tanh 1 = 0.76
printf("\nsinh 1 = %.2f",sinh(1));
printf("\ncosh 1 = %.2f",cosh(1));
printf("\ntanh 1 = %.2f",tanh(1)); Math Functions
pow 2,3 = 8.00
printf("\n\n\n Math Functions"); sqrt 49 = 7.00
printf("\npow 2,3 = %.2f",pow(2,3));
printf("\nsqrt 49 = %.2f",sqrt(49));
_getch();
}
Operators
int a=2,b=4,c1,c2,c3,c4,d1,d2,d3,d4; 6 -2 8 0
c1=c2=c3=c4=5; 0 10 1 0 1
d1=d2=d3=d4=8; 8 2 15 1
printf("\n%d %d %d %d",a+b,a-b,a*b,a/b); 8 98 7
printf("\n%d %d %d %d %d %d",a>b,a<b,a>=b,a<=b,a==b,a!=b);
printf("\n%d %d %d %d",c1+=3,c2-=3,c3*=3,c4/3);
printf("\n%d %d %d %d",d1++,++d2,d3--,--d4);
_getch();
}
Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d",- -a,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %d %d",a++,++a,a,a - -);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a+5,++a,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a+=5,++a,a);
printf("\n%d ",a);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a-=5,- -a,a);
printf("\n%d ",a);
_getch();
}
#include<stdio.h> Write the output for the program on left
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d %dd",a+=5,a++,a);
printf("\n%d ",a);
_getch();
}
Exercise
Write output for following programs and give reasons.
Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=5;
printf("\n%d %d",a++,a);
printf("\n%d ",a);
_getch();
}
Example: This table below shows nested loops. All the three programs have same output.
Loop Nested
Program Output Program Output
Loop
#include<stdio.h>
#include<conio.h>v
oid main(void)
#include<stdio.h> {
#i nclude<conio.h> for(int a=0;a<=3;a++)
void main(void)
{ {
For For for(int b=0;b<=3;b++)
for(int a=0;a<=12;a++) {
printf("%d x 2 = %d\n",a,a*2); printf("%d%d\t",a,b);
_getch(); }
printf("\n");
} }
_getch()
;}
#include<stdio.h>
#include<conio.h>v
oid main(void)
{
#include<stdio.h> int a=0,b;
#incl ude<conio. h> while(a<=3)
void main(void) 0x2=0
{ 1x2=2 {
2x2=4 b=0;
int a=0; 3x2=6
While while(a<=12) 4x2=8 While while(b<=3) 00 01 02 03
{ 5 x 2 = 10 { 10 11 12 13
printf("%d x 2 = %d\n",a,a*2); 6 x 2 = 12 printf("%d%d\t",a,b); 20 21 22 23
a++; 7 x 2 = 14 b++; 30 31 32 33
}
} 8 x 2 = 16
printf("\n");
_getch(); 9 x 2 = 18 a++;
} 10 x 2 = 20 }
11 x 2 = 22 _getch()
12 x 2 = 24 ;}
#include<stdio.h>
#include<conio.h>
void main(void)
#include<stdio.h> {
#i nclude<conio.h> int a=0,b;
void main(void) do
{
int a=0; {
do b=0;
Do while { Do while do
printf("%d x 2 = %d\n",a,a*2); {
a++; printf("%d%d\t",a,b);
b++;
} }while(b<=3);
while(a<=12); printf("\n");
_getch(); a++;
} }while(a<=3);
_getch();
}
67
This program of while loops takes continuous input until enter key is pressed.
Program Output
#include<stdio.h>
#include<conio.h>void main(void)
{ clrscr();
Type any sentence
int a=0; Iqra University
printf("Type any sentence\n"); Total Characters typed = 15
while(getche()!='\r')
a++;
printf("\nTotal Characters typed = %d",a); getch();
Exercise
Carefully observer the following program and write output with reasons.
Program Output
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
for(int a=0;a<=12;a++);
printf("%d x 2 = %d\n",a,a*2);
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
for(int a=0;1 ;a++);
printf("%d x 2 = %d\n",a,a*2);
_getch();
}
int a=0;
while(0)
{
printf("%d x 2 = %d\n",a,a*2);
a++;
}
_getch();
}
Write the output for the program on left
#include<stdio.h>
#include<conio.h>
void main(void)
{
int a=0,b;
while(a<=3);
{
b=0;
while(b<=3);
{
printf("%d%d\t",a,b);
b++;
}
printf("\n");
a++;
}
_getch();
}
68
Program:
Following program gives the sum of all numbers input by the user using while loop. The program will display the
sum when user enters 0 as input.
#include<conio.h>
#include<stdio.h>
void main()
{
system("cls"); // clear screen clrscr();
int num=-1;
int sum=0;
Understand the difference between break and continue by executing following programs.
break continue
int main() int main()
{ {
int i; int i;
double number, sum = 0.0; double number, sum = 0.0;
return 0; return 0;
} }
int a,b=0;
for(a=0;a<=3;a++)
{
b=0;
For While while(b<=3)
{
printf("%d%d\t",a,b);
b++;
}
printf("\n");
} 00 01 02 03
_getch(); 10 11 12 13
}
#include<stdio.h> 20 21 22 23
#include<conio.h>
30 31 32 33
void main(void)
{
int a=0,b;
while(a<=3)
{
While For for(b=0;b<=3;b++)
{
printf("%d%d\t",a,b);
}
printf("\n");
a++;
}
_getch();
}
Assignment
3. Write a program
using loops to generate following pattern.
1
121
12321
1234321
123454321
12345654321
1234567654321
123456787654321
12345678987654320
4. Write a program using loops to generate following output.
12 x 2 = 24
11 x 2 = 22
10 x 2 = 20
9 x 2 = 18
8 x 2 = 16
7 x 2 = 14
6 x 2 = 12
5 x 2 = 10
4 x 2 = 8
3 x 2 = 6
2 x 2 = 4
1 x 2 = 2
5. The Fibonacci sequence is a series where the next term is the sum of pervious two terms. Write a C
program to generate this sequence.