Variables And Input operator in c++

 Variables 
Variable size 

                                                                                                                                       
Variable provides us  to store the data in System with named witch further can manipulate. In C++  Variable has a specific type, which tell the size and layout of the variable's memory. 

Program: write a program to find out the average of two number take input from user using variable  

Code:
#include<iostream>
using namespace std;

int  main()
{
float num1,num2, sum,average;
cout<<"Give two number to find out the average\n";
cout<<"Enter first number:";
cin>>num1;
cout<<"Enter Second number:";
cin>>num2;
sum=num1+num2;
average=sum/2;
cout<<"The average of "<<num1<<" and "<<num2<<" is "<<average;
}

OUTPUT:
Give two number to find out the average
Enter first number:10.6
Enter Second number:12.5
The average of 10.6 and 12.5 is 11.55
--------------------------------


Input operator 

In C++, it's used to take input from user using << . In the above example nun1 and num2 two input take from user. The identifier cin (pronounced 'C in') is a predefined object in C++ that corresponds to the standard input stream. Here , this Stream represents the keyword.

    The operator >> is known as extraction or get from operator. It extracts (or takes ) the value from the keyboard and assigns it to the variable on its right. This corresponds to the familiar scanf() operation, Like <<, the operator >> can also be overloaded 


Program: Write a program to find whether a given number is palindrome or not and take input from user.

Code:
#include<iostream>
using namespace std;
int main()
{
int rev,temp,num,digit=0;
cout<<"Enter a number";
cin>>num;
temp=num;
while(num!=0)
{
digit=num%10;
rev=rev*10+digit;
num=num/10;
}
if(rev==temp)
{
cout<<"The given  number is palindrome ";
}
else 
cout<<"The given  number is  not  palindrome ";

}


OUTPUT:
Enter a number145636541
The given  number is palindrome
--------------------------------

Program: Write a program to find the area of rectangle, square and circle. Taking input as radius length and breath of rectangle, side of square.


Code:
#include<iostream>
using namespace std;
int main()
{
 int  radius, l,b;
 float a;
 cout<<"Enter the radius of circle";
 cin>> radius;
 cout<<"Enter the lenth and brath of rectangle ";
 cin>>l;
 cin>>b;
 cout<<"Enter the side of square ";
 cin>>a;
 cout<<"\nThe area of rectangle is "<<l*b;
 cout<<"\nThe area of square is"<<a*a;
 cout<<"\nThe area of circle is "<<3.14*radius*radius;
}

OUTPUT:
Enter the radius of circle3
Enter the lenth and brath of rectangle 5
6
Enter the side of square 5

The area of rectangle is 30
The area of square is25
The area of circle is 28.26
--------------------------------  

Comments

Popular posts from this blog

CYBER SECURITY & CRACKING PASSWORDS

"The Dark Side of Social Media: How It Fuels Digital Addiction and Impacts Mental Health"

Online Platforms to Learn Coding