瑞星卡卡安全论坛技术交流区系统软件 C计算输出 闰年【分享】【求助】

12   1  /  2  页   跳转

C计算输出 闰年【分享】【求助】

C计算输出 闰年【分享】【求助】

#include "stdio.h"
main()
{
  int i,n,k;
  for(i=2000;i<=2500;i++)
  {
    if(i%4==0 && i%100!=0)
    printf("%d\n",i);
  }
  getch();
}

[用户系统信息]Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)
最后编辑2008-04-09 22:33:46
分享到:
gototop
 

#include "stdio.h"
main()
{
  int i,n,k;
  printf("shu lu zi fu\n");
  scanf("%4d",&i);
怎么在这里控制只接收输入的前四位数字,并且只接收0~9,其它字符忽略或者弹出错误提示?
    if(i%4==0 && i%100!=0)
    printf("%d si run nian \n",i);
    else printf("shi pin nian\n");
  getch();
}

怎么控制输入的是0~9??

因为我测试过了,输入afdio也会弹出提示:

shi pin nian
gototop
 

另有一个老老的问题:

数组多少维的区分方法??

a[0]a[1]a[2]a[3]
a[1]a[2]a[3]a[4]
a[2]a[3]a[4]
a[3]a[4]

是不是这就是一个四维数组??
gototop
 

引用:
【过客2007的贴子】#include "stdio.h"
main()
{
  int i,n,k;
  printf("shu lu zi fu\n");
  scanf("%4d",&i);
怎么在这里控制只接收输入的前四位数字,并且只接收0~9,其它字符忽略或者弹出错误提示?
    if(i%4==0 && i%100!=0)
    printf("%d si run nian \n",i);
    else printf("shi pin nian\n");
  getch();
}

怎么控制输入的是0~9??

因为我测试过了,输入afdio也会弹出提示:

shi pin nian
………………


可以增加一个验证呀,如输入的非数字,则提示输入错误~
gototop
 

#include "stdio.h"
main()
{
  int i,b;
  int z,x,y,l,m=0;
  printf("shu lu zi fu\n");
  scanf("%d",&i);
  for(b=0;b<4;b++)
  if(i>='0'&&i<='9')
  {
    z=i*1000;
    x=i*100;
    y=i*10;
    l=i;
    m=x+y+l+z;
    if(i%4==0 && i%100!=0)
    printf("%d si run nian \n",i);
    else printf("shi pin nian\n");
  }

  else printf("char error!\n");

  getch();
}

这是我原来想的,本来想用数组接收字符,却因为单个数组也可以接收几位数,所以失败..

这就是失败的产物..
gototop
 

scanf("%4d",&i);

这条可以控制接收前面四个字符,但是却无法发现字母..
gototop
 

C++:
四维数组
d[j][k][l]
gototop
 

C++:
四维数组
d[j][k][l][m]
gototop
 

I think your program is illogical.

if i%400==0

if(i%4==0 && i%100!=0)

I'll install the CN version Windows and discuss with you.
gototop
 

You can use char and change char to int.
gototop
 
12   1  /  2  页   跳转
页面顶部
Powered by Discuz!NT