A. 在c語言程序中如何編輯秒數,讓它按小時;分鍾,秒的形式輸出
您好,是這樣的:
1.定義三個變數
分別來存儲輸入的分鍾數、轉換的小時數和剩餘的分鍾數。
2.
從界面獲取輸入的分鍾數。
3.
計算結果。
4.
把結果輸出到界面。
//1
定義三個變數
分別來存儲輸入的分鍾數、轉換的小時數和剩餘的分鍾數
//2
從界面獲取輸入的分鍾數
//3
計算結果
//4
把結果輸出到界面
int
i,
h,
m;
Console.WriteLine("請輸入一個分鍾數:");
i
=
int.Parse(Console.ReadLine());
h
=
i/60;
m
=
i%60;
Console.WriteLine("{0}分等於{1}小時{2}分",
i,
h,
m);
Console.ReadKey();
B. C語言中輸入一任意秒(正整數),轉換成多少日多少時多少分多少秒輸出
#include<stdio.h>
intmain(){
unsigneds,seconds,minites,hours,days;
scanf("%u",&s);
days=s/(24*3600);
s%=24*3600;
hours=s/3600;
s%=3600;
minites=s/60;
seconds=s;
printf("%d天,%d小時,%d分鍾,%d秒 ",days,hours,minites,seconds);
return0;
}
C. 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;
}
可以自己試試
D. c語言,編程題 輸入一個以秒為單位的時間值,將其轉換為「時:分:秒」的形式輸出,將轉換操作定義為函數
#include <stdio.h>
main()
{
char s[24];
int sec;
scanf("%d", &sec);
s2hms(s,sec);
printf("%s\n",s);
}s2hms(char* str, int sec)
{
int h,m,s;
h = sec/3600;
m = sec/60 - 60* h;
s = sec - 3600* h - 60*m;
sprintf(str,"%d:%d:%d",h,m,s);
}
E. C語言:輸入某時刻的時數,分數,秒數,轉化成秒數輸出。
#include <stdio.h>
int main ( )
{
int hour , minute , second ;
scanf ( "%d%d%d" , &hour , &minute , &second) ;
second = hour * 3600 + minute * 60 + second;
printf ( "%d\n" , second ) ;
return 0 ;
}
//時鍾的*3600,分針的*60~
F. c語言 列印輸出時分秒毫秒
#include<stdio.h>
#include<Windows.h>
int main()
{
SYSTEMTIME st;
GetLocalTime(&st);
printf("%d點%d分%d秒%d毫秒\n",st.wHour,st.wMinute,st.wSecond,st.wMilliseconds);
return 0;
}
G. 求助!用c語言編程:按年月日輸出系統日期按時分秒輸出系統時間。要求包含結構體;高手謝謝了O(∩_∩)O~
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
struct MyTime
{
int year;
int month;
int day;
int hour;
int min;
int sec;
void set()
{
char buffer[10];
time_t tt = time( NULL);
struct tm * t = gmtime(&tt);
/*
size_t strftime( char *str, size_t maxsize, const char *fmt, struct tm *time );
功能:函數按照參數fmt所設定格式將time類型的參數格式化為日期時間信息,
然後存儲在字元串str中(至多maxsize 個字元)。用於設定時間不同類型的代碼為
*/
strftime(buffer,10,"%Y",t);
/*
atoi(char* str)
功能:將字元串str轉換成一個整數並返回結果
*/
year = atoi(buffer);
strftime(buffer,10,"%m",t);
month = atoi(buffer);
strftime(buffer,10,"%d",t);
day = atoi(buffer);
strftime(buffer,10,"%H",t);
hour = atoi(buffer);
strftime(buffer,10,"%M",t);
min = atoi(buffer);
strftime(buffer,10,"%S",t);
sec = atoi(buffer);
}
int print()
{
set();
return printf("%4d-%.2d-%.2d %.2d:%.2d:%.2d",year,month,day,hour,min,sec);
}
};
int main(int argc, char *argv[])
{
struct MyTime t;
int printCharNum = 0;
int i;
while(1)
{
printCharNum = t.print();
// 清屏
for(i = 0 ; i < printCharNum ; i ++)
{
printf("\b");
}
}
return 0;
}
H. c語言怎麼控制5秒時間出一個結果
c語言可以通過辯沒設置時間定時器5秒時間出一個結果。
C語言頭文件
C語言是一門面向過程、抽象化攜畝納的耐段通用程序設計語言,廣泛應用於底層開發。