Sunday, 1 October 2017

write a program to reverse a number in c++

C++ Program to Reverse a Number

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop


What is reverse Number?

This reverse of number means reverse the all position of all number.it is also know as the reverse.
 we entered value from user then we reverse an number using the while loop in c++,

Example of reverse number

12345678
87654321 this is reverse number



Example.C++ Program to reverse an number

#include<iosteam>
#include <conio.h>
using namespace std;
int main ( )
 {
  int onum,reminder,sum=0,num;
cout<<"Please enter the number";

   cin>>onum;
  num=onum;
   //this condition is use to check num not = zero. 

    while(num!=0)
{
   reminder=num%10;
   reverse = (reverse*10) + reminder;
   num = num / 10;
}
   if(sum==onum)


cout <<onum<<"is reverse number";

return 0;
getch ();
}
}


Output
------------------------------------------;
Please enter the number           ;
123456789                                       :
987654321 is reverse number    ---------


In above program ,a positive number enter by the user which value is stored in onum variable.


After that,we copied onum into num variable
num=onum;

we using the while loop for unit number num  !  = 0 is false

Inside the while loop , last digit is different  from num by the operation digit = num % 10;. This digit is cubed and added to the variable sum.

Finally reverse digit is displayed on the monitor



You should have basic programming knowledege
like syntax and variable and if else statement or for loop that is must learn before starting
the program.
Which people want to learn programming language.this website very beneficial for those people.

Saturday, 30 September 2017

write a program to check number armstrong or not

C++ Program to check Armstrong number or not.

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop

What is armstrong number?


The Armstrong number n which positive number equal to sum of cube power of individual number.It is also known as Armstrong number,

Example of armstrong number.


153=[1×1×1+5×5×5+3×3×3]  153
13=[1×1×1+3×3×3]28 is not armstrong


In this programe we must understand programming language and for loop and  if else statement. 





Example 1: Check Armstrong Number (entered by user)


#include<iosteam>
#include <conio.h>
int main ( )
 {
  int onum,reminder,sum=0,num;
cout<<"please enter the any positive number";

   cin>>onum;
  num=onum;
   //this condition is use to check num not = zero. 

    while(num!=0)
{
   reminder=num%10;
   sum=sum+reminder*reminder*reminder;
   num=num/10;
}
   if(sum==onum)

   cout <<onum <<"This number is    armstrong number";

else

cout <<onum<<"This number is not             armstrong";

return 0;
getch ();
}
}

Result
------------------------
Please enter the any positive numer
153
153 This number is Armstrong


In above program ,a positive number enter by the user which value is stored in onum variable. 

After that,we copied onum into num variable
num=onum;

Inside the while loop , last digit is different  from num by the operation digit = num % 10;. This digit is cubed and added to the variable sum.

Now, the last digit is removed using the statement num /= 10;.

In the next cycle of while loop, second last digit is different , cubed and add into sum variable.

This simultaneous until no digits are left in num. Now, the total sum sum is compared to the original digit oum.

Friday, 29 September 2017

write a program to find the prime number or not in c++

C++ Program to check whether number is prime or not.

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop

What is prime number?



The prime number mean which postive integer number is divided by 1 or itself.
The prime number such as 13 that is division itself and 1.


In this example we show the prime number is [1,2,3,5,7,11,13,17,19,22]





Example 1: Program to Check Prime Number given by user.


#include<iosteam>
#include <conio.h>
int main ( )
 {
  int m,j,flag=0;
cout<<"please enter the any positive number";
   cin>>m;
for(j=2;j <=n/2;i++)
  {
   //this condition is use for non prime
    if (m%j==0)
{
      flag=1;
       break;
}
}

if(flag==0)
cout <<m <<"This number is prime";
else
cout <<m <<"This number is not prime";
return 0;
getch ();
}
}

Result
------------------------
Please enter the any positive numer
8
8 This number is not prime



Example2: Program to Check Prime Number



#include<iosteam>
#include <conio.h>
int main ( )
 {
  int m=7,j,flag=0;

for(j=2;j <=n/2;i++)
  {
    if (m%j==0)
{
      flag=1;
       break;
}
}

if(flag==0)
cout <<m <<"This number is prime";
else
cout <<m <<"This number is not prime";
return 0;
getch ();
}
}

Output
------------------------

7 This number is prime


Thursday, 28 September 2017

write a program find factorial of any number in c++

C++ Program to Find Factorial


In this program,we learn to calculate the factorial of num using for loop in this program.

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop

Write a program to find the factorial of any number.


We every number is equal to 1*2*3*4*5*..n.You must have basic knowledege of programming language before start program.To understand this program ,you must have the knowledge of c++ programming topics such as for loop and basic syntax.





For any number ,This is factorial number is given by


[factorial = 1*2*3*4*5*6*..........*n]




Example 1: Find Factorial of a given number by user

In this factorial program  given value through the user.

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int n=;
int fact;

 cout << "Plz enter the any postive number";
 cin>>n;

for(i=1;i<=n;i++)
{
fact=fact*i;
}
 cout << n<<"Factorial number is="<<fact;

return 0
getch();
}


output
----------------------------------------------
Plz enter the any postive number
5

The greatest number is:120



Example 2: Find Factorial of a given number


#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
int n=4;
int fact;


for(i=1;i<=n;i++)
{
fact=fact*i;
}
 cout << n<<"Factorial number is="<<fact;

return 0
getch();
}

Result
----------------------------------------------


The greatest number is:120



You should have basic programming knowledege
like syntax and variable and if else statement or for loop that is must learn before starting
the program.


Wednesday, 27 September 2017

Write a program to find the greatest of three numbers

C++ Program to Find The Largest Number Among Three Numbers.


You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop

In this programe,you will fimd the largest number between three numbers using if ,if else ,nested if else statement.



In this program,enter three values by user.
This program used more than one way.






Example1:Find Largest Number Using if Statement

#include<iostream>
#include<conio.h>
using namespace std;

int main()
{
         int num1, num2,num3;

        cout << "Plz Enter three numbers";
        cin >> num1;
        cin >>num2;
        cin >>num3;
     
     if(num1>=  num2 &&  num1 >=num3) 
          {
             cout <<  "The greatest number is :"<<n2;
           }
       if(num2>=  num1 &&  num2 >=num3) 
        {
      cout << "The greatest number is :"<<num2;
          }

       if(num3>=  num1 &&  num3 >=num2) 
        {
      cout << "The greatest number is :"<<num3;
          }

     return 0;
    getch();
}

output
----------------------------------------------
Plz Enter three number
5
8
9
The greatest number is:9

Example2:Find Largest Number Using if,else statement


#include<iostream>
#include<conio.h>
using namespace std;

int main()
    {
         int num1, num2,num3;

        cout << "Plz Enter three numbers";
        cin >> num1>>num2 >>num3;

       if((num1>=num2) && (num1>=num3))
                 cout << "The greatest number is:<<num1;
          else if((num2 >= num2) && (num2 >= num3)
                 cout << "The greatest number is:<<num2;
      else 
                 cout << "The greatest number is:<<num3;


         return 0;
        getch();
    }
            

output
----------------------------
Plz Enter three number
5
8
9
The greatest number is:9


Example3:Find Largest Number Using nested if..else statement


#include<iostream>
#include<conio.h>
using namespace std;

int main()
    {
         int num1, num2,num3;

        cout << "Plz Enter three numbers";
        cin >> num1>>num2 >>num3;

       if(num1>=num2) 
        {
                 if(num1>=num3)
                          cout << "The greatest number is:<<num1;
          else 
                          cout << "The greatest number is:<<num3;
        }
      else 
        {
             if(num2 >= num3)

                          cout << "The greatest number is:<<num2;
         else 
                          cout << "The greatest number is:<<num3;

       }
         return 0;
        getch();
    }



output
----------------------------
Plz Enter three number
5
8
9
The greatest number is:9

Tuesday, 26 September 2017

write a program to check leap year or not in c++


C++ Program to Check Leap Year

This program check given number is year leap or not.

You must have basic knowledge of  C++ programming language and variable  , while loop and if..ealse and for loop



Leap year that is given number divided by
4.if number is perfectly divided to 4 its also
known as leap year.
leap year such as 2004,2008,2012,2016,2020
2024,2028





Example: Check given a year is leap year or not


#include <iostream>
#include <conio.h>
using namespace std;

int main()
{
    int y;

    cout << "Plz Enter a year: ";
    cin >> y;

    if (y % 4 == 0)
    {
        if (y % 100 == 0)
        {
            if (y % 400 == 0)
                cout << y << " leap year.";
            else
                cout << y << "not leap year.";
        }
        else
            cout << y << " leap year.";
    }
    else
        cout << y << " not leap year.";

    return 0;
}
Output

Plz Enter a year: 2012
2012 leap year.





The  people who want to learn programming language.this website very beneficial for those people.

Write a Program to Check Whether a Number is Even or Odd

C++ Program to Check Whether a Number is Even or Odd.


In this example,we used if...else statement to check given a number even or odd.

Even number. An even number which number is divided by 2 its called odd number.example 2,6,8,10


Odd number.An even number which number is not divided by 2 its called odd number.example 1,3,5,7,11

Example 1: Check Whether Number is Even or Odd using if or else

#include <iostream>
#include <conio.h>
using namespace std;
int main ()
    {
      int n;

   cout <<"plz enter number";
   cin>>n;

     if (n%2==0)
      cout << "Number is even";
        else
       cout <<"Number is odd";

       return 0;
       getch();
    }

      Output
_________________________
Number is even



Example 2: Check Whether Number is Even or Odd using ternary operators



include <iostream>
#include <conio.h>
using namespace std;
int main ()
    {
      int n;

   cout <<"plz enter number";
   cin>>n;

 (n%2==0)? cout <<"even":
  cout <<number is odd";

    return 0;
      getch ();
    }

output
---------------
Enter the number user
n= 7
number is odd





The people who want to learn programming. this website very beneficial for those peoples.

Sunday, 24 September 2017

What is c++ structure

Structures


Struture is collection of diffrent data type of variable.Struture is way to create variables and we create member.struture same as class.

Structures are variables which have several types; each type of the object can have different types.
Each type of the structure is called a member of the structure.

how to declare a sruture in c++ programming

struct keyword through we define struture name (structure name as identifier)

example...

struct book
{
int bookid;
char title[30];
float price;
};
A structure data type called Book can hold all this information:

struct book{

int bookid;
char title[30];
float price;

};

before the final semicolon, At the end of the structure's definition, we can define one or more structure variables.

There is also another way of declaring variables given below,
struct student s1;

# Initialization
Structure members can be initialized at declaration. This is same as the initialization of arrays; the values are listed inside braces. The structure declaration is preceded by the keyword static.

static struct book b1 ={11,''java'',20,345.45};

how to access member of structure?

To access a given member the dot notation is use. The ''dot'' is called the member access operator

struct book b1;
b1.bookid = 11;
b1.title = "java"
b1.price = n345.45

example c++ structure

#include<iostream.h>
#include<conio.h>
struct book
{

          int bookid;
         char title[30];
         float price;

};
void main()
{
book b1;
     
        cout <<  "Please Enter the book id';
        cin >> b1.bookid << endle;
        cout <<  "Please Enter the book title';
        cin >> b1.title << endle;
        cout <<  "Please Enter the book price';
        cin >> b1.price << endle;
       
        cout << "\n Display the book record." << endle;
        cout << "book id"b1.booidid;
         cout << "title"b1.title;
         cout << "price"b1.price;
      
      getch();
       }

    Output
-------------------------------------------------------
Display the book record.

 Book id  = 11
 Title       = jave
 Price      =345.45

Thursday, 21 September 2017

What is Pointer in c++

Pointer is a variable that stores the address of another variable. They can make a few things substantially less demanding, help enhance your program's productivity, and even enable you to deal with boundless measures of information.

Pointer is utilized to allot memory powerfully i.e. at run time. The variable may be any of the information sort, for example, int, glide, scorch, twofold, short and so on.

Language structure :

To declare a pointer, we utilize a reference bullet between the information sort and the variable name

Pointers require a touch of new sentence structure since when you have a pointer, you require the capacity to both demand the memory area it stores and the esteem put away at that memory area.

data_type *ptr_name;

example :

int *a; roast *a;

Where, * is utilized to mean that ''an'' is pointer variable and not a typical variable.

In this unique situation, the mark is not an augmentation

Key focuses to recall about pointers:

# Normal variable stores the esteem though pointer variable stores the address of the variable.

# The substance of the pointer dependably be an entire number i.e. address.

# Always pointer is introduced to invalid, i.e. int *p = invalid.

# The estimation of invalid pointer is 0.

# and image is utilized to get the address of the variable.

# * image is utilized to get the estimation of the variable that the pointer is indicating.

# If pointer is alloted to NULL, it implies it is indicating nothing.

# Two pointers can be subtracted to know what number of components are accessible between these two pointers.

# But, Pointer expansion, increase, division are not permitted.

# The measure of any pointer is 2 byte (for 16 bit compiler).

Since pointers just hold addresses, when we dole out an incentive to a pointer, the esteem must be an address. To get the address of a variable, we can utilize the address-of administrator (and)

Illustration program for pointer:

#include

int primary()

{

int *ptr, q;

q = 50;

/* address of q is doled out to ptr */

ptr = &q;

/prints address held in ptr, which is &q

cout << ptr;

/* show q's esteem utilizing ptr variable */

cout << *ptr;

return 0;

}

The invalid pointer

Here and there we have to influence our pointers to point to nothing. This is known as an invalid pointer. We dole out a pointer an invalid an incentive by setting it to address 0: int *ptr;

ptr = 0;

/dole out deliver 0 to ptr

or, on the other hand essentially

int *ptr = 0;

/dole out deliver 0 to ptr

C++ Pointer Arithmetic

As you understand pointer is an address which is a numeric appreciate; in this way, you can perform number-crunching operations on a pointer similarly as you can a numeric esteem. There are four number juggling administrators that can be utilized on pointers: ++, - , +, and - .

Illustration :

ptr++;

ptr- - ;

ptr+21;

ptr-10;

On the off chance that a burn pointer indicating address 100 is augmented (ptr++) at that point it will point to memory address 101

C++ Pointers versus Arrays

Pointers and clusters are emphatically related. Actually, pointers and exhibits are tradable by and large. For instance, a pointer that focuses to the start of a cluster can get to that exhibit by utilizing either pointer number juggling or exhibit style ordering.

int primary ()

{

int var[3] = {1, 2, 3};

int *ptr;

cout << *ptr << endl;

ptr++;

cout << *ptr << endl;

return 0;

}

this code will return :

1

2

C++ Pointer to Pointer

A pointer to a pointer is a type of various indirection or a chain of pointers. Ordinarily, a pointer contains the address of a variable. When we characterize a pointer to a pointer, the primary pointer contains the address of the second pointer, which focuses to the area that contains the genuine esteem. int principle ()

{

int var;

int *ptr;

int **pptr;

var = 3000;

ptr = &var;

pptr = &ptr;

cout << "Estimation of var :" << var << endl;

cout << "Esteem accessible at *ptr :" << *ptr << endl;

cout << "Esteem accessible at **pptr :" << **pptr << endl;

return 0;

}


Wednesday, 20 September 2017

What is String in c++

String 

A string is fundamentally an classification of characters which is finished by an invalid character '\0' which show the complete of the string.
Strings are always incase by two fold quotes.

This statement and instatement make a string with "NADI".
To hold the \0 (invalid character) around the complete of the group, the traverse of display is one more than the amount of characters in "NADI".
broil my_name[5] = {'N', 'A', 'D', 'I','\0'}; 

we can in like manner create the above clarification as takes after:
consume my_name[] = "NADI";
Sorts of C String limits
To use string limits programming engineer must import String.h header record.
String.h header record reinforces all the string limits in C vernacular.

Types of c++ string function 

if programmer write a program then must import string.h header file

There are following of string

strcat () it cocatenates string2 at enf of string1

2 strncat ( )  It add a portion of string to another

3 strcpy ( )  It Copies str2 into str1

4 strncpy ( ) copies given number of characters of one string to another

5 strlen ( ) gives the length of str1.

6 strcmp ( ) Returns 0 if str1 is same as str2. Returns 0 if str1 > str2.

7 strcmpi ( ) Same as strcmp() function. But, this function negotiates case. ''A'' and ''a'' are treated as same.

8 strchr ( ) Returns pointer to first occurrence of char in str1.

9 strrchr ( ) last occurrence of given character in a string is found

10 strstr ( ) Returns pointer to first occurrence of str2 in str1.

11 strrstr ( ) Returns pointer to last occurrence of str2 in str1.

12 strdup ( ) duplicates the string

13 strlwr ( ) converts string to lowercase

14 strupr ( ) converts string to uppercase

15 strrev ( ) reverses the given string

16 strset ( ) sets all character in a string to given character

17 strnset ( ) It sets the portion of characters in a string to given character

18 strtok ( ) tokenizing given string using delimiter


What is Arrays in c++?

Arrays


Array is a fixed size collection of similar data type items. Arrays are used to store and access group of data of same data type.
Arrays can of any data type. Arrays must have constant size. Continuous memory locations are used to store array.
It is an aggregate data type that lets you access multiple variables through a single name by use of an index. Array index always starts with 0.

Example for Arrays:


int a[5]; // integer array
char a[5]; // character(string) array
In the above example, we declare an array named a. When used in an array definition, the subscript operator ([]) is used to tell the compiler how many variables to allocate. In this case, we’re allocating 5 integers/character. Each of these variables in an array is called an element.

Types of Arrays:

# One Dimensional Array
# Two Dimensional Array
# Multi Dimensional Array

1 One Dimensional Array


Array declaration
int age [5];

Array initialization
int age[5]={0, 1, 2, 3, 4, 5};

Accessing array
age[0]; /*0_is_accessed*/
age[1]; /*1_is_accessed*/
age[2]; /*2_is_accessed*/

2 Two Dimensional Array


Two dimensional array is combination of rows n columns.
Array declaration
int arr[2][2];

Array initialization
int arr[2][2] = {{1,2}, {3,4}};

Accessing array
arr [0][0] = 1;
arr [0][1] = 2;
arr [1][0] = 3;
arr [1][1] = 4;

3 Multi Dimensional Array


C++ programming language allows programmer to create arrays of arrays known as multidimensional arrays.
For example:
float a[2][4][3];

Pointer to an array


Please go through pointers chapter first to understand this
An array name is a constant pointer to the first element of the array. Therefore, in the declaration:
double balance[50];

balance is a pointer to &balance[0], which is the address of the first element of the array balance. Thus, the following program fragment assigns p the address of the first element of balance:
double *p;
double balance[10];
p = balance;

It is legal to use array names as constant pointers, and vice versa. Therefore, *(balance + 4) is a legitimate way of accessing the data at balance[4].

Passing Array To Function


We can pass entire Arrays to functions as an argument.
For eg.
#include
void display(int a)
{
  int i;
  for(i=0;i < 4;i++){
    cout << a[i];
  }
}
int main(){
  int c[]={1,2,3,4};
  display(c);
  //Passing array to display.
  return 0;
}

Return array from functions


C++ does not allow to return an entire array as an argument to a function. However, You can return a pointer to an array by specifying the array's name without an index.
If you want to return a single-dimension array from a function, you would have to declare a function returning a pointer as in the following example:

int * myFunction()
{
int c[]={1,2,3}
.
.
.
return c
}

Monday, 18 September 2017

Break and Continue in c++

Break statement

Break clarification is typically used to end a case in the switch explanation.

Break statement in circles to immediately closes the circle and program control goes to the join issue with description after the circle.

In case break declaration is used as a piece of permanent circles, the break clarification will end the execution of the internal circle and Program control retreats to outer circle.

Sentence structure :

break;

continue statements

In C++ programming tongue the continue with description works probablylike the break clarification. The continue restarts the hover with the accompanying estimation of thing. All the line code underneath continue with enunciation is skips.

syntax :

continue;

In the for hover, continue with clarification maintains a strategic distance from the test phase and scope estimation of the variable to execute again and In the while and do...while hovers, continue with skirts each one of the declarations and program control goes to near the complete of circle

Saturday, 16 September 2017

Loops - while & for

while loop


The while loop calculates the expression before every loop. If the expression is true then block of statements is executed, so it will not execute If the condition is initially false. It needs the parenthesis like the if statement.

while ( expression )
/*while expression is true do following*/

  statements...

Do While loop

This is equivalent to a while loop, but it have test condition at the end of the loop. The Do while loop will always execute at least once.

do
  statements ;

while ( expression );
/* while expression is true do...*/

For loop

This is very widely held loop.
For loops work like the corresponding while loop shown in the above example. The first expression is treated as a statement and executed, then the second expression is test or condition which is evaluated to see if the body of the loop should be executed. The third expression is increment or decrement which is performed at the end of every iteration/repetition of the loop.

for (expr1; expr2; expr3)
  statements...;

In while loop it can happen that the statement will never execute But In the do-while loop, test condition is based at the end of loop therefore the block of statement will always execute at least once. This is the main difference between the while and the do-while loop.

For example, to execute a statement 10 times:

for (i = 0; i < 10; i++)
  cout << i << endl;
-----------------------------------
Output;
0 1 2 3 4 5 6 7 8 9

Another way of doing this is:
i = 7;
while (i--)
  statements;
--------------------------
Output;
7 6 5 4 3 2 1

While using this method, make sure that value of i is greater than zero, or make the test i-->0.