Arimaa Forum (http://arimaa.com/arimaa/forum/cgi/YaBB.cgi)
Arimaa >> Off Topic Discussion >> My hobby
(Message started by: hanzack on Jun 19th, 2010, 7:24am)

Title: My hobby
Post by hanzack on Jun 19th, 2010, 7:24am
I want a program to plot all leap years from 1800 to 2007,

and add an indentation everytime it plot 10 leap years.

like this---->

1804 1808 1812 1816 1820 1824 1828 1832 1836 1840
1844 1848 1852 1856 1860 1864 1868 1872 1876 1880
1884 1888 1892 1896 1904 1908 1912 1916 1920 1924
1928 1932 1936 1940 1944 1948 1952 1956 1960 1964
1968 1972 1976 1980 1984 1988 1992 1996 2000 2004


I wrote like this--->


#include <stdio.h>
int main()
{
  int x;
 for(x = 1800; x <= 2007; x++){
  if(x % 4 == 0){
   if(x % 100 == 0){
    if(x % 400 == 0){
     printf("%d ", x);
     if((x - 1800) % 10 == 0){
      printf("\n");}else{}
    }else{}
   }else{
   printf("%d ", x);
    if((x - 1800) % 10 == 0){
      printf("\n");}else{}
   }else{]
   return 0;
}


I'm not sure that's like it, because I don't know how to use linux? centos?.

Please help me~~  ???

This is not my homework, so no need to hold back :-*

Title: Re: My hobby
Post by FireBorn on Jun 19th, 2010, 10:08am
By indentation, do you mean new line?

Also, you can use [ code ] tags to make it format correctly (the # button).

Get rid of the "else {}" things. They are unnecessary.

What output are you getting right now?

Title: Re: My hobby
Post by hanzack on Jun 19th, 2010, 3:58pm
yes i meant new lines. I didn't know the expression.

and I can't use linux at home so I don't know what output I get :-/

I want to use both windows xp and linux on my computer but don't know how to do it.

and once I download linux, I'm afraid I may not be able to use windows xp anymore ::)

Title: Re: My hobby
Post by FireBorn on Jun 19th, 2010, 4:16pm
There are C++ compilers for Windows. I believe Visual Studio Express is free. http://www.thefreecountry.com/compilers/cpp.shtml

I think in order to use linux and windows dualboot you'll have to reformat the drive first. Unless you have another one, maybe. I'm not sure of the details either.

Title: Re: My hobby
Post by hanzack on Jun 19th, 2010, 10:15pm
Thank you FireBorn!

I got this--->

1804 1808 1812 1816 1820
1824 1828 1832 1836 1840
1844 1848 1852 1856 1860
1864 1868 1872 1876 1880
1884 1888 1892 1896 1904 1908 1912 1916 1920
1924 1928 1932 1936 1940
1944 1948 1952 1956 1960
1964 1968 1972 1976 1980
1984 1988 1992 1996 2000
2004

How come ??? :'(


please tell me how to make a new line evrytime it plots 10 leap years

Title: Re: My hobby
Post by Oystein on Jun 20th, 2010, 2:46am
Make a counter for the number of years that has been plotted. Then use this counter instead of the year to check if you should add a new line.

Title: Re: My hobby
Post by hanzack on Jun 20th, 2010, 8:37pm
I wrote like this--->

#include <stdio.h>
int main()
{  
  int x, y = 0;
 for(x = 1800; x <= 2007; x++){
  if(x % 4 == 0 && ((x % 100) != 0 || x % 400 == 0))
        printf("%d ", x);y++;
 if(y % 10 == 0){
       printf("\n");]
   return 0;
}


and got this--->

1804 1808
1812 1816
1820 1824 1828
1832 1836
1840 1844 1848
1852 1856
1860 1864 1868
1872 1876
1880 1884 1888
1892 1896
1904 1908
1912 1916
1920 1924 1928
1932 1936
1940 1944 1948
1952 1956
1960 1964 1968
1972 1976
1980 1984 1988
1992 1996
2000 2004

My pc hates me! help meee! awawawa :(

Title: Re: My hobby
Post by hanzack on Jun 20th, 2010, 9:01pm
Thank you very much!
I made it!
:-*

Title: Re: My hobby
Post by knarl on Jun 20th, 2010, 9:37pm
The problem is you were printing a new line after every leap year where a multiple of 10 years had elapsed since 1800, and as correctly mentioned earlier in this thread, you could index the number of leap years with a separate variable.

Here's some reformatted, corrected code:

#include <stdio.h>
int main()
{
     int x,leap=0;
     
     for(x = 1800; x <= 2007; x++)
     {
           if((x%4 == 0) && ((x%100 != 0)||(x%400 == 0)))
           {
                 leap++;
                 if(leap%10 == 0)
                 {
                       printf("%d \n", x);
                 }
                 else
                 {
                       printf("%d ", x);
                 }
           }
     }
   return 0;
}

Title: Re: My hobby
Post by knarl on Jun 20th, 2010, 9:46pm
By the way. I use a nice free C/C++ development environment for windows (cross platform) called dev C++ by bloodshed http://www.bloodshed.net/

It's licence is GNU.

Cheers,
knarl.

Title: Re: My hobby
Post by Polyfractal on Jun 21st, 2010, 6:10am
I believe Visual Studio Express (http://www.microsoft.com/express/windows/) is free too, if you want to use a Microsoft product. :)

Title: Re: My hobby
Post by hanzack on Jun 22nd, 2010, 12:04am
Thank you very much knarl Polyfractal!!!

The information is ultra hyper helpful to me.

I'm very happy ,so I have no choice but dance!

  &#9834;&#9834;&#12541;(&#969;&#12539;&#12541;)(&#12494;&#12539;&#969;)&#65417;&#9834;&#9834;

:D

Title: Re: My hobby
Post by Arimabuff on Jun 22nd, 2010, 7:40am

on 06/22/10 at 00:04:55, hanzack wrote:
Thank you very much knarl Polyfractal!!!

The information is ultra hyper helpful to me.

I'm very happy ,so I have no choice but dance!

  &#9834;&#9834;&#12541;(&#969;&#12539;&#12541;)(&#12494;&#12539;&#969;)&#65417;&#9834;&#9834;

:D

I think that's Japanese for "I don't have that font".



Arimaa Forum » Powered by YaBB 1 Gold - SP 1.3.1!
YaBB © 2000-2003. All Rights Reserved.