Thursday, 21 June 2012

write a c program to calculate sum of major and minor element in diagnal element


/*write a c program to calculate sum of major and minor
element in diagnal element */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10],i,j,m,n,sum,max,min,k=0;
clrscr();
printf("\nenter the rows and coloumn:");
scanf("%d%d",&n,&m);
if(m==n)
{
printf("\nenter the element :\n");
for(i=0;i<n;i++)
for(j=0;j<n;j++)
scanf("%d",&a[i][j]);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
if(i==j)
{
b[k]=a[i][j];
k++;
}
}
}
printf("\ndisplay of diagnal element :\n");
for(i=0;i<k;i++)
{
printf("%d\t",b[i]);
}
max=b[0];
min=b[0];
for(i=1;i<k;i++)
{
if(b[i]>max)
max=b[i];
else
if(b[i]<min)
min=b[i];
}
sum=max+min;
printf("\nsum of major and minor diagnal element :%d",sum);
}
else
printf("not possible");
getch();
}
/*
enter the rows and coloumn:3 3                                                
                                                                               
enter the element :                                                            
4 5 6                                                                          
7 8 9                                                                          
1 2 3                                                                          
                                                                               
display of diagnal element :                                                  
4       8       3                                                              
sum of major and minor diagnal element :11                                    
*/

No comments: