Posts

Showing posts from September 21, 2012

SUM OF LEFT AND RIGHT DIAGONAL IN AN ARRAY

Image
LIST OF PROGRAMS #include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
int a[100][100],sum=0,sum2=0,no2,no3,no;
clrscr();

printf("enter rows and columns of 1st array:- \n ");
scanf("%d",&no);
scanf("%d",&no2);

no3=no-1;
if(no==no2)
{
printf("ENTER NUMBERS IN ARRAY \n");
for(i=0;i<no;i++)
for(j=0;j<no2;j++)
 { fflush(stdin);
scanf("%d",&a[i][j]);
 }

printf("ENTERED ARRAY \n");
for(i=0;i<no;i++)
   {
for(j=0;j<no2;j++)
printf("\t %d",a[i][j]);
printf("\n");
    }
for(i=0;i<no;i++)
sum+=a[i][i];

for(i=0;i<no;i++)
sum2+=a[i][no3-1];

printf("\nSUM OF LEFT DIAGONAL %d",sum);
printf("\nSUM OF RIGHT DIAGONAL %d",sum2);
}
else
printf("WRONG INPUT");
getch();

}


LIST OF PROGRAMS

MULTIPLY TWO ARRAYS

Image
LIST OF PROGRAMS
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
int a[100][100],b[100][100],c[100][100],no,no2,no3,no4;
clrscr();

printf("enter rows and columns of 1st array:- \n ");
scanf("%d",&no);
scanf("%d",&no2);
printf("enter rows and columns of 2nd array:- \n ");
scanf("%d",&no3);
scanf("%d",&no4);

if((no==no3)&&(no2==no4))
{
printf("ENTER NUMBERS IN ARRAY 1 \n");
for(i=0;i<no;i++)
for(j=0;j<no2;j++)
 { fflush(stdin);
scanf("%d",&a[i][j]);
 }
printf("ENTER NUMBERS IN ARRAY 2 \n");
for(i=0;i<no3;i++)
for(j=0;j<no4;j++)
  { fflush(stdin);
scanf("%d",&b[i][j]);
  }

printf("ENTERED ARRAY OF 1st ARRAY \n");
for(i=0;i<no;i++)
   {
for(j=0;j<no2;j++)
printf("\t %d",a[i][j]);
printf("\n");
    }

printf("ENTERED ARRAY OF 2ND ARRAY \n");
for(i=0;i<no3;i++)
    {
for(j=0;j<no4;j++)

printf("\t %d",b[i]…

TRANSPOSE AN ARRAY

Image
LIST OF PROGRAMS

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
int a[100][100],b[100][100],no=0,no2=0;
clrscr();

printf("enter rows and columns:- \n ");
scanf("%d",&no);
scanf("%d",&no2);

printf("ENTER NUMBERS IN ARRAY\n");
for(i=0;i<no;i++)
for(j=0;j<no2;j++)
{ fflush(stdin);
scanf("%d",&a[i][j]);
}
printf("ENTERED ARRAY \n");
for(i=0;i<no;i++)
{
for(j=0;j<no2;j++)
{
printf("\t%d",a[i][j]);
}
printf("\n");
}

for(i=0;i<no;i++)
for(j=0;j<no2;j++)
  b[j][i]=a[i][j];

printf("TRANSPOSED  ARRAY \n");
for(i=0;i<no2;i++)
{
for(j=0;j<no;j++)
{ printf("\t%d",b[i][j]);
}
printf("\n");
}

getch();
}

LIST OF PROGRAMS