Ticker

6/recent/ticker-posts

SOME SIMPLE C+ + PROGRAMS

In this section, some basic C++ program are given. You practice it and may write some more program like these

Program: 1 

// Printing a message 
#include 
int main(void) 

        cout << “Hello, this is my first C++ program” << endl; 
        return 0; 

Output: 

Hello, this is my first C++ program 

Program: 2

// Printing name
#include <iostream.h>
# include<conio.h>
main()

    char name [15];
    clrscr();
    cout << "Enter your name:”;
    cin >> name;
    cout<<”Your name is: “ <<name;
    return0;
}

Output: 

Enter your name: Ram 
Your name is: Ram

Program: 3 

// operating with variables 
#include 
using namespace std; 
int main () 

     // declaring variables: 
         int a, b; 
         int result; 
         // process: 
         a = 5; 
         b = 2; 
         a = a + 1; 
         result = a - b; 
         // print out the result: 
         cout << result; 
         // terminate the program: 
         return 0; 

Output: 

Result = 4 

Program: 4 

// initialization of variables 
#include 
using namespace std; 
int main () 

 int a=5; // initial value = 5 
 int b(2); // initial value = 2 
 int result; // initial value undetermined 
 a = a + 3; 
result = a - b; 
cout << result; 
 return 0; 

Output: 

Result = 6

Program: 5 

// my first string 
#include 
#include 
using namespace std; 
int main () 

     string mystring; 
     mystring = "This is the initial string content"; 
     cout << mystring << endl; 
     mystring = "This is a different string content"; 
     cout << mystring << endl; 
     return 0; 
}

Output: 

This is the initial string content 
This is a different string content

Program: 6

// defined constants: calculate circumference 
#include 
using namespace std; 
#define PI 3.14159 
#define NEWLINE ' \n' 
int main () 

     double r = 5.0; // radius 
     double circle; circle = 2 * PI * r; 
     cout << circle; cout << NEWLINE; 
     return 0; 
}

Output: 

Circle = 31.4258714 

Program: 7

#include <iostream.h>
# include<conio.h>
main()

        int num, num1;
        clrscr();
        cout << "Enter two numbers:”;
        cin >> name>>num1;
        cout<<”Entered numbers are : “ ;
        cout <<num<<”\t”<<num1;
        return0; 
}

Output: 

Enter two numbers: 9, 15 
Entered numbers are 9, 15

ALSO SEARCH:

"a simple C++ program"

"a simple C++ program to add two numbers"

"a simple C++ program to print hello"

"a simple C++ program to reverse the words in a string"

"a simple C++ program with explanation"

"write a simple C++ program"

"structure of a simple C++ program"

"write a simple C++ program to add two numbers"

"write a simple C++ program to retrieve first word from a sentence"

"any simple c program"