[英]Is there something wrong with my program? I only seems to get 0.0000 as my answers
#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);
}
}
You declared seconds as an integer, so you should change %.5f
to %d
.您将 seconds 声明为 integer,因此您应该将
%.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);
}
}
There are couple of mistakes in your code您的代码中有几个错误
Yo can use following code to get the output you want您可以使用以下代码获取您想要的 output
#include <stdio.h>
int main(void) {
int days, seconds;
printf("Enter the no. of days: ");
scanf("%d", &days);
if(days<=0){
printf("Invalid input");
}else{
seconds = days * 86400;
printf("It is equal to: %.5d Seconds", seconds);
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.