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

Syntax-Computer Fundementals-Lab 04 -Lab Assignment, Exercises of Computer Fundamentals

This lab work is assigned by Nauman Shamim at Pakistan Institute of Engineering and Applied Sciences, Islamabad (PIEAS) for Computer Fundementals course. It covers following topics: Lab, Code, Execute, Compare, Enter, Value, Mod, Operator, Extend, Program

Typology: Exercises

2011/2012

Uploaded on 07/04/2012

waniaa
waniaa šŸ‡µšŸ‡°

7 documents

1 / 2

Toggle sidebar

Related documents


Partial preview of the text

Download Syntax-Computer Fundementals-Lab 04 -Lab Assignment and more Exercises Computer Fundamentals in PDF only on Docsity! 1 DCIS-PIEAS nauman@pieas.edu.pk Computer Fundamental and Programming Lab-04 Write the following code, execute it and compare the output Program-01 #include <stdio.h> #include <conio.h> #include <iostream.h> main() { int x,y; cin>>x; cin>>y; if(x>y) cout<<ā€X is greater than Yā€); getch(); } Exercise Modify the program so that it should execute as given below Program Execution Enter value for X: 23 Enter value for Y: 65 Y=65 is greater than X=23 Press any key to terminate the program. . Read this: The % is called the mod operator, it returns the remainder of a division. e.g. 13%5 = 13 / 5 = 2 (quotient) + 3 (remainder) = 3 17 %5= 17 / 5 = 3 (quotient) + 2 (remainder) = 2 56 % 13 = 4 (quotient) + 4 (remainder) = 4 We can check if a number is even or odd by using % (mod) operator if a number is even the remainder with 2 will be zero for odd number it will be a non zero number 3 %2 = 1 (3 is odd) 7 %2 = 1 (7 is odd) 6% 2 = 0 (6 is even) (have a look at the following program) Program-02 #include <stdio.h> #include <conio.h> #include <iostream.h> main(void) { int x; cout<<ā€Enter value for x:ā€; cin>>x; if( (x%2)==0) cout<<ā€X is an even integerā€<<endl; else cout<<ā€X is an odd integerā€<<endl; getch(); } Program-03 #include <stdio.h> #include <conio.h> #include <iostream.h> main() { int length, width; cout<<ā€Enter the length of the diagramā€<<endl; cin>>length; cout<<ā€Enter the width of the diagramā€<<endl; if(length==width) cout<<ā€The diagram is a squareā€<<endl; else cout<<ā€The diagram is a rectangleā€; getch(); } Exercise Extend the program, get length and width of two diagram from the user and check 1) the two diagrams are of same length and same width 2) which of the two diagram is a square and which one is a rectangle Hint: Do it on paper for two diagrams , develop a technique to compare diagrams and then write the program Program-04 (character input) #include <stdio.h> #include <conio.h> #include <iostream.h> main() { char ans; cout<<ā€Is today your birthday ? (Y/N) : ā€œ; cin>>ans; if(ans==ā€™yā€™ || ans == ā€˜Yā€™) cout<<ā€ Happy Birthday To You ā€œ<<endl ; else Docsity.com
Docsity logo



Copyright Ā© 2024 Ladybird Srl - Via Leonardo da Vinci 16, 10126, Torino, Italy - VAT 10816460017 - All rights reserved