HOW TO CONVERT DAYS TO MONTH AND DAYS IN C PROGRAMING

 


In this post you can learn how to convert days to month and days using c program. The steps are given below to learn.

  • Create a c file in any c program editor.
  • Then start the program with #include<stdio.h>.
  • Then create a main function with int.
  • At next step we have create a variable like inputday, months, and days.
  • The three variables are declared at int variable.
  • The scanner ( scanf ) is used to get the input from the user.
  • To calculate the month ( months=inputday/30) formula is used.
  • To calculate the remaining days ( days=inputday-months*30 ) formula is used.
  • Then the printf statement is used to print the output of the program.

Program:

#include<stdio.h>
int main()
{
    int inputday,months,days;
    printf("Enter the number of days:")
    scanf("%d",&inputday);
    months=inputday/30;
    days=inputday-months*30;
    printf("No of Months:%d", months);
    printf("\nNo of remaining Days:%d",days);
}  

Input:

145

Output:

No of Months:4
No of remaining Days:25


0 Comments

Post a Comment

Post a Comment (0)

Previous Post Next Post