Click here to Skip to main content
15,889,877 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i need a combination like this
1 2 3 4 5 6 7 8 9
1 2 3 4 5 6 7 
1 2 3 4 5 6   8 
1 2 3 4 5   7 8 
1 2 3 4   6 7 8 
1 2 3   5 6 7 8 
1 2   4 5 6 7 8 
1   3 4 5 6 7 8 

For next iteration 
1 2 3 4 5 6 7 
1 2 3 4 5 6     9
1 2 3 4 5   7   9
1 2 3 4   6 7   9
1 2 3   5 6 7   9
1 2   4 5 6 7   9
1   3 4 5 6 7   9

like wise till
1   3 4 5 6 7 8 
1   3 4 5 6 7   9
1   3 4 5 6   8 9
1   3 4 5   7 8 9
1   3 4   6 7 8 9
1   3   5 6 7 8 9
1     4 5 6 7 8 9


What I have tried:

I have tired but not getting the logic. Please help me.
Posted
Updated 7-Feb-17 21:59pm
Comments
Peter Leow 8-Feb-17 1:09am    
"I have tired but not getting the logic" then show what you have tried.
OriginalGriff 8-Feb-17 1:59am    
What have you tried?
Where are you stuck?
What help do you need?

Look at the digits arranged as a square
(1,1)                      (1,9)
  \                         /
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
   1  2  3  4  5  6  7  8  9
  /                         \ 
(9,1)                      (9,9)


Then at iteration k you must show all the square items, but:
  • The ones of column k, that is (i,k).
  • The ones on the diagonal, that is (k, 10-k).
 
Share this answer
 
Quote:
I have tired but not getting the logic. Please help me.
First help yourself with method.
You have noted that
You don't understand the logic:
- try to draw by hand the result wanted for each iteration in order.
- try to analyze the differences between each iteration an note what t(he changes are.
By this point, you should have got the logic, otherwise, talk to your teacher.

are you sure about the 9 in first iteration ?
 
Share this answer
 
#include<stdio.h>

int main()
{
	int a[9]={1,2,3,4,5,6,7,8,9};
	int i,j=9,k;
	
	while(j>0)
	{
		for(i=1;i<8;i++)
		{
			for(k=0;k<9;k++)
			{
				if(k!=i&&k!=j)
			{
				printf("%d",a[k]);
				
			}
			else
			{
				printf(" ");
				continue;
			}
			}
			printf("\n");	
		}
		printf("\n");
		j--;
	}
	return 0;
}
 
Share this answer
 
Comments
Patrice T 8-Feb-17 4:08am    
A question and a solution without a single sentence!
Is it your solution or code that don't work ?
R!sh! 8-Feb-17 4:14am    
my solution. :)
Patrice T 8-Feb-17 4:17am    
So, use Accept answer (near "Solution 3") to signal it's solved and to close the question.
R!sh! 17-Feb-17 0:18am    
can you give your answer please??
R!sh! 8-Feb-17 4:14am    
finally i did it. :D

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900