Details of the program: Write a C program that takes a 2-dimensional array arr as input (of size 4 x 4), multiply all the even elements in arr and store in a variable mult check if multiplying any two elements in arr equals mult. Check this for all possible pairs.
If any pair equals mult, print those pairs.
Otherwise, print “No pair found”
#include<stdio.h>
void main()
{
int arr[4][4];
int i,j,n,m,mult=1,p=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("\nValues:");
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]%2==0)
mult=arr[i][j]*mult;
}
}
printf("\nMatrix as follows\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%d ",arr[i][j]);
printf("\n");
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]%2==0)
{
for(n=i;n<4;n++)
{
for(m=j;m<4;m++)
{
if(arr[n][m]%2==0 && arr[n][m]*arr[i][j]==mult)
{
printf("\n Pair %d %d",arr[i][j], arr[n][m]);
p=1;
}
}
}
}
}
}
if(p==0)
printf(" Pair Not Found");
getch();
}
#include<stdio.h>
void main()
{
int arr[4][4];
int i,j,n,m,mult=1,p=0;
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
printf("\nValues:");
scanf("%d",&arr[i][j]);
}
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]%2==0)
mult=arr[i][j]*mult;
}
}
printf("\nMatrix as follows\n");
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
printf("%d ",arr[i][j]);
printf("\n");
}
for(i=0;i<4;i++)
{
for(j=0;j<4;j++)
{
if(arr[i][j]%2==0)
{
for(n=i;n<4;n++)
{
for(m=j;m<4;m++)
{
if(arr[n][m]%2==0 && arr[n][m]*arr[i][j]==mult)
{
printf("\n Pair %d %d",arr[i][j], arr[n][m]);
p=1;
}
}
}
}
}
}
if(p==0)
printf(" Pair Not Found");
getch();
}
No comments:
Post a Comment