C++ Overview

June 30, 2019

     


                                       C language is a general-purpose programming language. It is similar to c language but, the syntax of c and c++ is a little bit different. In C we use printf for display statements and scanf for accepting the input from the user but, in C++ We use cout<< for the printing statements and cin>> for accepting input from the users. So first we see the simple program of C to print Hello World.

A simple program in C++

#include<iostream.h>    //standard I/O Streams

#include<conio.h>  //MSN-DOS compiler

void main()             //execution is started from this line

{                             //starting of program body

cout<<"HELLO WORLD";//to print the text on O/P screen

getch();                   //it holds the O/P screen

}                             //ending of program body

------------------------------------------------------------------------------------------

And save with extension .cpp

for eg.

simple.cpp//simple is the name of the file and .cpp is an extension of the file.

// Is one type of comment e.g.

void main();//Execution is started from this line.There are other functions available in c but, I will teach you in the next blog.......





C++ Overview C++ Overview Reviewed by Amit Waghmare on June 30, 2019 Rating: 5

Area of square

June 21, 2019


Area of Square


                    To calculate the area of the square we must know the formula area of the square is  area=side*side
                   To perform this operation in the c language first take the two variables as side and area to display or store the final answer. Then take the input from the user using scanf, then store that values in the side as shown in the code. Pass this variable in formulae to calculate the area of the square. Then the answer is stored in area variable, display area. Refer the following code to calculate the area of the square.  

C language code to calculate the area of square:

#include<stdio.h>

#include<conio.h>

int main()
 {
   int side, area;

   clrscr();

   printf("\nEnter the Length of Side : ");

   scanf("%d",&side);//to accept the side

   area=side*side;//formula to find the area of a square

   printf("\nArea of Square:%d",area);//To display the final answer

   getch();
}
-----------------------------------------------------------------------------------------
Output:
Enter the Length of Side: 5
Area of Square: 25

Area of square Area of square Reviewed by Amit Waghmare on June 21, 2019 Rating: 5

Area of Rectangle

June 21, 2019


Area of Rectangle

                          To calculate the area of the rectangle we must know the formula area of rectangle=Length*Breadth.
                              To perform this operation in the c language first take the three variables like length, breadth, and area to display or store the final answer. Then take the input from the user using scanf, then store that values in length and breadth as shown in the code. Pass these variables in formulae to calculate the area of the rectangle. Then the answer is stored in area variable, display area. Refer the following code to calculate the area of the rectangle.  

C language code to calculate area of Rectangle:

#include<stdio.h>
#include<conio.h>

void main()
{
   int length, breadth, area;

   clrscr();

   printf("\nEnter the Length of Rectangle:");

   scanf("%d",&length);           //to accept length of rectangle

   printf("\nEnter the Breadth of Rectangle:");

   scanf("%d",&breadth);        //to accept breadth of rectangle

   area=length*breadth;          //formula to find area of rectangle

   printf("\nArea of Rectangle:%d",area);//display area

   getch();
}
--------------------------------------------------------------------------------------
Output:
Enter the Length of Rectangle:6
Enter the Breadth of Rectangle:7
Area of Rectangle:42







Area of Rectangle Area of Rectangle Reviewed by Amit Waghmare on June 21, 2019 Rating: 5

Check given number is Palindrome or not.

June 20, 2019



                           
                                          First, we see what Palindrome number. If we are giving input as 1254 the program separates each and every integer no and rearrange it in a reverse manner and again see the original number is the same or not, the i.e original number is 1254 and reversed number is 4521, but 1254 is not equal to 4521. Then the output is like 1254 is not a Palindrome number. To see the demo of this code see the following code. 

C language code to check the given number is a palindrome or not:
#include<stdio.h>
#include<conio.h>
void main()
{
    int n, a = 0, r, ori_no;
    clrscr();
    printf("Enter an integer: ");
    scanf("%d", &n);

    ori_no = n;//to store the original number

    while( n!=0 ) //number must be a non zero integer number

    {
       //following formulas to check the given number is palindrome or not
r = n%10;
a = a*10 + r;
n /= 10;
    }

    // palindrome if ori_no and r are equal
    if (ori_no == a)
printf("%d is a palindrome.", ori_no);
    else
printf("%d is not a palindrome.", ori_no);

    getch();
}
-------------------------------------------------------------------------------
output:

Enter an integer:546
546 is not a palindrome.


Enter an integer:45654
45654 is not a palindrome.








Check given number is Palindrome or not. Check given number is Palindrome or not. Reviewed by Amit Waghmare on June 20, 2019 Rating: 5