Complete IIT AIEEE ICSE ISC PMT help forum
This is a free help Forum for Indian Students.
Complete IIT AIEEE ICSE ISC PMT help forum

Complete help forum for students preparing for icse iit aieee cbse pmt and other related exams.Stay updated about all 2011 exams.
 
HomeHome  PortalPortal  FAQFAQ  SearchSearch  RegisterRegister  MemberlistMemberlist  UsergroupsUsergroups  Log in  India NewsIndia News  
Keywords
2009 english CHEMISTRY java 2008 table time programs result class 2011 Results PAPERS SYLLABUS sample Icse timetable 10th board maths TEST practical computer Exam question MODEL
Latest topics
» optical fibre????
Fri May 18, 2012 8:54 pm by mahnoorbloch

» physics............
Fri May 18, 2012 8:43 pm by mahnoorbloch

» magnetism...........chapter
Fri May 18, 2012 8:33 pm by mahnoorbloch

» ac generator
Fri May 18, 2012 7:46 pm by mahnoorbloch

» Great website for maths
Sun May 06, 2012 9:39 am by mahnoorbloch

» BlueJ prog
Tue Apr 24, 2012 11:53 am by arryaan

» GBTU SEE 2012 22 April
Sat Apr 21, 2012 11:17 am by shreya94

» GBTU SEE or UPTU SEE 2012 Expected cutoff marks
Sat Apr 21, 2012 11:16 am by shreya94

» GBTU SEE 2012 UPTU SEE 2012 Solutions Answer key discussion
Sat Apr 21, 2012 11:15 am by shreya94

Top posters
abhas
 
Anu..i luv icse...:)
 
G-7
 
siya
 
Candy
 
jOhNy
 
Apurva
 
WinRrule
 
ambili
 
saif
 



Search if you can't find it here

Magic Square(odd order)

View previous topic View next topic Go down
AuthorMessage
sa12
Active member
Active member



PostSubject: Magic Square(odd order) Wed Feb 24, 2010 1:13 am

Magic Square odd order:[code]import java.io.*;
public class MagicSquare {
public static void main(String args[]) throws IOException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter (odd) size of Magic Square:");
int n=Integer.parseInt(in.readLine());
int a[][]= new int[n][n];
int i=0,j= ((n+1)/2)-1 ;
a[i][j]=1;
int counter=1;
while(counter< n*n){
int itemp=i, jtemp=j;
if (itemp==0) itemp=n-1; else itemp--;
if (jtemp==n-1) jtemp=0; else jtemp++;
if (a[itemp][jtemp]!=0) { itemp=(itemp+2)%n ; jtemp=j;}
a[itemp][jtemp]=++counter;
i=itemp; j=jtemp;
}
for(int y=0; y
Back to top Go down
View user profile
sa12
Active member
Active member



PostSubject: Re: Magic Square(odd order) Wed Feb 24, 2010 1:14 am

I don't know why posts are cut but aftr y=0
for(int y=0; y<n; y++){
for(int z=0; z<n ;z++){
System.out.printf("%2d",a[y][z]); System.out.print(" ");
}
System.out.println();
}

}
}
Back to top Go down
View user profile
saif
Active member
Active member



PostSubject: Re: Magic Square(odd order) Wed Feb 24, 2010 1:32 am

import java.io.*;
public class MagicSquare {
public static void main(String args[]) throws IOException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter (odd) size of Magic Square:");
int n=Integer.parseInt(in.readLine());
int a[][]= new int[n][n];
int i=0,j= ((n+1)/2)-1 ;
a[i][j]=1;
int counter=1;
while(counter< n*n){
int itemp=i, jtemp=j;
if (itemp==0) itemp=n-1; else itemp--;
if (jtemp==n-1) jtemp=0; else jtemp++;
if (a[itemp][jtemp]!=0) { itemp=(itemp+2)%n ; jtemp=j;}
a[itemp][jtemp]=++counter;
i=itemp; j=jtemp;
}
for(int y=0; y<n; y++){
for(int z=0; z<n ;z++){
System.out.printf("%2d",a[y][z]); System.out.print(" ");
}
System.out.println();
}

}
}


joined ur post WOW nice to see that i am not the only one who is awake till 1:30 today

Best of luck

I just made a prog. to generate truth table for three variable expression of type a.b+b.c+c.a+a.b.c+ .....
(single variable not allowed in expression)(input should be in ablove format only)
Back to top Go down
View user profile
sa12
Active member
Active member



PostSubject: Re: Magic Square(odd order) Wed Feb 24, 2010 1:36 am

I just started studying at 12:20. Didn't want to get into this situation but got into it nonethe less. Smile Note the System.out.printf in my program. The matrix that is printed is properly formatted.Anagrams via Recursion (though this will not come):</br>import java.io.*;
public class Anagrams {
public static void main(String args[])throws IOException {
BufferedReader in= new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter a word:");
String word=in.readLine();
System.out.println("The anagrams of the word are:");
printAnagrams("",word);
}
public static void printAnagrams(String prefix,String word){
if(word.length()<=1) System.out.println(prefix+word);
else {
for (int i=0;i<word.length();i++){
String current=word.substring(i,i+1);
String before=word.substring(0,i);
String after=word.substring(i+1);
printAnagrams(prefix+current,before+after);
}
}
}
}
Back to top Go down
View user profile

Magic Square(odd order)

View previous topic View next topic Back to top
Page 1 of 1

Permissions in this forum:You cannot reply to topics in this forum
Complete IIT AIEEE ICSE ISC PMT help forum :: ISC :: ISC 2010 [Class xii] :: Computer-