Computer Science SLO Based Key Point Notes

************************************

👉👉👉 Computer Science 12th Class Notes (Main Page)

************************************

Unit 4: Control Structures


4.1.2. The if-else statement

The if-else statement is another type of decision-making statement that executes one block of statement when the condition is true and the other when it is false.

General Syntax

if (condition)
{
        statements;
}
else
{
        statements;
}


Flow chart




Explanation

The condition is evaluated.

Example:

Write a program that inputs marks and displays the result. If the marks are greater than or equal to 40 then display pass otherwise Fail.

#include<iostream.h>
#include<conio.h>
void main()
{
                clrscr();
                int marks;
                cout<<“Please enter your Marks: “;
                cin>>marks;
                if (marks >= 40)
                {
                cout<<“Congratulations, You have passed”;
                }
                else
                {
                cout<<“Sorry, Your are fail”;
                }
                getch();
}



Similar Examples as an assignment:

  1. Write a program that reads a number and prints whether it is an even or odd number.
  2. Write a program that reads a number and prints its square if the number is greater than 10 otherwise prints its cube.
  3. Write a program that reads three numbers and prints the largest one.
  4. Write a program that reads a letter and prints whether it is a lowercase or uppercase letter.


************************************
👉👉👉 Computer Science 12th Class Notes (Main Page)

************************************



(National Book Foundation - As Federal Textbook Board, Islamabad 
Based on National Curriculum Pakistan 2023-2024 and Onward prescribed by Federal Board of Intermediate and Secondary Education, Islamabad, and All Pakistan Boards) 

{Contact WhatsApp # +923339719149 for Class-XII & XI Computer Science Complete SLO-Based Key Points notes in pdf for preparing/delivering the Lectures}

Note:  Write me in the comments box below for any query and also Share this information with your class-fellows and friends.