Skip to main content

C++ Control Statement(कण्ट्रोल स्टेटमेंट)

हेलो Students 
आज हम लोग कण्ट्रोल स्टेटमेंट के बारे में पढेंगे | ये कण्ट्रोल स्टेटमेंट हमारी प्रोग्रामिंग लैंग्वेज में बहुत usefull होता है ये स्टेटमेंट आपको बताते है की हम प्रोग्राम को कैसे बना सकते है | 
तो चलते है। ...... 

C++ if-else

In C++ programming, if statement is used to test the condition. There are various types of if statements in C++.

  • if statement
  • if-else statement
  • nested if statement
  • if-else-if ladder

C++  if  Statement

The C++ if statement tests the condition. It is executed if condition is true.

if(Condition)
{

// Code to be executed

}



#include <iostream.h> //Input output Stream Header File


   int main ()

 {  

   int num = 10;  // num = variable, int= Data Type
  
            if (num % 2 == 0)  
  
            {    

                cout<<"It is even number";    

            }   

   return 0;  
}  

if num=10 and num is modulous 2 equal to Zero means मैंने २ से डिवाइड  पर Remainder is Zero So the number is Even Number .



C++ IF-else Statement


The C++ if-else statement also tests the condition. It executes if block if condition is true otherwise else block is executed.



if(condition)
{    
//code if condition is true    
}
Else
{    
//code if condition is false    
}    


C++ If-else Example


#include <iostream>  

int main () 
{  

   int num = 11;   

            if (num % 2 == 0)    
            {    
                cout<<"It is even number";    
            }   
            else  
            {    
                cout<<"It is odd number";    
            }  
   return 0;  
}  

C++ If-else Example: with input from user


#include <iostream.h>  

int main () 
{  
    int num;  

    cout<<"Enter a Number: ";  

    cin>>num;  

            if (num % 2 == 0)    
            {    
                cout<<"It is even number";    
            }   
            else  
            {    
                cout<<"It is odd number";    
            }  
   return 0;  
}  


Output:
Enter a number:11
It is odd number
Output:
Enter a number:12
It is even number

C++ IF-else-if ladder Statement


The C++ if-else-if ladder statement executes one condition from multiple statements.


if(condition1)
{    
//code to be executed if condition1 is true    
}else if(condition2)
{    
//code to be executed if condition2 is true    
}    
else if(condition3)
{    
//code to be executed if condition3 is true    
}    
...    
Else
{    
//code to be executed if all the conditions are false    
}    




Comments

Popular posts from this blog

Input Devices

Input Devices(इनपुट डिवाइस ) Input device enables the user to send data, information or control signals to computer. Central processing unit of computer receives the input and processes it to produce output. Some of the popular input devices are: Keyboard Mouse Scanner Joystick Light Pen Track ball Digitizer Microphone Magnetic Ink Character Recognition (MICR) Optical Character Reader (OCR) Keyboard (कीबोर्ड ) It is a basic input device that is used to enter data by pressing keys. It has different sets of keys for letters, numbers, characters and functions. QWERTY keyboard is the commonly used keyboard to enter data. Mouse (माउस) It is a hand held input device. It is used to move cursor or pointer across the screen. It generally has left and right button and a scroll wheel between them. Laptop computers come with a touch pad that works as a mouse. It lets you control the movement of cursor or pointer by moving your finger over the touchpad. Scanner (...

Types of computer

Types of Computer (कंप्यूटर के प्रकार ) We can categorize computer by two ways: data handling capabilities and size. On the basis of data handling capabilities , the computer is of  three  types: Analogue Computer (एनालॉग  कंप्यूटर ) Digital Computer (डिजिटल कंप्यूटर ) Hybrid Computer (हाइब्रिड कंप्यूटर ) 1) Analogue Computer(एनालॉग  कंप्यूटर ) Analog computers are designed to process analogue data. Analogue data is continuous data that changes continuously and cannot have discrete values such as speed, temperature, pressure and current. The analogue computers measure the continuous changes in physical quantity and generally render output as a reading on a dial or scale. Analogue computers directly accept the data from the measuring device without first converting it into numbers and codes. Speedometer and mercury thermometer are examples of analogue computers. 2) Digital Computer(डिजिटल कंप्यूटर) A digital computer is designed to perfor...

OUTPUT DEVICES

Output Devices(आउटपुट डिवाइस ) The output device displays the result of the processing of raw data that is entered in the computer through an input device. There are a number of output devices that display output in different ways such as text, images, hard copies, and audio or video. Some of the popular output devices are: Monitor CRT Monitor LCD Monitor LED Monitor Plasma Monitor Printer Impact Printers Character Printers Dot Matrix printers Daisy Wheel printers Line printers Drum printers Chain printers Non-impact printers Laser printers Inkjet printers Projector 1) Monitor(मॉनिटर) The monitor is the display unit or screen of the computer. It is the main output device that displays the processed data or information as text, images, audio or video. The types of monitors are given below. i ) CRT Monitor(सी आर  टी  मॉनिटर ) CRT monitors are based on the cathode ray tubes. They are like vacuum tubes which produce images in the ...