Pages

Friday, 4 July 2014

Write a C++ Program take hours, minutes, seconds and print it in 24 hours & standard format

C++ program to display hours minutes and seconds in both  12 and 24 hours format:
24 Hours format : 23:30:12
Standard format : 11:30:12 pm
C++ CODE using Turbo C++ IDE.

code-
#include<iostream.h>
#include<conio.h>
void main()
{

   clrscr();

   int hours,mins,seconds,x;                         

   cout<<"Enter hours=";

   cin>>hours;

   cout<<"\nEnter minutes=";

   cin>>mins;

   cout<<"\nEnter seconds=";

   cin>>seconds;

   if(hours > 24)

    {

     cout<<"Invalid Entery";

   }

   else

   {

       cout<<"\n24 Hours Format\n";

cout<<"Hours  :  Mins  :  Seconds\n"<<"  "<<hours<<"  :     "<<mins<<"   :     "<<seconds<<"\n";

  
  if(hours > 12)

{

  hours=hours-12;

  cout<<"12 Hours Format\n";

cout<<"Hours  :  Mins  :  Seconds\n"<<"  "<<hours<<"  :     "<<mins<<"   :     "<<seconds;

  }

       else

  {

 cout<<"12 Hours Format\n";

 cout<<"Hours  :  Mins  :  Seconds\n"<<" "<<hours<<": "<<mins<<"   :        "<<seconds;

  }

   }


}                            // end of main

0 comments:

Post a Comment