第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

我的代碼是這樣的,還少了什么?

我的代碼是這樣的,還少了什么?

C++
吃雞游戲 2023-03-18 16:12:33
#include <iostream>using namespace std;#pragma comment(lib, "winmm.lib")#include<stdio.h>#include <windows.h>#include <string>#include <stdlib.h> #include <time.h>void dsptime(const struct tm* ptm){cout<<ptm->tm_hour<<":"<<ptm->tm_min<<":"<<endl;}void main(){time_t nowtime;nowtime=time(NULL);struct *local;local=localtime(time(NULL));srand(time(NULL));dsptime(local);int n;n=rand()%20;}我就是要表示下時間,然后用rand函數(shù)求下隨機(jī)數(shù),要怎么做???
查看完整描述

2 回答

?
蕭十郎

TA貢獻(xiàn)1815條經(jīng)驗(yàn) 獲得超13個贊

void main()
{
time_t nowtime;
nowtime=time(NULL);//獲取時間1970年1月1日00:00:00到當(dāng)前時刻的秒數(shù)
struct tm *local;//注意類型是tm struct 只是表示是結(jié)構(gòu)體,tm才是結(jié)構(gòu)體名稱
local=localtime(&nowtime);//將秒數(shù)轉(zhuǎn)化成本地時間,并轉(zhuǎn)成struct tm類型,該類型的各數(shù)據(jù)成員分別表示年月日時分秒。
dsptime(local);//顯示時間
srand(time(NULL));//產(chǎn)生時間種子
int n;
n=rand()%20;//產(chǎn)生隨機(jī)數(shù)
cout<<n<<endl;
}

查看完整回答
反對 回復(fù) 2023-03-21
?
湖上湖

TA貢獻(xiàn)2003條經(jīng)驗(yàn) 獲得超2個贊

時間:
#include <time.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/timeb.h>
#include <string.h>

void main()
{
char tmpbuf[128], ampm[] = "AM";
time_t ltime;
struct _timeb tstruct;
struct tm *today, *gmt, xmas = { 0, 0, 12, 25, 11, 93 };

/* Set time zone from TZ environment variable. If TZ is not set,
* the operating system is queried to obtain the default value 
* for the variable. 
*/
_tzset();

/* Display operating system-style date and time. */
_strtime( tmpbuf );
printf( "OS time:\t\t\t\t%s\n", tmpbuf );
_strdate( tmpbuf );
printf( "OS date:\t\t\t\t%s\n", tmpbuf );

/* Get UNIX-style time and display as number and string. */
time( <ime );
printf( "Time in seconds since UTC 1/1/70:\t%ld\n", ltime );
printf( "UNIX time and date:\t\t\t%s", ctime( <ime ) );

/* Display UTC. */
gmt = gmtime( <ime );
printf( "Coordinated universal time:\t\t%s", asctime( gmt ) );

/* Convert to time structure and adjust for PM if necessary. */
today = localtime( <ime );
if( today->tm_hour > 12 )
{
strcpy( ampm, "PM" );
today->tm_hour -= 12;
}
if( today->tm_hour == 0 ) /* Adjust if midnight hour. */
today->tm_hour = 12;

/* Note how pointer addition is used to skip the first 11 
* characters and printf is used to trim off terminating 
* characters.
*/
printf( "12-hour time:\t\t\t\t%.8s %s\n",
asctime( today ) + 11, ampm );

/* Print additional time information. */
_ftime( &tstruct );
printf( "Plus milliseconds:\t\t\t%u\n", tstruct.millitm );
printf( "Zone difference in seconds from UTC:\t%u\n", 
tstruct.timezone );
printf( "Time zone name:\t\t\t\t%s\n", _tzname[0] );
printf( "Daylight savings:\t\t\t%s\n", 
tstruct.dstflag ? "YES" : "NO" );

/* Make time for noon on Christmas, 1993. */
if( mktime( &xmas ) != (time_t)-1 )
printf( "Christmas\t\t\t\t%s\n", asctime( &xmas ) );

/* Use time structure to build a customized time string. */
today = localtime( <ime );

/* Use strftime to build a customized time string. */
strftime( tmpbuf, 128,
"Today is %A, day %d of %B in the year %Y.\n", today );
printf( tmpbuf );
}

Output

OS time: 21:51:03
OS date: 05/03/94
Time in seconds since UTC 1/1/70: 768027063
UNIX time and date: Tue May 03 21:51:03 1994
Coordinated universal time: Wed May 04 04:51:03 1994
12-hour time: 09:51:03 PM
Plus milliseconds: 279
Zone difference in seconds from UTC: 480
Time zone name:  
Daylight savings: YES
Christmas Sat Dec 25 12:00:00 1993

Today is Tuesday, day 03 of May in the year 1994.

隨機(jī)數(shù):
#include <stdlib.h>
#include <stdio.h>
#include <time.h>

void main( void )
{
int i;

/* Seed the random-number generator with current time so that
* the numbers will be different every time we run.
*/
srand( (unsigned)time( NULL ) );

/* Display 10 numbers. */
for( i = 0; i < 10;i++ )
printf( " %6d\n", rand() );
}


查看完整回答
反對 回復(fù) 2023-03-21
  • 2 回答
  • 0 關(guān)注
  • 346 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號