当前位置:首页 » 编程语言 » 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;
}
}