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

Memory Hierarchy

Memory Hierarchy A memory unit is an essential component in any digital computer since it is needed for storing programs and data. Typically, a memory unit can be classified into two categories: The memory unit that establishes direct communication with the CPU is called  Main Memory . The main memory is often referred to as RAM (Random Access Memory). The memory units that provide backup storage are called  Auxiliary Memory . For instance, magnetic disks and magnetic tapes are the most commonly used auxiliary memories. Apart from the basic classifications of a memory unit, the memory hierarchy consists all of the storage devices available in a computer system ranging from the slow but high-capacity auxiliary memory to relatively faster main memory. The following image illustrates the components in a typical memory hierarchy. Auxiliary Memory Auxiliary memory is known as the lowest-cost, highest-capacity and slowest-access storage in a computer system. Auxiliar

Objective Question of Computer Networking

  1.    Choose the correct meaning of the Greek word ‘tele’ in       context of telecommunication. A.   Near B.   Far C.   Never D.   Always   2.    Find the correct term used for the standards that have       been legislated by an officially recognized body.    A.   De jure B.   De facto C.   User standards D.   Channel standards   3.    Which agency developed standards for physical       connection interfaces and electronic signaling       specifications?      A.    ISO B.    ITU C.    ANSI D.    EIA   4.     Find full form of ANSI. A.    American Network Signal Institute B.    American National Signal Institute C.    American National Standards Institute D.    American Network Standards Institute   5.    Select the correct option to complete the following       statement.       The __________ defines the characteristics of the       interface between the devices and the transmission       medium. A.    Transport layer