c++ programming examples

C++ programming examples

C ++ में Programming हम शून्य स्तर से शुरू करेंगे, यहां आपको कुछ बेसिक programs के उदाहरण दिए गए हैं –

इस पेज में numbers को जोड़ने से सम्बंधित programs दिए गए हैं जो इस प्रकार दिए गए हैं –

printing of Two number Total in C++

#include<iostream.h>
#include<conio.h>

void main(void) // because function void type so void as argument in function
 {
  int num1,num2,sum; // three variable declare
  cout<<"Enter any two number: "; 
  cin>>num1>>num2;

   sum = num1+num2; // variable sum hold the total of variable a and b total 
   
   cout<<"Addition: "<<sum; // printing value of sum(which is total of a and b)
 
 getch();
}

OUTPUT

Enter any two number: 4 5
Addition: 9

Explanation:

program में, पहले 3 int type variables declare किए गए हैं,

int num1,num2,sum;

यहां पर variable num1 और variable num2 user द्वारा दिए गए input हैं जबकि variable इन दो variables के total को store करेगा।

sum = num1+num2;

लेकिन क्या होगा अगर हम दो के बजाय तीन संख्याओं को जोड़ना चाहते हैं?

यहां एक और उदाहरण है जहां हम उपयोगकर्ता द्वारा दिए गए तीन नंबर को जोड़ते हैं।

add three number of Total given by the user in C++

#include<iostream.h>
#include<conio.h>

void main(void)
{
  int num1,num2,num3,sum;
  cout<<"Enter any four number: "; 
  cin>>num1>>num2>>num3;
  
  sum = num1+num2+num3; 

  cout<<"nTotal: "<<sum; 
   // cout<<"Total: "<<num1+num2+num3; // also work
 getch();
}

OUTPUT

Enter any three number: 4 3 5
Total: 12

ऊपर दिए गए program से पता चलता है किहमें जितने numbers को जोड़ना होगा हमें program में उतने ही variables declare करने होंगे।

निचे दिए गए program में हमने 3 संख्याओं को multiply किया गया है –

multiply any three number in C++

#include<iostream.h>
#include<conio.h>

 int main()
 {
   int a,b,c,mul;
   cout<<"Enter any three number: "; 
   cin>>a>>b>>c;

  mul = a*b*c; // multiply variables a,b and c. and store result variable mul
  
  cout<<"Total: "<<mul; // print variable mul value
 
getch();
return 0; // using return because function main() is not void type 
}

OUTPUT

Enter any three number: 4 5 3
Multiply: 60

निचे दिए गए program में हमने तीन task को एक साथ perform किया गया है –

all in one find out any two number total,subtraction ,multiply and average in c++

#include<iostream.h>
#include<conio.h>

 void main(void) // no value return so void as argument(optional)
 {
   clrscr(); // to clear previous screen
   int num1,num2,sub,sum,mul,av;
 
   cout<<"Enter any two number: "<<endl; // endl used for next line like enter button 
   cin>>num1>>num2;
   
// storing result one by one of variable a and b 
   sum = num1+num2; 
   sub = num1-num2;
   mul = num1*num2;
   av = sum/2;

   //printing values one by one
   cout<<"nAddition: "<<a<<"+"<<b<<" = "<<sum;
   cout<<"nSubstrac: "<<a<<"-"<<b<<" = "<<sub;
   cout<<"nMultiply: "<<a<<"x"<<b<<" = "<<mul;
   cout<<"nAverage : ("<<a<<"/"<<b<<")/2 = "<<av;

 getch();
}

OUTPUT

Enter any two number: 4 5
Addition: 4+5 = 9
Substrac: 4-5 = -1
Multiply: 4x5 = 20
Average : (4/5)/2 = 4

 

 

 

v

Leave a Reply

Your email address will not be published.