當前位置:首頁 » 編程語言 » 如何知道總秒數用c語言求時分秒
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

如何知道總秒數用c語言求時分秒

發布時間: 2022-08-27 04:57:15

⑴ 1. c語言編程,怎麼編寫 時 分 秒 的程序

#include<stdio.h>
int main(){
int hour,minute,second;
printf("請輸入時間:");
scanf("%d:%d:%d",&hour,&minute,&second);
printf("Time:%02d:%02d:%02d\n",hour,minute,second);
return 0;
}

⑵ c語言編寫 輸入一個以秒為單位的時間值,將其轉化成「時:分:秒」的形式輸出,怎麼轉換定義成函數

#include<stdio.h>
void trans(int sec){
int hour,min;
hour=sec/3600; //計算時 3600進制
min=(sec%3600)/60; //計算分 60進制
sec=(sec%3600)%60; //計算秒 餘下的全為秒數
printf("%d時:%d分:%d秒\n",hour,min,sec);
}
int main(){
int sec;
printf("請輸入秒數:\n");
scanf("%d",&sec);
trans(sec);
return 0;
}
可以自己試試

⑶ C語言秒的轉換

根據輸入的秒數,轉換成相應的時,分,秒數據輸出過程為:定義變數h,m,s來存儲轉換結果定義seconds變數,接收用戶輸入得到小時數:h=seconds/3600;去除小時數:seconds%=3600; 得到分鍾數:m=seconds/60;得到秒數:s=seconds%60;輸出結果參考代碼:#includeint main(){ int h,m,s,seconds; printf("input sec: ");scanf("%d", &seconds ); h=seconds/3600; seconds %= 3600 ; m=seconds/60; s=seconds%60; printf("%d:%d:%d\n", h,m,s ); return 0;}運行結果:input sec: 145674:2:47

⑷ 使用C#,將總秒數轉化為年月日時分秒的格式

親,抽空用winform做了一個,覺得還可以歡迎採納,要看代碼用vs2010或以上版本打開就可以了,只是看效果,直接打開bin文件夾下的.exe文件運行即可

⑸ 用c語言如何獲取系統當前時間的函數

1、C語言中讀取系統時間的函數為time(),其函數原型為:
#include <time.h>
time_t time( time_t * ) ;
time_t就是long,函數返回從1970年1月1日(MFC是1899年12月31日)0時0分0秒,到現在的的秒數。
2、C語言還提供了將秒數轉換成相應的時間格式的函數:
char * ctime(const time_t *timer); //將日歷時間轉換成本地時間,返回轉換後的字元串指針 可定義字元串或是字元指針來接收返回值
struct tm * gmtime(const time_t *timer); //將日歷時間轉化為世界標准時間(即格林尼治時間),返回結構體指針 可定義struct tm *變數來接收結果
struct tm * localtime(const time_t * timer); //將日歷時間轉化為本地時間,返回結構體指針 可定義struct tm *變數來接收結果
3、常式:
#include <time.h>
void main()
{
time_t t;
struct tm *pt ;
char *pc ;
time(&t);
pc=ctime(&t) ; printf("ctime:%s", pc );
pt=localtime(&t) ; printf("year=%d", pt->tm_year+1900 );
}

時間結構體struct tm 說明:

struct tm {
int tm_sec; /* 秒 – 取值區間為[0,59] */
int tm_min; /* 分 - 取值區間為[0,59] */
int tm_hour; /* 時 - 取值區間為[0,23] */
int tm_mday; /* 一個月中的日期 - 取值區間為[1,31] */
int tm_mon; /* 月份(從一月開始,0代表一月) - 取值區間為[0,11] */
int tm_year; /* 年份,其值等於實際年份減去1900 */
int tm_wday; /* 星期 – 取值區間為[0,6],其中0代表星期天,1代表星期一,以此類推 */
int tm_yday; /* 從每年的1月1日開始的天數 – 取值區間為[0,365],其中0代表1月1日,1代表1月2日,以此類推 */
int tm_isdst; /* 夏令時標識符,實行夏令時的時候,tm_isdst為正。不實行夏令時的進候,tm_isdst為0;不了解情況時,tm_isdst()為負。*/
};

⑹ c語言,秒轉換為時分秒,新手不知道哪裡錯了

輸入輸出用%d

#include<stdio.h>
intmain()
{
inta,b,c,d,e;
printf("請輸入秒數:");
scanf("%d",&a);
b=a/3600;//求幾小時
c=(a%3600)/60;//求幾分
d=a-3600*b-60*c;//求秒

printf("%d時」,b);
printf("%d分」,c);
printf("%d秒」,d);
}

⑺ 給秒數 怎麼算他的時分秒甚至是月年

JAVA語言不懂,但可以給你說演算法
假設有X秒
X整除60=分鍾A,X和60求余=秒
分鍾A整除60=小時 分鍾A和60求余=分鍾B

接下來依次求天,月,年

明白?
以65000秒來說
65000整除60=1083 餘20
1083整除60=18 余 3
最後結果65000秒=18小時3分鍾20秒

⑻ 在c語言程序中如何編輯秒數,讓它按小時;分鍾,秒的形式輸出

根據輸入的秒數,轉換成相應的時,分,秒數據輸出過程為:

  1. 定義變數h, m, s來存儲轉換結果

  2. 定義seconds變數,接收用戶輸入

  3. 得到小時數:h=seconds/3600;

  4. 去除小時數:seconds%=3600;

  5. 得到分鍾數:m=seconds/60;

  6. 得到秒數:s=seconds%60 ;

  7. 輸出結果

參考代碼:

#include<stdio.h>
intmain()
{
inth,m,s,seconds;
printf("inputsec:");scanf("%d",&seconds);
h=seconds/3600;
seconds%=3600;
m=seconds/60;
s=seconds%60;
printf("%d:%d:%d ",h,m,s);
return0;
}
運行結果:
inputsec:14567
4:2:47

⑼ c語言:輸入秒數,將它轉換,用小時,分鍾,秒來表示,比如說多少秒變成幾時幾分幾秒

#include<stdio.h>
intmain()
{
inth,m,s;
scanf("%d",&s);
h=s/3600;
m=s/60%60;
s%=60;
printf("%d:%d:%d ",h,m,s);
return0;
}

⑽ c語言編寫 輸入一個以秒為單位的時間值,將其轉化成「時:分:秒」的形式輸出,將轉換操作定義成函數

#include<stdio.h>
void trans(int sec){
int hour,min;
hour=sec/3600; //計算時 3600進制
min=(sec%3600)/60; //計算分 60進制
sec=(sec%3600)%60; //計算秒 餘下的全為秒數
printf("%d時:%d分:%d秒\n",hour,min,sec);
}
int main(){
int sec;
printf("請輸入秒數:\n");
scanf("%d",&sec);
trans(sec);
return 0;
}
可以自己試試