Tuesday, August 14, 2012

If Construct....

Solve all the questions we discussed in class.
Use if construct  OR
Use if else Construct OR
Use Nested if Construct.

Syntax of if Construct is

if <condition>
begin

                    Print messages or values if the condition is TRUE

end



Syntax of if...else Construct is

if <condition>
begin

                    Print messages or values if the condition is TRUE

end
else

begin

                    Print messages or values if the condition is FALSE

end

Syntax of Nested IF Construct is

if <condition>
begin
       if <condition>
       begin   
                    Print messages or values if the condition is TRUE
        end
        else
        begin
                    Print messages or values of the condition is FALSE
        end   
end
else

begin

                    Print messages or values if the condition is FALSE

end






13 comments:

Unknown said...

Accept three numbers and display the largest number
Begin
Numeric = nNum1, nNum2, nNum3
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
Display “enter number3”
Accept nNum3
If (nNum1== nNum2) and (nNum1== nNum3)
Begin
Display “numbers are equal”
End
Else
Begin
If (nNum1> nNum2) and (nNum1> nNum3)
Begin
Display nNum1
End
Else
Begin
If (nNum1< nNum2) and (nNum2> nNum3)
Begin
Display nNum2
End
Else
Begin
Display nNum3
End
End
End
End
Compare the number and check the equality.
Begin
Numeric= nNum1, nNum2
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
If (nNum1==nNum2)
Begin
Display “the numbers are equal”
End
Else
Begin
Display “numbers are not equal”
End
End

Unknown said...

Accept the age of candidates. If the age entered is 18 or above, a message should be displayed “you are eligible to vote” if age is below 18 a message should be displayed “you are not eligible to vote”
Begin
Numeric nAge
Display “enter age”
Accept nAge
If (nAge>=18)
Begin
Display “you are eligible to vote”
End
Else
Begin
Display “you are not eligible to vote”
End
End
Accept two numbers and display the quotient as a result. In addition an error message should be displayed if the second number is zero or is greater than first number.
Begin
Numeric = nNum1, nNum2, nQuotient
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
Switch (nNum1/nNum2)
Begin
Case 1(nNum1>nNum2):
Display nQuotient
Break
Case 2(nNum1nNum2) and (nNum2>0)
Begin
nQuotient= nNum1/nNum2
Display “equal to”
Display nQuotient
End
Else
Begin
Display “Error”
End
End

Unknown said...

Accept two numbers and display the quotient as a result. In addition an error message should be displayed if the second number is zero or is greater than first number.
Begin
Numeric = nNum1, nNum2, nQuotient
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
If (nNum1>nNum2) and (nNum2>0)
Begin
nQuotient= nNum1/nNum2
Display “equal to”
Display nQuotient
End
Else
Begin
Display “Error”
End
End
Enter the year and determined whether the year is a leap or not. A leap year is a non centaury year that is divisible by 4. A centaury year is a year divisible by hundred such as 1900. A centaury year which is divisible by 400 such as 2000is also a leap year. Considered the year entered by the user is either 2000 or 1997.
Begin
Numeric= nYear
Display “enter year”
Accept nYear
Switch (leap year = nYear/4)
Begin
Case 1(nYear 2000):
Display “leap year”
Break
Case 2(nYear 1997):
Display “not leap year”
Break
Default
Display “invalid year”
End
End

Unknown said...

Compare two numbers and print the largest number
Begin
Numeric =nNum1, nNum2
Display “enter number1”
Accept nNum1
Display “enter number 2”
Accept nNum2
If nNum1==nNum2
Begin
Display “numbers are equal”
End
Else
Begin
If nNum1>nNum2
Begin
Display nNum1
End
Else
Begin
Display nNum2
End
End
End

Unknown said...

arshdeep kaur
1.Pseudocode to accept two numbers and print largest of them.
Sol: begin
numeric num1,num2
display 'enter a number'
accept num1
display 'enter a number'
accept num2
if num1==num2
begin
display 'the numbers are equal'
end
else
begin
if num1>num2
begin
if num1>num2
begin
display num1
end
else
begin
display num2
end
end
end
2.Consider another eg. where all candidates have to take 2 tests before appearing for
an interview. A candidate is selected for the interview round based on the scores of
2 tests. The individual scores in each tests should be greater than 75 & the avg should
be minimum of 80. A call letter for interview is to be sent to candidate who have been
selected & a rejection letter is to be sent to the rest.
Sol: begin
numeric marks1,marks2,navg
display'enter the marks for test1'
accept mark1
display'enter the marks for test2'
accept marks2
avg=(marks1+maarks2)/2
if(mark1>75 && marks2>75 && navg>80)
begin
display'call letter'
end
begin
display'rejection letter'
end
end
3.Pseudocode for switch case
Sol: begin
numeric nNUM1
display 'enter a number'
accept nNUM1
switch(nNUM1)
begin
case1:
display "one"
break
case2:
display "two"
break
case3:
display "three"
break
default:
display "invalid number"
end
end
4.Pseudocode to accept 3 no's & find largest one.
Sol: begin
numeric nNUM1,nNUM2,nNUM3
display'enter nNUM1,nNUM2,nNUM3'
accept nNUM1,nNUM2,nNUM3
if(num1>num2 && num1>num3)
begin
display'NUM1'
end
else if(num2>num3)
begin
display'NUM2'
end
else
begin
display'NUM3'
end
end
5.Pseudocode to accept a number and then find out wheather or not the number is
divisible by 5
Sol: begin
numeric num1
display 'enter a number'
accept num1
if(num1%5==0)
begin
display 'number is divisible by 5'
end
else
begin
display 'number is not divisible by 5'
end
end
6.Pseudocode to accept age of a candidate. If age entered is 18 or above 18 then print
"You are eligible to vote". If age entered is below 18 then print "You are not eligible
to vote".
Sol: begin
numeric num1
display 'enter a number'
accept num1
if(num1>=18)
begin
display'You are eligible to vote'
end
else if(num1<18)
begin
display'You are not eligible to vote'
end
end
7.Pseudocode to enter a year and determine wheather the year is leap year or not. A
leap year is a non-century year that is divisible by 4. A century year is a year divisible
by 100, such as 1900. A century year which is divisible by 400, such as 2000 is also
a leap year. Consider the year entered by user is either 2000 or 1997
Sol: begin
numeric nYear
display 'enter year'
accept nYear
switch(leap year=nYear/4)
begin
case1:(nYear=1997)
display 'not a leap year'
break
case2:(nYear=2000)
display 'leap year'
break
default
display'invalid'
end
end
8.Pseudocode to accept 2 numbers and display the quotient as aresult. In addition an
error message should be displayed if the second number is zero or is greater than the
thr first number.
Sol: begin
numeric nNUM1,nNUM2,nQuotient
display 'enter a number'
accept nNUM1
display 'enter a number'
accept nNUM2
if (nNUM1>nNUM2) and (nNUM2>0)
begin
nQutiont =nNUM1/nNUM2
display'qutiont'
display'equal to'
end
else
begin
display'error message'
end
end

Unknown said...

1. The following pseudocode accept two numbers and print the larger of the two numbers...

sol...begin
numeric nNum1,nNum2
display "enter number1:"
accept nNum1
display "enter number2:"
accept nNum2
if nNum1==nNum2
begin
display'the number are equal'
end
else
begin
if nNum1>nNum2
begin
display 'nNum1'
end
else
begin
display 'nNum2'
end
end
end

2. Write the pseudocode to accept a number and than find out weather or not the number is divisible by five.

sol..begin
numeric num1
display "enter a number"
accept num1
if(num1%5==0)
begin
display 'number is divisible by 5'
end
else
begin
display 'number is not divisible by 5'
end
end
3. write the pseudocode to accept three number and display the largest number.

sol..begin
Numeric nNum1, nNum2, nNum3
display "enter number1"
accept nNum1
display "enter number2"
accept nNum2
display "enter number3"
accept nNum3
if (nNum1== nNum2) AND (nNum1== nNum3)
begin
display "numbers are equal"
end
else
begin
if (nNum1> nNum2) AND (nNum1> nNum3)
begin
display 'nNum1'
end
else
begin
if (nNum1< nNum2) AND (nNum2> nNum3)
begin
display 'nNum2'
end
else
begin
display 'nNum3'
end
end
end
end

4. Enter a year and determine whether the year is leap year or not. A leap year is non-century year that ia divisible by 4. A century year is a year divisible bt 100, such as 1900. A century year, which is divisible by400,such as 2000, is also a leap year. Consider the year entered by a user is either 2000 or 1997.

sol...begin
numeric nYear
display "enter year"
accept nYear
switch(leap year=nYear/4)
begin
case1:(nYear=1997)
display 'not a leap year'
break
case2:(nYear=2000)
display 'leap year'
break
default:
display'invalid year'
end
end

Unknown said...

5. Write the pseudocode to accept two numbers and display the quotient as a result. In addition, an error message should be displayed if the second number is zero or is greater than the first number.

sol..begin
numeric nNUM1,nNUM2,nQuotient
display "enter first number"
accept nNUM1
display "enter second number"
accept nNUM2
if (nNUM1>nNUM2) AND (nNUM2>0)
begin
nQuotient =nNUM1/nNUM2
display'quotient'
display'equal to'
end
else
begin
display'error message'
end
end

6.. Consider another example where all candidates have to take two tests before appearing for an interview. A candidate is selected for the interview round based on the scores of the two tests . The individual score in each test should be greater than 75 and the average score accros the two tests should be a minimum of 80. a call letter for the interview is to be sent to candidates who have been selected and a rejection letter is to be sent to thee rest.

sol..begin
numeric marks1,marks2,navg
display'enter the marks for test1'
accept marks1
display'enter the marks for test2'
accept marks2
avg=(marks1+maarks2)/2
if(mark1>75 && marks2>75 && navg>80)
begin
display'call letter'
end
begin
display'rejection letter'
end
end


7.SWITCH CASE
begin
numeric nNum1
display "enter number"
accept nNum1
switch(nNum1)
begin
case1:
display "one"
break
case2:
display "two"
break
case3:
display "three"
break
default:
display "invalid no."
end
end


8. Write the pseudocode to accept the age of a candidate . If the age entered is 18 or above , a message should be displayed "you are eligible to vote". If the age entered is below 18 "you are not eligible to vote".

sol...begin
numeric num1
display "enter a number"
accept num1
if(num1>=18)
begin
display'eligible to vote'
end
else
begin
if(num1<18)
begin
display'not eligible to vote'
end
end
end

Unknown said...

1:-Accept three numbers and display the largest number
Begin
Numeric = nNum1, nNum2, nNum3
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
Display “enter number3”
Accept nNum3
If (nNum1== nNum2) and (nNum1== nNum3)
Begin
Display “numbers are equal”
End
Else
Begin
If (nNum1> nNum2) and (nNum1> nNum3)
Begin
Display nNum1
End
Else
Begin
If (nNum1< nNum2) and (nNum2> nNum3)
Begin
Display nNum2
End
Else
Begin
Display nNum3
End
End
End
End



2:-Compare the number and check the equality.
Begin
Numeric= nNum1, nNum2
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
If (nNum1==nNum2)
Begin
Display “the numbers are equal”
End
Else
Begin
Display “numbers are not equal”
End
End



3:-Accept the age of candidates. If the age entered is 18 or above, a message should be displayed “you are eligible to vote” if age is below 18 a message should be displayed “you are not eligible to vote”
Begin
Numeric nAge
Display “enter age”
Accept nAge
If (nAge>=18)
Begin
Display “you are eligible to vote”
End
Else
Begin
Display “you are not eligible to vote”
End
End .


4:-Pseudocode to accept a number and then find out wheather or not the number is
divisible by 5
Sol: begin
numeric num1
display 'enter a number'
accept num1
if(num1%5==0)
begin
display 'number is divisible by 5'
end
else
begin
display 'number is not divisible by 5'
end
end




5:-Enter a year and determine whether the year is leap year or not. A leap year is non-century year that ia divisible by 4. A century year is a year divisible bt 100, such as 1900. A century year, which is divisible by400,such as 2000, is also a leap year. Consider the year entered by a user is either 2000 or 1997.

sol...begin
numeric nYear
display "enter year"
accept nYear
switch(leap year=nYear/4)
begin
case1:(nYear=1997)
display 'not a leap year'
break
case2:(nYear=2000)
display 'leap year'
break
default:
display'invalid year'
end
end


6:-Accept two numbers and print the largest of the two numbers?
Begin
Numeric nNum1,nNum2
Display”enter number1”
Accept nNum1
Display”enter number2”
Accept nNum2
If nNum1==nNum2
Begin
Display ‘the number are equal’
End
Else
Begin
If nNum1>nNum2
Begin
Display nNum1
End
Else
Begin
Display nNum2
End
End
End.

7:-
Begin
Numeric nNum1
Display”enter number”
Accept nNum1
Switch(nNum1)
Begin
Case1:
Display”one”
break
Case2:
Display”two”
break
Case3:
Display”three”
Break
Default:
Display”invalid number”
End
End.

Unknown said...

Q1 the following pseudocode segment compares two nos and checks the equality.
Begin
Numeric nNum1,nNum2
Display “enter two numbers”
Accept nNum1,nNum2
If (nNum 1=nNum2)
Begin
Display “the numbers are equal”
End
Else
Begin
Display “the numbers are not equal”
End
End

Q2 The following pseudocode accepts two numbers and prints the larger of two numbers.
Begin
Numeric nNum1,nNum2
Accepts nNum1
Accepts nNum2
If nNum1==nNum2
Begin
Display “the numbers are equal”
End
Else
Begin
If nNum1>nNum2
Begin
Display nNum1
End
Else
Begin
Display nNum2
End
End
End

Q4 Accept a number and then find out whether or not the number is divisible by 5
Begin
Numeric nNum1,
Display “enter a number”
Accept nNum1
If(nNum1%5=0)
Begin
Display “number is divisible by 5”
End
Else
Begin
Display”number is not divisible by5”
End
End

Unknown said...

Q5 write the pseudocode to accept two numbers and display the quotient as a result . in addition an error message should be displayed if the second number is 0 or is greater than the first number.
Begin
Numeric nNum1,nNum2
Accept nNum1,nNum2
Display nNum1,nNum2
If (nNum1/num2)
Begin
Display”the quotient as result”
End
Else
Begin
Display”if the nNum2 is equal to 0 or nNum2>nNum1”
End
End

Q6 write the pseudocode to accept the age of the candidate . if the age entered is 18 or above a message should be displayed you are eligible to vote . if the age entered is below the 18 you are not eligible to vote.
Begin
Numeric nage
Display enter age
Accept nage
If (nage>=18)
Begin
Display”you are eligible to vote”
End
Begin
Else
Display”you are not eligible to vote”
End
end

CODING BASED ON SWITCH CASE STATEMENT

Q1 Begin
Numeric nNum1
Display “enter a no”
Accept nNum1
Switch (nNum1)
Begin
Case1:
Display “one”
Break
Case2:
Display “two”
Break
Case3:
Display “three”
Break
Default
Display “invalid no”
End
End

Q2 enter a year and determine whether the year is leap year or not . a leap year is non century year that is divisible by 4 . a century year is year divisible by 100 such as 1900 . a century year which is divisible by 400 such as 2000 is also a leap year . consider a year entered by user is either 2000 or 1997
Begin
Numeric nyear
Display “enter year”
Accept nyear
Switch(leap year=nyear/4)
Begin
Case1:(nyear=2000)
Display leap year
Break
Case2:(nyear=1997)
Display not a leap year
Break
Default
Display”invalid year”
End
End

Unknown said...

Accept three numbers and display the largest number
Begin
Numeric = nNum1, nNum2, nNum3
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
Display “enter number3”
Accept nNum3
If (nNum1== nNum2) and (nNum1== nNum3)
Begin
Display “numbers are equal”
End
Else
Begin
If (nNum1> nNum2) and (nNum1> nNum3)
Begin
Display nNum1
End
Else
Begin
If (nNum1< nNum2) and (nNum2> nNum3)
Begin
Display nNum2
End
Else
Begin
Display nNum3
End
End
End
End
Compare the number and check the equality.
Begin
Numeric= nNum1, nNum2
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
If (nNum1==nNum2)
Begin
Display “the numbers are equal”
End
Else
Begin
Display “numbers are not equal”
End
End
Compare two numbers and print the largest number
Begin
Numeric =nNum1, nNum2
Display “enter number1”
Accept nNum1
Display “enter number 2”
Accept nNum2
If nNum1==nNum2
Begin
Display “numbers are equal”
End
Else
Begin
If nNum1>nNum2
Begin
Display nNum1
End
Else
Begin
Display nNum2
End
End
End

Unknown said...

Accept two numbers and display the quotient as a result. In addition an error message should be displayed if the second number is zero or is greater than first number.
Begin
Numeric = nNum1, nNum2, nQuotient
Display “enter number1”
Accept nNum1
Display “enter number2”
Accept nNum2
If (nNum1>nNum2) and (nNum2>0)
Begin
nQuotient= nNum1/nNum2
Display “equal to”
Display nQuotient
End
Else
Begin
Display “Error”
End
End
Enter the year and determined whether the year is a leap or not. A leap year is a non centaury year that is divisible by 4. A centaury year is a year divisible by hundred such as 1900. A centaury year which is divisible by 400 such as 2000is also a leap year. Considered the year entered by the user is either 2000 or 1997.
Begin
Numeric= nYear
Display “enter year”
Accept nYear
Switch (leap year = nYear/4)
Begin
Case 1(nYear 2000):
Display “leap year”
Break
Case 2(nYear 1997):
Display “not leap year”
Break
Default
Display “invalid year”
End
End

Unknown said...

t