c语言代码,输入年月日计算离2018年春节(2019年2月5日)还有多少天? - 爱问答

(爱问答)

c语言代码,输入年月日计算离2018年春节(2019年2月5日)还有多少天?

这个可以用C标准函数实现

#include <stdio.h>
#include <time.h>
time_t gettime(int y, int m, int d) //转换格式
{
   struct tm tm_;
   time_t t;
   tm_.tm_year  = y - 1900; //年
   tm_.tm_mon   = m - 1; //月
   tm_.tm_mday  = d; //日
   tm_.tm_hour  = 0; //时
   tm_.tm_min   = 0; //分
   tm_.tm_sec   = 0; //秒
   tm_.tm_isdst = 0;  //夏令时
   t = mktime(&tm_); //生成时间
   return t;
}
int main()
{
   const struct tm *tm;
   time_t t, t1, dif;
   char str[20];
    int y, m, d;
     printf("请输入年月日(用-号分隔): ");
    scanf("%d-%d-%d", &y, &m, &d);
   t = gettime(y,m,d);
   t1=gettime(2019,2,5); //2018春节
   dif = difftime(t1, t); //与输入时间差,秒数
   printf("输入日期与2018春节相差%d天 ", dif / (3600 * 24));
   return 0;
}

相关标签:c语言

下一篇:c语言while编程求解:1/22/33/4…99/100.

上一篇:设计算法编写程序,定义有10个元素的一维数组,输入变量x,将数组中所有与x值相等的元素删除

热门标签:
excel 网盘 破解 word dll
最新更新:
微软重新评估新的Outlook的使用时机 联想推出搭载联发科Helio G80芯片组的Tab M9平板 英特尔创新大赛时间确定! 微软Edge浏览器在稳定渠道中推出Workspaces功能 英伟达RTX4060TiGPU推出MaxSun动漫主题! 谷歌地图为用户提供了街景服务! GameSir 在T4 Kaleid中推出了一款出色的控制器! 微软开始在Windows 11 中测试其画图应用程序的新深色模式! LG电子推出全球首款无线OLED电视 英伟达人工智能芯片崭露头角! Steam Deck可以玩什么游戏-Steam Deck价格限时优惠 雷蛇推出CobraPro鼠标 Kindle电子阅读器可以访问谷歌商店吗 Windows10如何加入组策略 window10图片查看器怎么没有了?