Pratik Ghelani: cpp

Pratik Ghelani

Breaking

Showing posts with label cpp. Show all posts
Showing posts with label cpp. Show all posts

Sunday, January 20, 2019

4:43 AM

Write a program in C++ to perform following pattern.

Write a program in C++ to perform following pattern:

3 5 
7 9 11 
13 15 17 19

Program:-

#include<iostream>
using namespace std;
int main() 

    int i,j,num=-1; 
    
    for(i=1;i<=4;i++) 
    { 
        for(j=1;j<=i;j++)
        { 
            num=num+2;
            cout<<num;
            cout<<" "; 
        } 
        cout<<endl; 
    }
    

}

Output:-





4:37 AM

Write a program in C++ to create basic calculator (add, sub, mul, div) using switch case.

Program:-

#include<iostream> 
using namespace std;
int main() 

    int a,b,ch,ans;
    cout<<"Enter the first number:"; 
    cin>>a; 
    cout<<"Enter the second number:"; 
    cin>>b; 
    cout<<"1.Addition \n2.Subtraction \n3.Multiplication \n4.Division \n"; 
    cout<<"Enter your choice:"; 
    cin>>ch; 
    switch(ch) 
    { 
        case 1: ans=a+b; 
        break;
        case 2: ans=a-b;
        break; 
        case 3: ans=a*b;
        break; 
        case 4: ans=a/b; 
        break; 
        default: cout<<"Invalid choice!"; 
        
    } 
        cout<<"Answer is:"<<ans<<endl; 
    

}

Output:-