指针与数组练习题

题3 编写下列函数:
void split_time(long int total_sec,int *hr,int *min,int *sec);

total_sec是从午夜计算的秒数表示的时间。hr、min和sec都是指向变量的指针,这些变量在函数中将分别存储着按小时算(0-23)、按分钟算(0-59)和按秒算(0-59)的等价的时间。

答:程序如下
#include<stdio.h>
#include<stdlib.h>

void time_split(long int total_sec,int *hr,int *min,int *sec)
{

int i,j;
i=total_sec/60;
j=total_sec-i*60;
*sec=j;
if(i<60)
	{
		*min=i;
		*hr=0;
     }
else 
{
	int k;
	*hr=i/60;
	k=i-*hr*60;
	*min=k;
 }

}
int main()
{

long int total_sec;
int hr,min,sec;
printf("Enter total_second:");
scanf("%ld",&total_sec);
time_split(total_sec,&hr,&min,&sec);
printf("hr=%d,min=%d,sec=%d\n",hr,min,sec);

system("pause");
return 0;

}
在这里插入图片描述

  • 4
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值