c语言高手进。 帮我编程下 。 小弟感激不尽~

来自:    更新日期:早些时候
c语言编程软件如何下载?~

http://www.ijbc.net/index.php?m=content&c=index&a=show&catid=31&id=4
Microsoft Visual C 6.0 简体中文企业版

void strncpy(char *str1,const char *str2,int n)
{
int i;
for(i=0;i<n;i++)str1[i]=str2[i];
}
void strncat(char *str1,const char *str2,int n)
{
char *str3;
strncpy(str3,str2,n);
strcat(str1,str3);
}
int strncmp(char *str1,char *str2,int n)
{
char *str3,*str4;
strncpy(str3,str1,n);strncpy(str4,str2,n);
return strcmp(str3,str4);
}

#include<stdio.h>

int main(void)
{
int yearB=0, monthB=0, dayB=0;
int yearE=0, monthE=0, dayE=0;
int difYear, difMonth;
// 输入日期1
printf("Input the beginning date(yyyy.mm.dd)\n");
scanf("%d.%d.%d", &yearB, &monthB, &dayB);
// printf( "%d.%d.%d\n", yearB, monthB, dayB); 这行是我测试用的,甭管
// 检验日期1的合法性
switch(monthB)
{
case 2:
if( dayB<=0 || dayB>29 )
{
printf("Illegal date. exiting...");
exit(1);
}
else if( dayB==29 && !((yearB%4==0&&yearB%100!=0)||yearB%400==0) )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 4:
case 6:
case 9:
case 11:
if( dayB<=0 || dayB>30 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if( dayB<=0 || dayB>31 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

default:
printf("Illegal date. Exiting...");
exit(1);
break;
}

// 输入日期2
printf("Input the end date(yyyy.mm.dd)\n");
scanf("%d.%d.%d",&yearE,&monthE,&dayE);
// printf("%d.%d.%d\n", yearE, monthE, dayE); 甭管
// 检验日期2的合法性
switch(monthE)
{
case 2:
if( dayE<=0 || dayE>29 )
{
printf("Illegal date. Exiting...");
exit(1);
}
else if( dayE==29 && !((yearE%4==0&&yearE%100!=0)||yearE%400==0) )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 4:
case 6:
case 9:
case 11:
if( dayE<=0 || dayE>30 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if( dayE<=0 || dayE>31 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

default:
printf("Illegal date. Exiting...");
exit(1);
break;
}

// 检验日期1是否在日期2之前
if(
(yearB>yearE)
|| ((yearB==yearE)&&(monthB>monthE))
|| ((yearB==yearE)&&(monthB==monthE)&&(dayB>dayE))
)
{
printf("Error! Beginning date is later than end date. Exiting...\n");
exit(1);
}

// 相隔年数
if(monthE>monthB || (monthE==monthB&&judge_lastDay(yearE,monthE,dayE)) )
{
difYear = yearE-yearB;
}
else
{
difYear = yearE-yearB-1;
}

// 相隔完整月数
if( judge_lastDay(yearE, monthE, dayE) )
{
difMonth = (monthE-monthB+12)%12;
}
else
{
difMonth = (monthE-monthB+11)%12;
}

// 输出
printf( "There are %d year(s) and %d month(s) from beginning date to end date.\n", difYear, difMonth );

}

// 月末日期判断函数
int judge_lastDay( int year, int month, int day )
{
switch(day)
{
case 28:
if( month==2 && !((year%4==0&&year%100!=0)||year%400==0) )
return 1;
break;

case 29:
if(month==2 && ((year%4==0&&year%100!=0)||year%400==0))
return 1;
break;

case 30:
if( month==4||month==6||month==9||month==11)
return 1;
break;

case 31:
if( month==1||month==3||month==5||month==7||month==8||month==10||month==12)
return 1;
break;

default:
return 0;
}
return 0;
}

1.

#include<stdio.h>

int main(void)
{
char input[63], c;
int i=0;

// 输入句子
printf("Input your sentence\n");
while((c=getchar())!='\n'&&i<63)
{
*(input+i)=c;
i++;
}
input[i]='\0';

// printf("%s\n", input);
i=0;

// 改变大小写
while(input[i]!='\0')
{
if( (input[i]<'A' || (input[i]>'Z'&&input[i]<'a') || input[i]>'z')
&& (input[i-1]>='a'&&input[i-1]<='z') )
{
input[i-1]-=32;
}
i++;
}
// 输出
printf("%s\n", input);

return 0;
}

2.完整月份的问题我还有些疑问,1月18日到4月15日之间是 2个完整月吗?应该不能用1月份的13天填补4月份吧?如果我理解有误,你把完整月计算部分改一下就行了。

#include<stdio.h>

int main(void)
{
int yearB=0, monthB=0, dayB=0;
int yearE=0, monthE=0, dayE=0;
int difYear, difMonth;
// 输入日期1
printf("Input the beginning date(yyyy.mm.dd)\n");
scanf("%d.%d.%d", &yearB, &monthB, &dayB);
// printf( "%d.%d.%d\n", yearB, monthB, dayB); 这行是我测试用的,甭管
// 检验日期1的合法性
switch(monthB)
{
case 2:
if( dayB<=0 || dayB>29 )
{
printf("Illegal date. exiting...");
exit(1);
}
else if( dayB==29 && !((yearB%4==0&&yearB%100!=0)||yearB%400==0) )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 4:
case 6:
case 9:
case 11:
if( dayB<=0 || dayB>30 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if( dayB<=0 || dayB>31 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

default:
printf("Illegal date. Exiting...");
exit(1);
break;
}

// 输入日期2
printf("Input the end date(yyyy.mm.dd)\n");
scanf("%d.%d.%d",&yearE,&monthE,&dayE);
// printf("%d.%d.%d\n", yearE, monthE, dayE); 甭管
// 检验日期2的合法性
switch(monthE)
{
case 2:
if( dayE<=0 || dayE>29 )
{
printf("Illegal date. Exiting...");
exit(1);
}
else if( dayE==29 && !((yearE%4==0&&yearE%100!=0)||yearE%400==0) )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 4:
case 6:
case 9:
case 11:
if( dayE<=0 || dayE>30 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
if( dayE<=0 || dayE>31 )
{
printf("Illegal date. Exiting...");
exit(1);
}
break;

default:
printf("Illegal date. Exiting...");
exit(1);
break;
}

// 检验日期1是否在日期2之前
if(
(yearB>yearE)
|| ((yearB==yearE)&&(monthB>monthE))
|| ((yearB==yearE)&&(monthB==monthE)&&(dayB>dayE))
)
{
printf("Error! Beginning date is later than end date. Exiting...\n");
exit(1);
}

// 相隔年数
if(monthE>monthB || (monthE==monthB&&judge_lastDay(yearE,monthE,dayE)) )
{
difYear = yearE-yearB;
}
else
{
difYear = yearE-yearB-1;
}

// 相隔完整月数
if( judge_lastDay(yearE, monthE, dayE) )
{
difMonth = (monthE-monthB+12)%12;
}
else
{
difMonth = (monthE-monthB+11)%12;
}

// 输出
printf( "There are %d year(s) and %d month(s) from beginning date to end date.\n", difYear, difMonth );

}

// 月末日期判断函数
int judge_lastDay( int year, int month, int day )
{
switch(day)
{
case 28:
if( month==2 && !((year%4==0&&year%100!=0)||year%400==0) )
return 1;
break;

case 29:
if(month==2 && ((year%4==0&&year%100!=0)||year%400==0))
return 1;
break;

case 30:
if( month==4||month==6||month==9||month==11)
return 1;
break;

case 31:
if( month==1||month==3||month==5||month==7||month==8||month==10||month==12)
return 1;
break;

default:
return 0;
}
return 0;
}

你觉得我写这么长的代码敢不调试运行就放上来吗?我这里完全可以运行,应该是编译器的问题,一般都是库函数所属头文件的问题。还有就是一些标识符转到文档编辑器里可能就不是合法符号了。你可以自己调试一下呀,编译器里错误和警告出现在哪一行都写的很清楚,实在不行再提问,难道都等别人喂着吃吗?

下面是我这里的输出,我用的gcc在windows下的兼容版本mingw。

F:\C\MyFile>gcc 83.c

F:\C\MyFile>a.exe
Input your sentence
areyousick alkdge alkg; dalsk.
areyousicK alkdgE alkG; dalsK.

F:\C\MyFile>gcc 84.c

F:\C\MyFile>a.exe
Input the beginning date(yyyy.mm.dd)
2002.12.1
Input the end date(yyyy.mm.dd)
2005.6.21
There are 2 year(s) and 5 month(s) from beginning date to end date.

F:\C\MyFile>

#include <stdio.h>
#define MAX 64

int main(void)
{
char a[MAX];
int i,n;

for(i=0;;i++)
{
scanf("%c",&a[i]);
if(a[i]=='\n')
break;
}
n=i;
for(i=0,flag=0;i<=n;i++)
{
if('a'<=a[i]&&a[i]<='z'||'A'<=a[i]&&a[i]<='Z')
flag=1;
else
{
if(flag==1)
{
a[i-1]=a[i-1]<='Z'?a[i-1]:a[i-1]-'a'+'A';
flag=0;
}
}
}
for(i=0;i<n;i++)
printf("%c",a[i]);
printf("\n");
return 0;
}

题目很繁琐,我想知道的是你是 不会做 还是 懒得做??

分有点少吧,兄弟


c语言高手进。 帮我编程下 。 小弟感激不尽~视频

相关评论:

相关主题精彩

版权声明:本网站为非赢利性站点,内容来自于网络投稿和网络,若有相关事宜,请联系管理员

Copyright © 喜物网