Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

#Include #Include #Include Using Namespace Int: Declaring Functions

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

#include<iostream>sfds

#include<cmath>
#include <ctime>
using namespace std;

int main()
{

time_t t = time(NULL);
tm* tPtr = localtime(&t);
cout << "\n\n Display the Current Date and Time :\n";
cout << "----------------------------------------\n";
cout << " seconds = " << (tPtr->tm_sec) << endl;
cout << " minutes = " << (tPtr->tm_min) << endl;
cout << " hours = " << (tPtr->tm_hour) << endl;
cout << " day of month = " << (tPtr->tm_mday) << endl;
cout << " month of year = " << (tPtr->tm_mon)+1 << endl;
cout << " year = " << (tPtr->tm_year)+1900 << endl;
cout << " weekday = " << (tPtr->tm_wday )<< endl;
cout << " day of year = " << (tPtr->tm_yday )<< endl;
cout << " daylight savings = " <<(tPtr->tm_isdst )<< endl;
cout << endl;
cout << endl;

cout << " Current Date: " <<(tPtr->tm_mday)<<"/"<< (tPtr->tm_mon)+1 <<"/"<<


(tPtr->tm_year)+1900<< endl;
cout << " Current Time: " << (tPtr->tm_hour)<<":"<< (tPtr->tm_min)<<":"<< (tPtr-
>tm_sec) << endl;
cout << endl;
system("pause");
return 0;
}

Declaring Functions

// declaring functions prototypes


#include <iostream>
using namespace std;

void odd (int a);


void even(int a);

int main()
{
int i;
do {
cout << "Type a number (0 to exit): ";
cin >> i;
odd (i);
} while (i!=0);

system("pause");
return 0;
}

void odd(int a)
{
if ((a%2)!=0) cout << "Number is odd.\n";
else even (a);
}
void even(int a)
{
if ((a%2)==0) cout << "Number is even.\n";
else odd (a);
}

Arrays

// arrays example
#include <iostream>
using namespace std;
int main ()
{
int Integer[3];

cout<< "Enter Integer 1: "; cin>>Integer[0];


cout<< "Enter Integer 2: "; cin>>Integer[1];

Integer[2] = ((Integer[0]*5) + Integer[1])/2;

cout<< "The Total Value of Integer 3 is: " << Integer[2] << "\n";
system("pause");
return 0;
}

You might also like