1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Find upper and lower diagonal of 3x3 matrices

Discussion in 'C' started by Ziaur Rahman, Oct 26, 2006.

  1. Ziaur Rahman

    Ziaur Rahman New Member

    Joined:
    Oct 22, 2006
    Messages:
    11
    Likes Received:
    1
    Trophy Points:
    0
    Occupation:
    Student
    Location:
    Pune
    The code to find upper and lower diagonal of 3x3 matrices

    Code:
    #include<conio.h>
    #include<stdio.h>
    void main()
    {
    	int a[3][3],i,j,k;
    	clrscr();
    	printf("\n Enter a Matrix 3x3:\n\n");
    	for(i=0;i<=2;i++)
    	{
    		for(j=0;j<=2;j++)
    		{
    			scanf("%d",&a[i][j]);
    		}
    	}
    	/* Displaying entered matrix 3x3*/
    	printf("\n The Matrix is:-\n");
    	for(i=0;i<=2;i++)
    	{
    		for(j=0;j<=2;j++)
    		{
    			printf("%d\t",a[i][j]);
    		}
    		printf("\n");
    	}
    	printf("\n");
    	printf("\n Lower diagonal:\n\n");
    	for(i=1;i<=2;i++)
    	{
    		for(j=0;j<i;j++)
    		{
    			printf("%d\t",a[i][j]);
    		}
    		printf("\n");
    	}
    	printf("\n \n");
    	printf("\n Upper diagonal\n");
    	for(i=0;i<2;i++)
    	{
    		for(j=i+1;j<=2;j++)
    		{
    			if(i==1)
    			{
    				printf("        ");
    				printf("%d",a[i][j]);
    			}
    			else
    				printf("%d\t",a[i][j]);
    			
    		}
    		printf("\n");
    	}
    	getch();
    }
     
  2. aisha.ansari84

    aisha.ansari84 New Member

    Joined:
    Feb 13, 2008
    Messages:
    82
    Likes Received:
    1
    Trophy Points:
    0
    i find some problem
     
  3. rahul.mca2001

    rahul.mca2001 New Member

    Joined:
    Feb 13, 2008
    Messages:
    103
    Likes Received:
    0
    Trophy Points:
    0
    no there is no problem
     

Share This Page