Description

1. Write a c++ program to print the "Hello World!".

#include<iostream>

using namespace std;

int main(){
    cout<<"Hello World!";
    return 0;
}

Output :

Hello World!

2. Write a CPP program add two numbers.

#include<iostream>
using namespace std;

int main(){
    
    int n1, n2;
    cout<<"Enter the number 1 : ";
    cin>>n1;
    cout<<"Enter the number 2 : ";
    cin>>n2;
    
    int add = n1 + n2;
    cout<<"The sum of "<<n1<<" and "<<n2<<" is : "<<add<<endl;
    return 0;
}

Output : 

Enter the number 1 : 6
Enter the number 2 : 7
The sum of 6and 7 is : 13

3. Write a CPP program to explain cascading of Insertion ( << ) operator and cascading of Extraction ( >> ).

#include<iostream>

using namespace std;

int main(){
    int n1, n2;
    cout<<"Enter two numbers : ";
    cin>>n1>>n2;
    int sub = n1 - n2;
    cout<<"\n"<<n1<<" - "<<n2<<" = "<<sub<<endl;
    return 0;
}

Output :

Enter two numbers : 45 30
45 - 30 = 15

4. Write a CPP program print the lapmos.com but in program also write "Hello World, Welcome to lapmos.com" but do not execute this statement.

#include<iostream>

using namespace std;

int main(){
    
    // Hello World, welcome to lapmos.com
    cout<<"lapmos.com";
    return 0;
}

Output :

lapmos.com

5. Write a CPP program to print "Hello World!" and each print in a new line 5 times.

#include<iostream>

using namespace std;

int main(){

    cout<<"Hello World"<<endl;
    cout<<"Hello World"<<endl;
    cout<<"Hello World"<<endl;
    cout<<"Hello World"<<endl;
    cout<<"Hello World"<<endl;
    return 0;
}

Output : 

Hello World
Hello World
Hello World
Hello World
Hello World

6. Write a program using setw() as an example.

#include<iostream>
#include<iomanip>

using namespace std;

int main(){

    cout<<setw(10)<<"lapmos"<<endl;
    cout<<setw(10)<<"lapmos.com"<<endl;
    return 0;
}

Output : 

        lapmos
lapmos.com

7. Write a CPP Program swap to numbers using third variable.

#include<iostream>

using namespace std;

int main(){

    int n1, n2, temp;
    cout<<"Enter two Numbers : ";
    cin>>n1>>n2;
    
    cout<<"Before Swapping : n1 = "<<n1<<" and n2 = "<<n2<<endl;
   
    temp = n1;
    n1 = n2;
    n2 = temp;
   
    cout<<"After Swapping : n1 = "<<n1<<" and n2 = "<<n2<<endl;
    return 0;
}

Output :

Enter two Numbers : 56 34
Before Swapping : n1 = 56 and n2 = 34
After Swapping : n1 = 34 and n2 = 56

8. Write a CPP program swap two number without using third variable.

#include<iostream>

using namespace std;

int main(){

    int n1, n2, temp;
    cout<<"Enter two Numbers : ";
    cin>>n1>>n2;
    
    cout<<"Before Swapping : n1 = "<<n1<<" and n2 = "<<n2<<endl;
   
    n1 = n1 + n2;
    n2 = n1 - n2;
    n1 = n1 - n2;
   
    cout<<"After Swapping : n1 = "<<n1<<" and n2 = "<<n2<<endl;
    return 0;
}

Output : 

Enter two Numbers : 10 20
Before Swapping : n1 = 10 and n2 = 20
After Swapping : n1 = 20 and n2 = 10

9. Write a CPP program to print the value from 1 to 100.

#include<iostream>

using namespace std;

int main(){
   
    for(int i = 1; i<=100; i++){
        cout<<i<<" ";
    }
    return 0;
}

Output : 

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 

Comments

Login is mandatory to comment Please login

Recommended Posts

Spy Number | c programming

Today we are going to write a program which is to check if given number is spy or not and yes the most important thing is what is spy number, you will get the answer of all these on this blog.

Display Name of the month by accepting digit of the month | c programming

We will print the month name from the month number given by the user which will give us the user input. For Example : User Entered 5 then print

Happy Numbers | with Example And Programs

Replace the number by the sum of the squares of its digits, and repeat the process. At the end, if the number is equals to 1 then it is a Happy Number, or it loops endlessly in a cycle that does not include 1 (if it is not a happy number then this process will end at 4).

Sunny Number in programming

A number is a sunny number. If 1 is added to that number and the square root of it becomes a whole number.

Program to check whether number is Disarium Number

A Number is a disarium number if the sum of the digits powered with their respective positions is equal to the number itself.

Floyd Triangle | Programs | Algorithm

A Floyd Triangle is right angled triangle consisting of consecutive natural numbers starting with one and then going down through the rows.