作业贴
本帖最后由 yangbing1990 于 2010-11-16 12:36 编辑显示菱形#include<stdio.h>
main()
{
char Len=0;
char Middle=0;
char i,j;
printf("Qing Shu Ru Lin Xin De Bian Chang:");
scanf("%d",&Middle);
printf("\n\n");
Len=Middle*2-1;
for(i=1;i<=Len;i++) /*hang*/
{
for(j=1;j<=Len;j++)/*Lie*/
{
if((i==1 || i==Len) && j==Middle)
{
printf("*");
continue;
}
if((j==1 || j==Len) && i==Middle)
{
printf("*");
continue;
}
if(Middle-i+1==j || Middle+i-1==j)
{
printf("*");
continue;
}
if(i-Middle+1==j || Len-i+Middle==j)
{
printf("*");
continue;
}
printf(" ");
}
printf("\n");
}
}
20个人围成一个圈 从7开始报数从0开始报 报到11的人出去 下个人从0开始......#include<stdio.h>
main()
{
char ShuZu;
char K=0;
char I=0;
char J=0;
for(K=0;K<20;K++)
{
ShuZu=K+1;
printf("%d",ShuZu);
if(K==19)
{
printf("\n");
}else{
printf(",");
}
}
K=6;
while(1)
{
for(;K<20;K++)
{
if(ShuZu)
{
J++;
if(J==12)
{
J=0;
printf("%d,",ShuZu);
ShuZu=0;
}
}
}
for(K=0;K<20;K++)
{
if(!ShuZu)
{
I++;
}
}
if(I==20) break;
I=K=0;
}
}
ASCII码表 查询
#include<stdio.h>
main()
{
unsigned char i=0;
printf("///////////// ASCIICODE /////////////////\n");
printf(" ");
for(i=0;i<16;i++)
{
printf("%x ",i);
if((i+1)%8==0 && (i+1)%16!=0)
{
printf(" -");
}
}
for(i=0;i<255;i++)
{
if(i%16==0)
{
printf("\nOx%x0:",i/16);
}
if(i%8==0 && i%16!=0)
{
if(i==8)
{
printf("-");
}else{
printf(" -");
}
}
if(i!='\r' && i!='\n' && i!='\t')
{
printf("%c ",i);
}else{
printf(" ");
}
}
printf("\n///////////// ASCIICODE /////////////////\n\n");
printf("\n///////////// QUERYASCII /////////////////\n");
while(1)
{
printf("\nPlease input your inquires the characters:");
scanf("%c",&i);
getchar();
printf("\nASCII Code Is:0x%x\n",i);
printf("\nTry again?(Y or N):");
scanf("%c",&i);
getchar();
if(i=='n' || i=='N')
{
break;
}
}
}
菱形我觉得在开始判断一下是奇数还是偶数,只有输入的是奇数才可能打印出菱形/:017 LS仔细看代码 你懂的... 万年历int runnian(int nian)
{
if( ( nian%4==0 && nian%100!=0 ) || ( nian%400==0 && nian%4==0 && nian%100==0) )
{
return 1;
}else{
return 0;
}
}
int yuetian(int nian,int i)
{
if(i==1 || i==3 || i==5 || i==7 || i==8 || i==10 || i==12)
{
return 31;
}
if(i==4 || i==6 || i==9 || i==11)
{
return 30;
}
if(i==2)
{
if(runnian(nian))
{
return 29;
}else{
return 28;
}
}
}
int fun(int nian,int yue)
{
int a,b,c,d,i,sum;
a=b=c=d=i=sum=0;
for(i=1;i<yue;i++)
{
d+=yuetian(nian,i);
}
d+=1;
a=(nian-1)/4;
b=(nian-1)/100;
c=(nian-1)/400;
sum=(nian-1)+a-b+c+d;
if(sum%7)
{
return sum%7;
}else{
return 7;
}
}
show(int xingqi,char shu)
{
int i,x=2,y=6,j,k=xingqi;
clrscr();
for(i=0;i<7;i++)
{
gotoxy(4+x,4);
printf("%d",i+1);
x+=4;
}
x=2;
printf("\n------------------------------------------");
for(j=1;j<=shu;j++)
{
gotoxy((4*xingqi)+x,y);
printf("%d",j);
x+=4;
if(!(k%7))
{
xingqi=1;
x=2;
y++;
k=0;
}
k++;
}
}
main()
{
int nian,yue,shu;
int i,xingqi;
printf("qing shu ru ri qi(1990 5):");
scanf("%d %d",&nian,&yue);
shu=yuetian(nian,yue);
xingqi=fun(nian,yue);
show(xingqi,shu);
}
页:
[1]