主题:怎样双行输出
nuoyakiss
[专家分:0] 发布于 2010-09-07 17:14:00
这个程序:
#ifndef _TM_DEFINED
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
#define _TM_DEFINED
#endif
#include <iostream.h>
#include <time.h>
int main(void)
{
struct tm *local;
long t;
time(&t);
cout << "The Calendar Time now is:" << t << endl ;
local = localtime(&t);
local->tm_year = local->tm_year + 1900;
local->tm_mon ++;
cout << "今天是: " << local->tm_year << "年" << local->tm_mon
<< "月" << local->tm_mday << "日" << "星期" << local->tm_wday
<<"当前的时间是:"<< local->tm_hour
<< "时" << local->tm_min << "分" << local->tm_sec <<"秒"
<< endl;
return 0;
}
怎么让它像这样输出:
今天是: 2005年12月20日,星期二
当前时间是:22时40分43秒
应该怎么做,改什么东西?还请赐教!
回复列表 (共3个回复)
沙发
强强 [专家分:4740] 发布于 2010-09-07 19:28:00
在要换行的地方加一个ENDL不就完了吗
板凳
nuoyakiss [专家分:0] 发布于 2010-09-07 21:50:00
拿着两个程序如何进行组合啊,最后成什么样?
#include "stdio.h"
#include "conio.h"
void main()
{
int leap_year(int y);
int count_leap(long year);
int monthdays(int month,long year);
void monthprint(long year,int month);
int month=0;
long year=0;
char choose;
do
{printf ("\n\nPlease input one integer number as 'year'(0~999999):\n");
scanf ("%ld",&year);
if (year<0||year>999999) printf ("WANNING:ERROR,please input again!");
}
while (year<0||year>999999);
printf ("\n\n");
do
{printf ("please input the month(1~12)\n\n");
scanf ("%d",&month);
if (month<=0||month>12) printf ("WANNING:ERROR,please input again!");
}
while (month<=0||month>12);
printf ("\n\n\n");
printf("\t\t\t\t%ld\t%d\n\n",year,month);
printf
("\n********************************************************************************\n");
printf("\t\t Sun\t Mon\t Tue\t Wen\t Thu\t Fri\t Sat\n");
monthprint(year,month);
printf("\n\n");
choose=getchar();
printf("Continue?(y/n):\n\n");
scanf("%c",&choose);
if (choose=='y'||choose=='Y') main(); /*main函数调用main函数本身*/
}
int leap_year(int y)//判断闰年
{ int i;
if (y%4==0&&y%100!=0||y%400==0) i=1;
else i=0;
return i;
}
int count_leap(long year)
{
int i=0,j,min,max;
if(year>2006) {min=2006;max=year;}
else {min=year+1;max=2006;}
for(j=min;j<max;j++)
if(leap_year(j)) i++;
return i;
}
int monthdays(int month,long year)
{
int sum=0,i,j;
if(year>=2006)
{ static int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};/*1~12月的每月天数*/
j=month-1;
if(leap_year(year)) t[1]=29;
else t[1]=28;
for(i=0;i<j;i++)
sum=sum+t[i];
}
else
{ static int t1[12]={31,30,31,30,31,31,30,31,30,31,0,31}; /*12~1月的每月天数*/
j=12-month;
if(leap_year(year)) t1[10]=29;
else t1[10]=28;
for(i=0;i<=j;i++)
sum=sum+t1[i];
}
return sum;
}
void monthprint(long year,int month)
{
static int t[12]={31,0,31,30,31,30,31,31,30,31,30,31};
int i,y,weekday=0;
long days=0;
if(leap_year(year)) t[1]=29;
else t[1]=28;
y=t[month-1];
if(year>2006)
{
days=(year-2006)*365+count_leap(year)+monthdays(month,year);
weekday=days%7;
}
else if(year<2006)
{days=(2005-year)*365+count_leap(year)+monthdays(month,year);
weekday=7-days%7;
}
else
{days=monthdays(month,year);weekday=days%7;}
for (i=1;i<=weekday+2;i++) /*由于上一行打印星期的时候空2个制表位,所以weekday要加2*/
printf ("\t");
for (i=1;i<=y;i++)
{if ((i+weekday-1)%7==0) printf ("\n\n\t\t%3d\t",i);
else printf ("%3d\t",i);};
printf
("\n********************************************************************************\n\n");
}
和
#ifndef _TM_DEFINED
struct tm
{
int tm_sec;
int tm_min;
int tm_hour;
int tm_mday;
int tm_mon;
int tm_year;
int tm_wday;
int tm_yday;
int tm_isdst;
};
#define _TM_DEFINED
#endif
#include <iostream.h>
#include <time.h>
int main(void)
{
struct tm *local;
long t;
time(&t);
cout << "The Calendar Time now is:" << t << endl ;
local = localtime(&t);
local->tm_year = local->tm_year + 1900;
local->tm_mon ++;
cout << "今天是: " << local->tm_year << "年" << local->tm_mon
<< "月" << local->tm_mday << "日" << "星期" << local->tm_wday
<<"当前的时间是:"<< local->tm_hour
<< "时" << local->tm_min << "分" << local->tm_sec <<"秒"
<< endl;
return 0;
}
3 楼
淘宝商盟 [专家分:30] 发布于 2010-09-26 13:55:00
寻找中国的最优秀的网商领袖精英
当今世界正经历着全球经济一体化的大潮,中国本土企业也因此面临着前所未有的机遇与挑战。
在这场洗礼中,哪些互联网平台有能力成为世界级的电子商务平台?网商精英要怎样做,才能最终成长为世界级网商精英领袖?
淘宝商盟平台震撼登场,携手淘宝30万商家联盟购物商城。
平台刚刚启动,互联网的网商精英请咨询qq: 908889846
占领市场第一先机,合力打造网商系统!
淘宝商盟官网 www.taobaosm.com
http://blog.sina.com.cn/tbsm8
淘宝商盟奖励制度
我来回复