C Program to Convert a Given Number of Days in numbers of Years, months,Weeks & Days - My CS Tutorial

Breaking

Programming languages full tutorial and programs, exam papers, visual basic( Vb.net ), information of new technologies and more....

Saturday, June 15, 2019

C Program to Convert a Given Number of Days in numbers of Years, months,Weeks & Days

In this C program we will convert a given numbers of days in numbers of years,months, weeks and remaining days.In this program we find number of years,months,weeks and days by number of days.


Solution

  • In this program we will use total numbers of days so we will take one variables for total numbers of days and four variables for years,months, weeks and remaining days' values.
  • We declared these variables in int data type.
  • Then we will enter the total numbers of days.
  • We use some logic for convert the total numbers of days in years, months, weeks and remaining days. Which are as...
  1. years=tn/365;
  2. months=tn%365/31;
  3. weeks=tn%365%31/7;
  4. days=tn%365%31%7;
  • When we use these statement the value of these operations will be store in own variable.
  • Then we will print the value of all operations as years,months, weeks and days.


C program code


#include<stdio.h>
#include<conio.h>
void main()
{
int tn;
int years,months,weeks,days;
clrscr();
printf("Enter the value of total numbers=");
scanf("%d",&tn);

years=tn/365;
printf("\n the value of years is=");
printf("%d",years);

months=tn%365/31;
printf("\n the value of months is=");
printf("%d",months);

weeks=tn%365%31/7;
printf("\n the value of weeks is=");
printf("%d",weeks);

days=tn%365%31%7;
printf("\n the value of days is=");
printf("%d",days);

getch();
}


Output 1:




Output 2:




In this program we find number of years,months,weeks and days by number of days.we will use total numbers of days so we will take one variables for total numbers of days and four variables for years,months, weeks and remaining days' values.

No comments:

Post a Comment