Write a program in C++ to print Fibonacci series upto number entered by user

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

int main() {   
   int n, c, first = 0, second = 1, next;
 
   cout<<"*** FIBONACCI SERIES ***"<<endl; 
   cout << "Enter number of terms: ";
   cin >> n;
   cout << endl;
   
   for ( c = 0 ; c < n ; c++ )
   {
      if ( c <= 1 )
         next = c;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      cout << next << " ";
   }
   return 0;
}

Output:

Read more

Write a program in C++ to find factorial of entered number

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

int main() {

 int num,factorial=1;
 
 cout << "Enter Number: ";
 cin >> num;
 
 for (int a=1;a<=num;a++) {
  factorial=factorial*a;
 }
 
 cout<<"Factorial: "<< factorial << endl;
 return 0;
}


Output:

Read more

Write a program in C++ to check whether the entered number if prime number or not

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

int main() {
{  
    int num, i, count = 0;

    cout << "Enter the number to be checked : ";
    cin >> num;

    if (num == 0)
    {
        cout << "\n" << num << " is not prime";
        exit(1);
    }
    else   
    {
        for(i=2; i < num; i++)
            if (num % i == 0)
                count++;
    }
    if (count > 1)
  cout << "\n" << num << " is not prime.";
    else
        cout << "\n" << num << " is prime.";
 return 0;
}


Output:

Read more

Write a program in C++ to find area of Triangle, Rectangle or Circle using IF ELSE (must be menu driven)

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

int main() {
        
    int shape, a, b;
    char ans;
    
    Repeat: 
    system("CLS");
    cout << "Select Shape:" << endl;
    cout << "1.Triangle" << endl;
    cout << "2.Rectangle" << endl;
    cout << "3.Circle" << endl;
    
    cin >> shape;
    
    if(shape==1) {
       cout << "Base: ";
       cin >> a;
       cout << "Altitude: ";
       cin >> b;
       cout << endl << "Area of Triangle: " << 0.5*a*b;
    } else if(shape==2) {
       cout << "Length: ";
       cin >> a;
       cout << "Breadth: ";
       cin >> b;
       cout << endl << "Area of Rectangle: " << a*b;           
    } else if(shape==3) {           
       cout << "Radius: ";
       cin >> a;
       cout << endl << "Area of Circle: " << 3.14*a*a;  
    } else {
       cout << "Invalid Shape";       
    }
    
    cout << endl << "Do you want more calculation? (y/n)";
    cin >> ans;
    
    if (ans=='y') {
       goto Repeat;
    }
    
    getch();
    return 0;
}


Output:

Read more

Write a program in C++ to find whether the entered year is LEAP YEAR or not

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

int main() {
        
  int year;
    
  cout << "Enter Year: ";   
  cin >> year;
    
  (year%4)==0 ? cout<<"Leap Year" : cout<<"NOT Leap Year";
    
  getch();
  return 0;
}


Output:

Read more

Write a program in C++ to find SIMPLE INTEREST

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

int main() {
    //p=principle, r=rate, t=time in years
    float p, r, t;
    
    cout << "Principle: ";   
    cin >> p;
    
    cout << "Rate: ";
    cin >> r;
    
    cout << "Time: ";
    cin >> t;
    
    cout << endl << "Simple Interest:" << p*r*t/100;
    
    getch();
    return 0;
}


Output:

Read more

Write a program in C++ to find highest of 3 numbers using conditional operator

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

int main() {
    int a, b, c, big;
            
    cout << "First No: ";
    cin >> a;
    
    cout << "Second No: ";
    cin >> b;
    
    cout << "Third No: ";
    cin >> c;
    
    big = a > b ? ( a > c ? a : c) : (b > c ? b : c) ;
    
    cout << "Highest Number: " << big;
    
    getch();
    return 0;
}


Output:

Read more

Uses of C++

  1. C++ is being highly used to write device drivers and other softwares that rely on direct manipulation of hardware under realtime constraints
  2. C++ is widely used for teaching and research because it is clean enough for successful teaching of basic concepts
Read more

C++ Tutorials

Use CTRL+F to find the desired program


  1. Introduction to C++
  2. a
  3. a
  4. a
  5. a
  6. a
  7. a
  8. a
  9. a
  10. a
  11. a
  12. a
Read more

INTRODUCTION to C++

  • 1. C++ is a middle-level programming language developed by Bjarne Stroustrup starting in 1979 at Bell Labs. 
  • 2. C++ runs on a variety of platforms, such as Windows, Mac OS, and the various versions of UNIX.
  • 3. C++ is a statically typed, compiled, general-purpose, case-sensitive, programming language that supports procedural, object-oriented, and generic programming.
  • 4. C++ supports OOPS
Read more

Write a program in C++ to find area of triangle

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

int main() {   
    float base, altitude;
    
    cout << "Base: ";   
    cin >> base;
    
    cout << "Altitude: ";
    cin >> altitude;
    
    cout << endl << "Area:" << 0.5*base*altitude;
      
    getch();
    return 0;
}

Output:

Read more

Write a program in C++ to find Highest of 3 numbers using nested if else

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

int main() {   
    int a, b, c;
            
    cout << "First No: ";
    cin >> a;
    
    cout << "Second No: ";
    cin >> b;
    
    cout << "Third No: ";
    cin >> c;
    
    if (a>b) {
       if(a>c)
          cout << a << " is highest";
       else 
          cout << c << " is highest";
    } else {
       if(b>c)
          cout << b << " is highest";
       else 
          cout << c << " is highest";
    }
      
    getch();
    return 0;
}

Output:



Search Tags: c++ programs, cpp programs, c++ practice programs, cpp practice programs, nested if else, highest number, maximum number
Read more

Write a program in C++ to print prime numbers from 1 to 100

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

int main() {   
    int count=0;
            
    for (int i=1; i<=100; i++) {    
        for(int k=i; k>=1; k--) {
           if(i%k==0) {
              count++; 
           }
        }
        if(count==1 || count==2) {
            cout << i << endl;
        }    
        count=0;
    }
      
    getch();
    return 0;
}

Output:



Search Tags: c++ programs, cpp programs, c++ practice programs, cpp practice programs, prime numbers
Read more

Write a program in C++ to find area of circle

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

int main() {   
    float r, area;
        
    cout << "Enter Radius:";
    cin >> r;
    
    area = 3.14*r*r;
    
    cout << endl << "Area: " << area;
      
    getch();
    return 0;
}


Output:

Read more

Write a program in C++ to check the number is positive or negative using Conditional Operator

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

int main() {   
    int a;
        
    cout << "Enter a:";
    cin >> a;
    
    a>=0 ? cout<<"Positive" : cout<<"Negative";
      
    getch();
    return 0;
}

Output:

Read more

Write a program in C++ to swap two variables without using third variable

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

int main() {   
    int a=10, b=15;
    
    a = a+b;
    b = a-b;
    a = a-b;
    
    cout << "a:" << a << endl;
    cout << "b:" << b << endl;
      
    getch();
    return 0;
}

Output:
Read more

Write a program in C++ to find the Square and Cube of any number

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

int main() {   
    float a, b;
    
    cout << "Enter No: ";   
    cin >> a;
    
    cout << "Square:" << a*a << endl;
    cout << "Cube:" << a*a*a << endl;
      
    getch();
    return 0;
}

Output:

Read more

Write a program in C++ to find Addition, Subtraction, Multiplication, Division, Remainder and Average of two floating numbers

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

int main() {   
    float a, b;
    
    cout << "First No: ";   
    cin >> a;
    
    cout << "Second No: ";
    cin >> b;
    
    cout << "Add:" << a+b << endl;
    cout << "Sub:" << a-b << endl;
    cout << "Div:" << a/b << endl;
    cout << "Mul:" << a*b << endl;
    cout << "Remainder:" << (int)a % (int)b << endl;
    cout << "Average:" << (a+b)/2 << endl;
    
    getch();
    return 0;
}


Output:



Read more

Write a program in C++ to input roll no, name and marks and display entered details and average marks

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

int main() {
    int rollno;
    char name[30];
    float mat, sci, com;
    
    cout << "Roll No: ";   
    cin >> rollno;
    
    cout << "Name: ";
    cin >> name;
    
    cout << "\nEnter Marks:" << endl;
    cout << "Maths: ";
    cin >> mat;
    
    cout << "Science: ";
    cin >> sci;
    
    cout << "Computer: ";
    cin >> com;
    
    cout << "\n------\n\n";
    
    cout << "Roll No: " << rollno << endl;
    cout << "Name: " << name << endl;
    cout << "Average: " << (mat+sci+com)/3;
    
    getch();
    return 0;
}


Output:



Read more

C++ Programs

Use CTRL+F to find the desired program


  1. Write a program in C++ to input roll no, name and marks and display entered details and average marks
  2. Write a program in C++ to find Addition, Subtraction, Multiplication, Division, Remainder and Average of two floating numbers
  3. Write a program in C++ to find the Square and Cube of any number
  4. Write a program in C++ to swap two variables without using third variable
  5. Write a program in C++ to check the number is positive or negative using Conditional Operator
  6. Write a program in C++ to find area of circle
  7. Write a program in C++ to find area of triangle
  8. Write a program in C++ to find simple interest
  9. Write a program in C++ to enter marks of 5 subjects and then calculate percentage
    a.     Percentage > 75 then print “Distinction”
    b.     Percentage > 60 print “First Class”
    c.     Percentage > 50 print “Second Class”
    d.     Percentage > 35 print “Pass”
    e.     Otherwise print “Fail”
  10. Write a program in C++ to check whether the entered year is leap year or not
  11. Write a program in C++ to print prime numbers from 1 to 100
  12. Write a program in C++ to check whether the entered number if prime number or not
  13. Write a program in C++ to find Maximum of 3 number using Conditional Operator
  14. Write a program in C++ to find Maximum of 3 number using Nested If Else
  15. Write a program in C++ to find addition, subtraction, multiplication or division of 2 numbers entered by user using switch case
  16. Write a program in C++ to find out Area of Triangle, Rectangle or Circle using If else (Must be menu driven)
  17. Write a program in C++ to find factorial of entered number
  18. Write a program in C++ to print Fibonacci series upto number entered by user
  19. Write a program to print table of entered number
  20. Write a program to find max digit in entered number (e.g. in 1563 max digit is 6)
  21. Write a program to find summation of digits of any number (e.g. in 1563 summation is 1+5+6+3=14)
  22. Write a program to find summation of first and last digit of a number (e.g. in 1365 summation is 1+5=6)
  23. Write a program to print following pyramids
    *
    **
    ***
    ****
    1
    12
    123
    1234
    1
    22
    333
    4444
    *
    **
    ***
    ****
    1
    21
    321
    4321
    54321
    *
    * *
    * * *
    * * * *
    * * * * *
    1
    1 2
    1 2 3
    1 2 3 4
    1 2 3 4 5
    1
    2 2
    3 3 3
    4 4 4 4
    5 5 5 5 5
    *
    **
    ***
    ****
    ***
    **
    *

    * * * * * *
    * * * * *
    * * * *
    * * *
    * *
    *

    * * * * * * * *
    * * *       * * *
    * *             * *
    *                   * 

    *
    * * 
    * * *
    * * * *
    * * * 
    * *
  24. Write a program to enter 6 elements in array and print square of every element
  25. Write a program to enter 10 elements in array and print the number of even and odd elements in it
  26. Write a program to enter 10 elements in array and print summation and average of elements
  27. Write a program to print max of 10 elements of array
  28. Write a program to sort array in ascending order
  29. Write a program to sort array in descending order
  30. Write a program to find second smallest element of array
  31. Write a program to print Matrix using 2D array
  32. Write a program for addition and subtraction 2 Matrix using 2D array
  33. Write a program for multiplication of 2 Matrix using 2D array
  34. Write a program to find Max element in 2D array (Matrix)
  35. Write a program to convert string from uppercase to lowercase and vice versa
  36. Write a program to count the number of words without using string function
  37. Write a program to copy a string’s value into another without using string function
  38. Write a program to reverse the string without using string function
  39. Write a program to check whether the entered string is Palindrome or not
  40. Write a program to concatenate 2 strings without using string function
  41. Write a program to find addition, subtraction, multiplication and division of 2 numbers using Function
  42. Write a program to find square and cube of any number using Function
  43. Write a program to find factorial of any number using Function
  44. Write a program to print Fibonacci Series using Function
  45. Write a program to find min and max element of an array using Function
  46. Write a program to sort the array using Function
  47. Write a program to print the string in reverse order using Function
  48. Write a program to for factorial using Recursive Function
  49. Write a program to check whether the entered number if Palindrome or not using Recursive Function
  50. Write a program of Structure employee that provides following information: emp_no, emp_name, emp_age, emp_designation, emp_salary, emp_address
  51. Write a program of Structure employee that provides following information for 5 employees: emp_no, emp_name, emp_age, emp_designation, emp_salary, emp_address
  52. Write a program of structure student having roll_no and marks of 3 subjects of 5 students, then print the total marks and percentage of every student
  53. Write a program to make addition of 2 numbers using pointer
  54. Write a program to swap two variables using pointer
  55. Write a program to concatenate 2 strings using pointer
  56. Write a program to sort array using pointer and function
  57. Write a program to read data from file
  58. Write a program to write data into a file
  59. Write a program to append data into already existing file
  60. Write a program to calculate square of any number using Macro
  61. Write a program to assign any constant value (e.g. pi=3.14) to Macro and use it to find area of circle 
Read more

Contact Form

Name

Email *

Message *

Followers