1 条题解

  • 0
    @ 2021-6-15 10:11:08

    C :

    #include<stdio.h>
    int main()
    {
    	int a1,a2,i,a3,s=2;
    	a1=0;a2=1;
    	printf("%d %d",a1,a2);
    	for(i=3;i<=30;i++)
    	{
    		a3=a1+a2;s++;
    		if(s%5==1)printf("%d",a3);else printf(" %d",a3);
    		if(s%5==0)printf("\n");
    		a1=a2;
    		a2=a3;
    	}
    	return 0;
    }
    

    C++ :

    #include<iostream>
    using namespace std;
    int main()
    {
      int a=0,b=1,c;
      cout<<a<<" "<<b<<" ";
      for (int i=3;i<=30;++i)
        {
          c=a+b;
    		if (i%5==0)
    		cout<<c<<endl;
    		else
    			cout<<c<<" ";
    		a=b;b=c;
         }
    	return 0;
    }
    

    Pascal :

    program bnhg;
    var
      a:array[0..29] of longint;
      i,s:integer;
      begin
        s:=0;
        a[0]:=0;
        a[1]:=1;
        for i:=2 to 29 do
        a[i]:=a[i-1]+a[i-2];
        for i:=0 to 29 do
        begin
          inc(s);
          if s<>5 then write(a[i],' ')
          else
          begin
            writeln(a[i]);
            s:=0;
          end;
        end;
    end.
    
    • 1

    信息

    ID
    386
    时间
    1000ms
    内存
    128MiB
    难度
    (无)
    标签
    递交数
    0
    已通过
    0
    上传者