Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Declaring, Initializing and Using Variables-Computer Fundamentals-Lab Manuals, Exercises of Computer Fundamentals

Kavar Singh gave this Lab Manuals for subject of Computer Fundamentals at Central University of Haryana. Its about: Turbo , C\C , programs, Create, Objective , Predic,  Output, Declaring, Initializing, Variables

Typology: Exercises

2011/2012

Uploaded on 07/03/2012

prakash
prakash 🇮🇳

4.6

(10)

63 documents

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Com
p
uter Fundamental
Lab-02
Instructions
1. UseTurboC\C++forthefollowingprograms
2. CreateafolderCF_Labs
3. Createnewfolderforeachlabe.g.createfolder“lab02”andsaveallthefilesinthatfolderforthislab
4. Createnewfileforeachofthefollowingprogram
5. Foranyhelpcontactlabstafforfacultymemberavailableinthelab
6. Whileleavingthelabcloseallprogramsandshutdownthecomputers,takeabackupofyourcode
7. Donotdiscardthishandout
Objective
Understandtheworkingofdifferentformatspecifiers,Learntodeclaredifferentvariables,initializethem,usethem,and
printvaluesusingformatspecifiers.

For the following code, try to predict the output of the program, write it down on this handout, execute the program and then
match the out of your program with your predicted output.
#include <conio.h>
#include <stdio.h>
void main(void)
{
clrscr();
printf("This is year %d\n",2011);
printf("The sun will rise at %d:%d in the morning today \n",6,30);
printf("If we multiply %d with %d the answer will be %d \n",12,3,36);
printf("My friend %s came to visit me yesterday at %d-%d p.m.\n", "Ahmed",5,30);
printf("\n\t%d\n\t%d+\n\t----\n\t%d",10,20,30);
getch();
}
Your Predicted Output
Line-1
Line-2
Line-3
Line-4
Line-5
Line-6
Line-7
Line-8
TASK01 Predicttheout
p
ut
Docsity.com
pf3

Partial preview of the text

Download Declaring, Initializing and Using Variables-Computer Fundamentals-Lab Manuals and more Exercises Computer Fundamentals in PDF only on Docsity!

Computer Fundamental

Lab-

Instructions

  1. Use Turbo C\C++ for the following programs
  2. Create a folder CF_Labs
  3. Create new folder for each lab e.g. create folder “lab‐02” and save all the files in that folder for this lab
  4. Create new file for each of the following program
  5. For any help contact lab staff or faculty member available in the lab
  6. While leaving the lab close all programs and shutdown the computers, take a back up of your code
  7. Do not discard this handout

Objective Understand the working of different format specifiers, Learn to declare different variables, initialize them, use them, and print values using format specifiers.

For the following code, try to predict the output of the program, write it down on this handout, execute the program and then match the out of your program with your predicted output.

#include <conio.h> #include <stdio.h> void main(void) { clrscr(); printf("This is year %d\n",2011); printf("The sun will rise at %d:%d in the morning today \n",6,30); printf("If we multiply %d with %d the answer will be %d \n",12,3,36); printf("My friend %s came to visit me yesterday at %d-%d p.m.\n", "Ahmed",5,30); printf("\n\t%d\n\t%d+\n\t----\n\t%d",10,20,30); getch(); }

Your Predicted Output Line- Line- Line- Line- Line- Line- Line- Line-

TASK‐ (^01) Predict the output

Type the following programs and understand declaring, initializing and printing variables (only, int, char and float this itme) Program‐ 01 Simple declaration and initialization; #include <conio.h> #include <stdio.h> void main(void) { clrscr(); int A=100; int B=200; printf(“the value of A =%d\n “,A); printf(“The value of B = %d \n”,B); A=300; printf(“New value of A = %d\n”,A); printf(“Value of B = %d\n”,B); getche(); }

Program‐ 02 Other way of initialization and declaration #include <conio.h> #include <stdio.h> void main(void) { clrscr(); int A,B; int C,D=20;

A=100; B=200; C=A+B;

printf(“The value of A =%d\n “,A); printf(“The value of B = %d \n”,B); printf(“The value of C = %d\n”,C); printf(“The Value of D = %d\n”,D); getche(); } Program‐ 03 Using variables The objective of this program is to solve the equation (a+b) 2 = (a 2 +b^2 +2ab);

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

void main(void) { clrscr(); int a,b,c; int ans; a=12; b=9; printf(“ a =%d , b= %d \n“,a,b); ans=aa+bb+2ab; printf(“ (a+b)^2 = %d \n “,ans); getch(); }

Program‐ 03 Working with compound statement

The purpose of this program is to show the use of compound statement with variables

#include <conio.h> #include <stdio.h> void main(void) { clrscr(); int a,b,c; a=b=c=100; printf(“Starting value of a,b,c are\n“); printf(“a=%d,b=%d,c=%d\n“,a,b,c); a+=b; printf(“a+b = %d \n“,a); c=a=550; printf(“ New value of a b c are \n“); printf(“a=%d , b=%d , c=%d”,a,b,c); getch(); }

Program‐ 04 Increment and Decrement Operators The following program demonstrate use of increment and decrement operators we discussed in the class

TASK‐ (^02) Declaring ,Initializing and using Variables