C++ Programs
1. Program to print
#include<iostream>
using namespace std;
int main()
{
    cout << "Hello guys" << endl;
    return 0;
} 
2. Understanding DataTypes
//  Integer -> 4bytes x 8bits = > 32bits
//  Range (unsigned) = 0 to 2**32 - 1
//  Range (signed) = -2**31 to 2**32 - 1    
//  MSB 1 - negative  0 - positive
// Float -> 4 bytes upto 7 decimal digits
// Double -> 8 bytes upto 15 decimal digits
// Character -> 1 byte -> uses ASCII values
// Bool -> 1 byte
#include<iostream>
using namespace std;
int main()
{
    // int ascii = 'a';
    // cout << ascii << endl;
    int a;
    a = 12;
    cout << "Size of int " << sizeof(a) <<endl;
    float b;
    b = 12.0;
    cout << "Size of float " << sizeof(b) <<endl;
    char c;
    c = 'a';
    cout << "Size of Character " << sizeof(c) <<endl;
    bool d;
    d = true;
    cout << "Size of Bool " << sizeof(d) <<endl;
    /* Modifiers */
    // Signed - 4 bytes
    // Unigned - 4 bytes
    // long - 8 bytes
    // short - 2 bytes
    short int s;
    long int l;
    cout << "Size of Short Int " << sizeof(s) <<endl;
    cout << "Size of Long Int " << sizeof(l) <<endl;
    return 0;
}
3. Greatest of three numbers
#include<iostream>
using namespace std;
// Greatest of the three numbers
int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b){
        if(a>c){
            cout<<a<<endl;
        }else{
            cout<<c<<endl;
        }
    }
    else{
        if(b>c){
            cout<<b<<endl;
        }else{
            cout<<c<<endl;
        }
    }
}
4. Finding Even or Odd
#include<iostream>
using namespace std;
// Greatest of the three numbers
int main() {
    int n;
    cin>>n;
    if(n%2==0){
        cout<<"Even"<<endl;
    }else{
        cout<<"Odd"<<endl;
    }
    return 0;
}
Comments
Post a Comment