Programming Examples

Write a program that converts number of years


Write a program that converts number of years into (1) minutes, (2) hours, (3) days, (4) months and (5) seconds using switch statements.

Solution

#include<stdio.h>
void main()
{
long ch,min,hrs,ds,mon,yrs,se;
clrscr();
printf(“\n[1] MINUTES”);
printf(“\n[2] HOURS”);
printf(“\n[3] DAYS”);
printf(“\n[4] MONTHS”);
printf(“\n[5] SECONDS”);
printf(“\n[0] EXIT”);
printf(“\n Enter Your Choice :”);
scanf(“%ld”, &ch);
if(ch>0 && ch<6 )
{
 printf(“Enter Years :”);
 scanf(“%ld”,&yrs);
}
 mon=yrs*12;
 ds=mon*30;
 ds=ds+yrs*5;
 hrs=ds*24;
 min=hrs*60;
 se=min*60;
 switch(ch)
 {
 case 1 :
 printf(“\n Minutes : %ld”,min);
 break;
 case 2 :
 printf(“\n Hours : %ld”,hrs);
 break;
 case 3 :
 printf(“\n Days : %ld”,ds);
 break;
 case 4 :
 printf(“\n Months : %ld”,mon);
 break;
 case 5 :
 printf(“\n Seconds: %ld”,se);
 break;
 case 0 :
 printf(“\n Terminated by choice”);
exit();
 break;
 default :
 printf(“\n Invalid Choice”);
 }
getch();
}
Output

OUTPUT:

[1] MINUTES

[2] HOURS

[3] DAYS

[4] MONTHS

[5] SECONDS

[0] EXIT

Enter Your Choice : 4

Enter Years : 2

Months : 24

Latest Current Affairs 2024 Online Exam Quiz for One day Exam Online Typing Test CCC Online Test 2024 Python Programming Tutorials Best Computer Training Institute in Prayagraj (Allahabad) Best Java Training Institute in Prayagraj (Allahabad) Best Python Training Institute in Prayagraj (Allahabad) O Level Online Test in Hindi Bank SSC Railway TET UPTET Question Bank career counselling in allahabad Sarkari Naukari Notification Best Website and Software Company in Allahabad Sarkari Exam Quiz