

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Community
Ask the community for help and clear up your study doubts
Discover the best universities in your country according to Docsity users
Free resources
Download our free guides on studying techniques, anxiety management strategies, and thesis advice from Docsity tutors
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
1 / 3
This page cannot be seen from the preview
Don't miss anything!
Instructions
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