Category: C++ Program

print star pattern in c++

print star patterns in c++: –These program prints various different patterns of numbers and stars. This program will print triangle star patterns using c++ program. A pattern of numbers, star or characters is a way of arranging these in some logical manner or they may form a sequence.

code to prints star pattern in c++

Here we have written a program in c++ to generate print star pattern.we have used header file on the top of the program then used the namespace after that we have taken input from the console to display.we have used for loop to print star pattern in the form of traingle shape

#include<iostream>

#include<conio.h>

using namespace std;




int main()

{

            int i,j,k;

            for(i=1;i<=5;i++)

            {

                        for(j=5;j>i;j--)

                                    cout<<' ';

                        for(k=1;k<2*i;k++)

                                    cout<<'*';

                        cout<<endl;

            }




            getch();

            return 0;

}

OUTPUT

print star pattern

palindrome number program in c++

palindrome number program: –Hi Readers, In this tutorial we create a program in c++ to check whether a number is a palindrome or not.Here we start the topic on how to make palindrome number program in c++

palindrome number  logic

A palindrome number is a number such that if we reverse it, it will not change.

 we have used header file on the top of the program then used the namespace after that we have taken input from the console to display

Code

#include<iostream>

#include<conio.h>

using namespace std;




int main()

{

    unsigned long n,num,d,rev=0;

    cout<<"Enter any number: ";

    cin>>n;

    num=n;




    do

    {

        d=n%10;

        rev=(rev*10)+d;

        n=n/10;

    }while(n!=0);

   

    if(num==rev)

        cout<<endl<<"Number is Palindrome";

    else

        cout<<endl<<"Number is not Palindrome";

 getch();

    return 0;

}

palindrome number program in c++

 

I hope you would like this topic about check palindrome number in c++

 fibonacci series program in c++

 fibonacci series program in c++: –Hi Readers, in this blog we will create a C++ program to generate or display fibonacci series in c++.First of all, we need to know what is the meaning of fibonacci series program and their logic to generate fibonacci series

 

 fibonacci series logic in c++

Fibonacci sequence are few numbers of series are 0, 1, 1, 2, 3, 5, 8 etc, Except first two terms in sequence every other term is the sum of two previous terms.

C++ program to generate Fibonacci series program

Here we have written a program in c++ to generate fibonacci series.we have used header file on the top of the program then used the namespace after that we have taken input from the console to display

fibonacci series

#include<iostream>

#include<conio.h>

using namespace std;

main()

{

   int n, c, first = 0, second = 1, next;

   cout << "Enter the number of terms of Fibonacci series you want" << endl;

   cin >> n;

   cout << "First " << n << " terms of Fibonacci series are :- " << endl;

   for ( c = 0 ; c < n ; c++ )

   {

      if ( c <= 1 )

         next = c;

      else

      {

         next = first + second;

         first = second;

         second = next;

      }

      cout << next << endl;

   }

 getch();

   return 0;

}




fibonacci series program

I hope you would like this topic.Thanks

How to swap two numbers without using the third variable in c++?

swap two numbers: – Swap any two numbers means the value will be interchanged. It means suppose there are two variable and each has its value and after the swap, their value will be interchanged.

Example: – A whose value is 10 and B whose value is 20 when you perform the swapping the value of A will assign to B and value of B will assign to A now the value of A will become 20 and the value of B will become 10.

 

Program to swap two numbers in c++

Here we have written a program in c++ to swap any two numbers without using the third variable.we have used header file on the top of the program then used the namespace after that we have taken input from the console end to swap any numbers and used the logic to swap two numbers.

#include<iostream>

#include<conio.h>

using namespace std;




int main()

{

int a,b;

cout<<"\nEnter two numbers : ";

cin>>a>>b;

a=a+b;

b=a-b;

a=a-b;

cout<<"\nAfter swapping numbers are : ";

cout<<a<<" "<<b;

getch();

return 0;

}

Output:

swap two numbers