public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "Srujan.K.V.S." <srujan@students.iiit.ac.in>
To: gcc-bugs@gcc.gnu.org
Subject: IS IT A BUG ????
Date: Wed, 28 Sep 2005 07:36:00 -0000	[thread overview]
Message-ID: <Pine.LNX.4.61.0509281243570.12385@students.iiit.net> (raw)


Hi,

 	 The following is the program to print magic squares.I`m getting 
wierd output when i remove the printf statement "printf("a")" from the 
code. The required output is obtained by simply substituting that by 
putchar('\0'). I would be very glad if someone can let me know.
Please kindly help me regarding this.

Expecting an early rep,


Srujan.K.V.S


************************************************************************

//This is a simple program to design magic squares.
//A magic square is an arangment of numbers of numbers from 1 to n^2 such
// that any row, diagonal or column sums to the same. This program wil
  //work for only odd sized squares
#include<stdio.h>
#include<stdlib.h>
#include<math.h> 
main() {
         int n,x=1,i,j,k,p,r,t;
         scanf("%d",&n);
         printf("%d\n",n);
         p=n*n;
         int a[n][n];
         for(i=0;i<n;i++)
                 for(j=0;j<n;j++)
                         a[i][j]=0;
         i=0;j=(n-1)/2;
         a[i][j]=1;// starting  1 int the first row central column. :)
         //We try to put the next number in the top left diagonal square
 	//from the recent numbered square.
         //If we have already numbered , we then number the square just
 	//below it.
         for(k=1;k<p;k++)
         {
                 if((i-1)<0&&j!=0&&a[n-1][j-1]==0) i=n;
                 if((j-1)<0&&i!=0&&a[i-1][n-1]==0) j=n;
                 if(i==0&&j==0&&a[n-1][n-1]==0)
                 {
                         i=n;j=n;
                 }
                 x++;
                 if(a[i-1][j-1]==0)
                 {
                         //The following printf statement if removed is 
alering the output when n=5
                         printf("a");

                         a[i-1][j-1]=x;
                         i=i-1;
                         j=j-1;

                 }
                 else
                 {
                         if((i+1)>(n-1)) i=-1;
                         a[i+1][j]=x;
                         i=i+1;
                         j=j;
                 }
         }
         for(i=0;i<n;i++)
         {
                 for(j=0;j<n;j++)
                         printf("%4d \t",a[i][j]);
                 printf("\n");
         }
}
*****************************************************************************



             reply	other threads:[~2005-09-28  7:36 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-09-28  7:36 Srujan.K.V.S. [this message]
2005-10-08  1:56 ` Jim Wilson
     [not found] <1a57b36d0803141049q771b54d2gf886f3dc2788309d@mail.gmail.com>
2008-03-14 17:58 ` is it a bug? Denisss
  -- strict thread matches above, loose matches on Subject: below --
2003-08-09 10:31 Is " Lev Assinovsky
2001-05-22  2:28 is " Arne Moe
1999-08-26  5:37 Is " Magnus Benngard
1998-04-30 10:25 is " JC Loredo-Osti
1998-04-30 13:15 ` Joe Buck
1998-04-30 13:15   ` JC Loredo-Osti
1997-12-08  3:17 Is it a bug ? knizhnik
1997-12-08 12:01 ` Alexandre Oliva

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.61.0509281243570.12385@students.iiit.net \
    --to=srujan@students.iiit.ac.in \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).