當前位置:首頁 » 編程語言 » c語言顯示比賽時間地點
擴展閱讀
webinf下怎麼引入js 2023-08-31 21:54:13
堡壘機怎麼打開web 2023-08-31 21:54:11

c語言顯示比賽時間地點

發布時間: 2023-08-23 05:38:19

1. c語言 輸入時間顯示不同時間段

#include <stdio.h>


int main()

{

//int a[10];

int time;

char c;

int m;

printf("請輸時間: ");

scanf("%d%c%d",&time,&c,&m);

if(0<=time&&time<=5)

{

if(0<=m&&m<9)

printf("凌晨好,現在是%d%c0%d",time,c,m);

printf("凌晨好,現在是%d%c%d",time,c,m);

}

if(5<time&&time<=8)

{

if(0<=m&&m<9)

printf("早上好,現在是%d%c0%d",time,c,m);

printf("早上好,現在是%d%c%d",time,c,m);

}

if(8<time&&time<=11)

{

if(0<=m&&m<9)

printf("上午好,現在是%d%c0%d",time,c,m);

printf("上午好,現在是%d%c%d",time,c,m);

}

if(11<time&&time<=13)

{

if(0<=m&&m<9)

printf("中午好,現在是%d%c0%d",time,c,m);

printf("中午好,現在是%d%c%d",time,c,m);

}

if(13<time&&time<=18)

{

if(0<=m&&m<9)

printf("下午好,現在是%d%c0%d",time,c,m);

printf("下午好,現在是%d%c%d",time,c,m);

}

if(18<time&&time<24)

{

if(0<=m&&m<9)

printf("晚上好,現在是%d%c0%d",time,c,m);


printf("晚上好,現在是%d%c%d",time,c,m);

}

return 0;

}


ok

2. C語言顯示系統時間

#include<stdio.h>
#include<time.h>
intmain()
{
time_trawtime;
structtm*timeinfo;
time(&rawtime);
timeinfo=localtime(&rawtime);
printf("Thecurrentdate/timeis:%s",asctime(timeinfo));

return0;
}

time_t//時間類型(time.h定義)
structtm{//時間結構,time.h定義如下:
inttm_sec;
inttm_min;
inttm_hour;
inttm_mday;
inttm_mon;
inttm_year;
inttm_wday;
inttm_yday;
inttm_isdst;
}
time(&rawtime);//獲取時間,以秒計,從1970年1月一日起算,存於rawtime
localtime(&rawtime);//轉為當地時間,tm時間結構
asctime()//轉為標准ASCII時間格式:
//就是直接列印tm,tm_year從1900年計算,所以要加1900,月tm_mon,從0計算,所以要加1

3. c語言中什麼函數可以顯示實時時間用visualc++

主要就下面這幾個函數,會用即可。

/* #include <time.h>
庫函數
1 char *asctime(const struct tm *timeptr)
返回一個御啟指向字元串的指針,它代表了結構 timeptr 的日期和時間。
2 clock_t clock(void)
返回程序執行起(一般為程序的開頭),處理器時鍾所使用的時間。
3 char *ctime(const time_t *timer)
返回一個表示當地時間的字元串,當地時間是基於參數 timer。
4 double difftime(time_t time1, time_t time2)
返回 time1 和 time2 之間相差的秒數 (time1-time2)。
5 struct tm *gmtime(const time_t *timer)
timer 的值被分鎮桐如解為 tm 結構,並用協調世界時(UTC)也被稱為格林尼治標准時間(GMT)表示。
6 struct tm *localtime(const time_t *timer)
timer 的值被分解為 tm 結構,並用本地時區表示。
7 time_t mktime(struct tm *timeptr)
把 timeptr 所指向的結構轉換為一個依據本地時區的 time_t 值。
8 size_t strftime(char *str, size_t maxsize, const char *format, const struct tm *timeptr)
根據 format 中定義的格式化規則,格式化結構 timeptr 表示的時間,並把它存儲在 str 中。
9 time_t time(time_t *timer)
計算當前日歷時間,輪侍並把它編碼成 time_t 格式。
*/

4. 用C語言編寫一個程序顯示日期

#include
<stdio.h>
#include
<windows.h>
main()
{
//定義一個時間結構存儲時間數據;
SYSTEMTIME
*stm;
//定義了十二個月份的數組,用的時候直接調用
char
month[12][10]
=
{"January","February","March",
"April","May","June","July","August",
"September","October","November","December"};
//為時間結構體申請空間(c語言中必須)
stm
=
(SYSTEMTIME*)malloc(sizeof(SYSTEMTIME));
//獲取系統時間
GetSystemTime(stm);
//顯示時間
printf("%d\st
%s
%d",stm->wDay,month[stm->wMonth-1],stm->wYear);
}

5. 設有N個運動員要進行羽毛球比賽,用C語言設計一個滿足一下要求的比賽日程表

#include<stdlib.h>
#include<stdio.h>
int **A;
int *schele;
int N =1;
int isodd(int x)
{
return x&1;
}
void print()
{
int i,j, row, col;
if(isodd(N))
{
row=N;
col=N+1;
}
else
{
row=N;
col=N;
}
printf("第1列是選手編號\n");
for(i=0;i<row; i++)
{
for(j=0;j<col; j++)
{
printf("%4d", A[i][j]);
}
printf("\n");
}
}
void init()
{ int i, n;
char line[100]={'\0'};
printf("請輸入選手人數:");
fgets(line,sizeof(line), stdin);
N=atoi(line);
if(N<=0) exit(-1);
if(isodd(N))
n=N+1;
else
n=N;
schele=(int *)calloc(n*n, sizeof(int));
A=(int **)calloc(n, sizeof(int *));
if(!schele || A==NULL) exit(-2);
for(i=0;i<n;i++)
{
A[i]=schele+i*n;
A[i][0]=i+1;
}
return;
}
void replaceVirtual(int m)
{
int i,j;
for(i=0;i<m-1;i++)
{
for (j=0;j<=m;j++)
A[i][j] = (A[i][j]==m)?0:A[i][j];
}
return;
}
void even(int m)
{
if(isodd(m)) return;
int i,j;
for (j=0;j<m;j++)
{
for (i=0;i<m;i++)
{
A[i+m][j]=A[i][j]+m;
}
}
for (j=m;j<2*m;j++)
{
for (i=0;i<m;i++)
{
A[i][j]=A[i+m][j-m];
}
for (i=m;i<2*m;i++)
{
A[i][j]=A[i-m][j-m];
}
}
return;
}
void odd(int m)
{
int i,j;
for (j=0;j<=m;j++)
{
for (i=0;i<m;i++)
{
if (A[i][j]!=0)
{
A[i+m][j]=A[i][j]+m;
}
else
{
A[i+m][j] = i+1;
A[i][j] = i+m+1;
}
}
}
for(i=0,j=m+1;j<2*m;j++)
{
A[i][j] = j+1;
A[ (A[i][j] -1) ][j] = i+1;
}
for (i=1;i<m;i++)
{
for (j=m+1;j<2*m;j++)
{
A[i][j] = ((A[i-1][j]+1)%m==0)?A[i-1][j]+1 :m + (A[i-1][j]+1)%m;
A[ (A[i][j]-1) ][j] = i+1;
}
}
return;
}
void make(int m)
{
if (isodd(m/2))
odd(m/2);
else
even(m/2);
}
void tournament(int m)
{
if(m==1)
{
A[0][0]=1;
return ;
}
else if(isodd(m))
{
tournament(m+1);
replaceVirtual(m+1);
return ;
}
else
{
tournament(m/2);
make(m);
}
return ;
}
void endprogram()
{
free(schele);
free(A);
}
int main()
{
init();
tournament(N);
print();
endprogram();
return 0;
}

6. C語言課程設計~~~ 要求編寫一段程序,題目是《校際運動會管理系統》

我這是源代碼已經調試過了,在VC++上運行成功了。
#include "stdio.h" /*I/O函數*/
#include "stdlib.h" /*其它說明*/
#include "string.h" /*字元串函數*/
#include "conio.h" /*屏幕操作函數*/
#include "mem.h" /*內存操作函數*/
#include "ctype.h" /*字元操作函數*/
#include "alloc.h" /*動態地址分配函數*/
struct score
{
int mingci;
char xuehao[8];
char mingzi[20];
float score[6];
}data,info[1000];
int i,j,k=0;
char temp[20],ch;
FILE *fp,*fp1;

void shuru()
{
if((fp=fopen("s_score.txt","ab+"))==NULL)
{
printf("cannot open this file.\n");
getch();exit(0);
}
for(i=0;i<=1000;i++)
{
printf("\nPlease shuru xuehao:");
gets(data.xuehao);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please shuru wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please shur huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];
fwrite(&data,sizeof(data),1,fp);
printf("another?y/n");
ch=getch();
if(ch=='n'||ch=='N')
break;
} fclose(fp);
}
void xianshi()
{
float s;int n;
if((fp=fopen("s_score.txt","rb+"))==NULL)
{
printf("Cannot reading this file.\n");
exit(0);
}
for(i=0;i<=1000;i++)
{
if((fread(&info[i],sizeof(info[i]),1,fp))!=1)
break;
}
printf("\nxuehao mingzi yuwen shuxue yingyu wuli huauxue zhongfen\n");
for(j=0,k=1;j<i;j++,k++)
{
info[j].mingci=k;
printf("%6s %8s %3.1f %3.1f %3.1f %3.1f %3.1f %3.1f\n",info[j].xuehao,info[j].mingzi,info[j].score[0],info[j].score[1],info[j].score[2],info[j].score[3],info[j].score[4],
info[j].score[5]);
}
getch();
fclose(fp);
}

void xiugai()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("Cannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xiugai xuehao:");
scanf("%d",&i); getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{
printf("xuehao:%s\nmingzi:%s\n",data.xuehao,data.mingzi);
printf("Please shuru mingzi:");
gets(data.mingzi);
printf("Please shuru yuwen score:");
gets(temp);data.score[0]=atof(temp);
printf("Please shuru shuxue score:");
gets(temp);data.score[1]=atof(temp);
printf("Please input yingyu score:");
gets(temp);data.score[2]=atof(temp);
printf("Please input wuli score:");
gets(temp);data.score[3]=atof(temp);
printf("Please input huaxue score:");
gets(temp);data.score[4]=atof(temp);
data.score[5]=data.score[0]+data.score[1]+data.score[2]+data.score[3]+data.score[4];

} fwrite(&data,sizeof(data),1,fp1);
}
fseek(fp,0L,0);
fseek(fp1,0L,0);
while((fread(&data,sizeof(data),1,fp1))==1)
{
fwrite(&data,sizeof(data),1,fp);
}

fclose(fp);
fclose(fp1);
}
void chazhao()
{
if((fp=fopen("s_score.txt","rb"))==NULL)
{
printf("\nCannot open this file.\n");
exit(0);
}
printf("\nPLease shuru xuehao chakan:");
scanf("%d",&i);
while(fread(&data,sizeof(data),1,fp)==1)
{
j=atoi(data.xuehao);
if(i==j)
{
printf("xuehao:%s mingzi:%s\nyuwen:%f\n shuxue:%f\n yingyu:%f\n wuli:%f\n huaxue:%f\n ",data.xuehao,data.mingzi,data.score[0],data.score[1],data.score[2],data.score[3],data.score[4],data.score[5]);
}getch();
}
}
void shanchu()
{
if((fp=fopen("s_score.txt","rb+"))==NULL||(fp1=fopen("temp.txt","wb+"))==NULL)
{
printf("\nopen score.txt was failed!");
getch();
exit(0);
}
printf("\nPlease input ID which you want to del:");
scanf("%d",&i);getchar();
while((fread(&data,sizeof(data),1,fp))==1)
{
j=atoi(data.xuehao);
if(j==i)
{

printf("Anykey will delet it.\n");
getch();
continue;
}
fwrite(&data,sizeof(data),1,fp1);
}
fclose(fp);
fclose(fp1);
remove("s_score.txt");
rename("temp.txt","s_score.txt");
printf("Data delet was succesful!\n");
printf("Anykey will return to main.");
getch();
}
main()
{
while(1)
{
clrscr(); /*清屏幕*/
gotoxy(1,1); /*移動游標*/
textcolor(YELLOW); /*設置文本顯示顏色為黃色*/
textbackground(BLUE); /*設置背景顏色為藍色*/
window(1,1,99,99); /* 製作顯示菜單的窗口,大小根據菜單條數設計*/
clrscr();
printf("*************welcome to use student manage******************\n");
printf("*************************menu********************************\n");
printf("* ========================================================= * \n");
printf("* 1>shuru 2>xiugai * \n");
printf("* 3>shanchu 4>chazhao * \n");
printf("* 5>xianshi 6>exit * \n");
printf("* * \n");
printf("* --------------------------------------------------------- * \n");
printf(" Please input which you want(1-6):");
ch=getch();
switch(ch)
{
case '1':shuru();break;
case '2':xiugai(); break;
case '3':shanchu(); break;
case '4':chazhao(); break;
case '5':xianshi(); break;
case '6':exit(0);
default: continue;
}
}