首页 > 解决方案 > 我的程序有问题吗?我似乎只得到 0.0000 作为我的答案

问题描述

#include <stdio.h>
void main (void)    
{
    int days, seconds;
    
    printf("Enter the no. of days: ");
    scanf("%d", &days);
    
    seconds = days*36400;
    
    if (days<0)
    {
        printf("Invalid input!");
    }
    else 
    {
        printf("It is equal to %.5f seconds", seconds);
    }
}

标签: cbranch

解决方案


您将 seconds 声明为整数,因此您应该更改%.5f%d.

#include <stdio.h>
void main (void)
{
  int days, seconds;

  printf("Enter the no. of days: ");
  scanf("%d", &days);
  
  seconds = days*36400;
 
  if (days<0)
    {
      printf("Invalid input!");
    }
  else 
    {
      printf("It is equal to %d seconds", seconds);
    }
  
}

推荐阅读