Sunday, 8 May 2016

C And C++ Program to extract last two digits of a given year Problem Solution.


C Solution:

#include<stdio.h>
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int year,y;
    printf("Enter a year in for digits: ");
    scanf("%d",&year);

    y = year % 100;
    printf("Last two digits of year is: %02d",y);

    return 0;
}

C++ Solution:

#include<iostream>
#include<iomanip>
using namespace std;
/*
    *
    * Prosen Ghosh
    * American International University - Bangladesh (AIUB)
    *
*/
int main(){

    int year;
    cout << "Enter a year in for digits: ";
    cin >> year;

    cout << "Last two digits of year is: " << setfill('0') << setw(2) << year % 100 << endl;;

    return 0;
}

No comments:

Post a Comment