一、要求输入年月日,输出这是这一年的第几天
int main ()
{
int year , mounth , day ;
printf("请输入今天的年月日,中间用空格隔开\n");
scanf("%d%d%d",&year,&mounth,&day);
int dath0 = 31 ;
int dath1 = 30 ;
int dath = 0 ;
int dath2 ;
if(year / 4 == 0 && year / 100 != 0 || year / 400 == 0 )
dath2 = 29 ;
else
dath2 = 28 ;
if ( mounth > 1 )
dath = dath + dath0 ;
if ( mounth > 2 )
dath = dath + dath2 ;
if ( mounth > 3 )
dath = dath + dath0 ;
if ( mounth > 4 )
dath = dath + dath1 ;
if ( mounth > 5 )
dath = dath + dath0 ;
if ( mounth > 6 )
dath = dath + dath1 ;
if ( mounth > 7 )
dath = dath + dath0 ;
if ( mounth > 8 )
dath = dath + dath1 ;
if ( mounth > 9 )
dath = dath + dath1 ;
if ( mounth > 10 )
dath = dath + dath0 ;
if ( mounth > 11 )
dath = dath + dath1 ;
if ( mounth > 12 )
dath = dath + dath0 ;
dath = dath + day ;
printf("今天是这一年的第%d天\n",dath);
return 0 ;
}
二、菱形空心输出
int main()
{
int a,b,n;
a = 1 ;
b = 1 ;
printf("请输入菱形的棱长\n");
scanf("%d",&n);
for(int i = 0 ; i <= n ; i++ )
{
for (int m = 0 ; m <= 2*n ; m ++)
{
if(m == n-i || m==n+i )
printf("*");
else
printf(" ");
}
printf("\n");
}
for(int i = 1 ; i <= n ; i++ )
{
for (int m = 0 ; m <= 2*n ; m ++)
{
if(m == i || m == 2*n-i )
printf("*");
else
printf(" ");
}
printf("\n");
}
return 0 ;
}
三、用 go to 写求质数
int main()
{
int num1 , num2 ;
printf("请输入您想找出从几到几的质数\n");
scanf("%d%d",&num1,&num2);
//for( int i = num1 ; i < num2 ; i++)
int i = num1 ;
start_1_1:
// {
if ( i > num2)
{
goto end_1_1 ;
}
int a = 2 ;
//for( int a = 2 ; a <= i ; a++ )
//{
start_2_1 :
if(a > i)
goto end_2_1 ;
if(i == a)
printf("%d ", i );
if( i%a == 0 )
{
//break ;
goto end_2_1;
}
a++;
goto start_2_1 ;
//}
end_2_1 :
i++;
goto start_1_1;
// }
end_1_1 :
return 0 ;
}