We have been working very hard since 2009 to facilitate in your learning Read More. We can't keep up without your support. Donate Now.

www.bit.ly/vucodes

+ Link For Assignments, GDBs & Online Quizzes Solution

www.bit.ly/papersvu

+ Link For Past Papers, Solved MCQs, Short Notes & More

Dear Students! Share your Assignments / GDBs / Quizzes files as you receive in your LMS, So it can be discussed/solved timely. Add Discussion

How to Add New Discussion in Study Group ? Step By Step Guide Click Here.

to determine whether a number is even or not,we can put a check on it

if(2*(number/2)==number)

cout"number is even";

i am not getting the logic behind this.because if we enter 3 then 3/2=1.5 and 1.5*2=3, so we get the number in either case.kindly help me understand this.i know that the code is correct.


+ http://bit.ly/vucodes (Link for Assignments, GDBs & Online Quizzes Solution)

+ http://bit.ly/papersvu (Link for Past Papers, Solved MCQs, Short Notes & More)

+ Click Here to Search (Looking For something at vustudents.ning.com?)

+ Click Here To Join (Our facebook study Group)


Views: 223

Replies to This Discussion

i think the code is not correct if we enter 3 then we get 1.5 and remainder will truncate which is .5 and the answer will be 2 here we use modules operater instead of division

but this code is given in handouts in lec9.i have run it and it worked

Sorry  Mrs.haris eski kiya logic ha mujay khud smjh ni a rahii net parr search ki ha wahn tou sare progs Modulus operator se he hain.......

ye divide operator e use hoga. but ye isay float value ma change nahi karay ga.

3/2= 1 answer lay ga.... jaisy remainder ma b 1 e aye ga.... n answer 2 aye ga. jo k even ha.

if(2*(number/2)==number)

ye code sahi hy kyn k number ==number means k agr hm 4 entr karin tu ans 4 a jae tu num is even

lekin agr hum 5 entr karin tu ans 5 ni ata it means k entred num is not even.

it means k jo num hm entr karin wo hi ans a jai tu num is even

waise b even num ko 2 se divide kar k multiply karin tu wo num dobara a jata hy.......

Aslamoalikum ..dera this is an integer division .. it mean that tha fractional part will b droped .. for example

3/2=1.5 ( In mathematics)

but 3/2=1 (in C++ here  the fraction part  0.5 will be dropped and the only 1 is your answer)

in case of ur question 3/2=1 and 1*2=2

 one more example 

5/2=2.5 (in mathematics)

5/2=2   ((in C++ here  the fraction part  0.5 will be dropped and the only 2 is your answer)

 

i hope this is the helpfull 4 u 

agr even he check krna hai tu simple if statement lago ..

if(x%2==0)

{cout"this number is even";}

else{cout"this number is odd";}

RSS

Latest Activity

+M.Tariq Malik replied to +M.Tariq Malik's discussion CS304 Assignment 01 Fall 2020 Solution / Discussion in the group CS304 Object Oriented Programming
3 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion CS302 Assignment 01 Fall 2020 Solution / Discussion in the group CS302 Digital Logic Design
12 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion CS507 Assignment No 01 Fall 2020 Solution & Discussion Due Date: 25-11-2020 in the group CS507 Information Systems
15 minutes ago
Nouman Butt liked + " J i y a " ♥'s discussion Agr............
20 minutes ago
Nouman Butt liked 彡JK彡 ❤️'s discussion **I've loved, I've lost But I've never changed** @KAMBO
20 minutes ago
Profile IconMinhaas, Zee Meer, Ubaid ullah and 21 more joined Virtual University of Pakistan
32 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion CS201 Assignment 01 Fall 2020 Solution / Discussion in the group CS201 Introduction to Programming
33 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion CS201 Assignment 01 Fall 2020 Solution / Discussion in the group CS201 Introduction to Programming
33 minutes ago
Muhammad Bilal replied to Hassan's discussion *** نیند چبھنے لگی ہے آنکھوں میں***
38 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion FIN611 GDB No 1 Fall 2020 Solution / Discussion in the group FIN611 Advanced Financial Accounting
47 minutes ago
+M.Tariq Malik liked +M.Tariq Malik's discussion FIN611 GDB No 1 Fall 2020 Solution / Discussion
47 minutes ago
+M.Tariq Malik replied to +M.Tariq Malik's discussion MTH100 Assignment 01 Fall 2020 Solution / Discussion in the group MTH100 General Mathematics
54 minutes ago

Today Top Members 

Looking For Something? Search Here

© 2020   Created by +M.Tariq Malik.   Powered by

Promote Us  |  Report an Issue  |  Privacy Policy  |  Terms of Service

.