Q.9 Write a C program to read in 10 integer numbers and print their average, minimum and maximum numbers. (AKTU. 2009-10)
Ans.
#include<stdio.h>
#include<conio.h>
#define n 10 /* number of integers */
int a[n]; /* array to hold numbers */
void input(void);
float average(int[ ]);
int minimum(int[ ]);
int maximum(int[ ]);
void main( )
{
clrscr();
input();
printf("\n The average of the numbers is: %f",average(a));
printf("\n The minimum of the numbers is: %d",minimum(a));
printf("\n The maximum of the numbers is: %d",maximum(a));
getch();
}
void input(void)
{
int i;
printf("\n Enter %d numbers\n",(int) n);
for(i = 0; i< n; i++)
scanf("%d",&a[i]);
}
float average(int a[])
{
float temp = 0.0;
int i;
for(i = 0; i < n; i++)
temp += a[i];
temp /= n;
return temp;
}
int minimum(int a[])
{
int min,temp, i;
min = a[0];
for(i = 0; i < n; i++)
if(min > a[i])
{
temp = min;
min = a[i];
a[i] = temp;
}
return min;
}
int maximum(int a[])
{
int max,temp, i;
max = a[0];
for(i = 0; i < n; i++)
if(max < a[i])
{
temp = max;
max = a[i];
a[i] = temp;
}
return max;
}
Q.10 Write a C program to add, multiply two N x N matrix. (AKTU. 2009-10)
Related Questions -
Q. Write a program to add the two matrixes A [4 x 4] and B [4 x 4] of positive integers. The result should be stored in matrix R. (AKTU. 2012 - 13)
Ans.
#include<stdio.h>
#include<conio.h>
#define N 2
double a[N][N]; /* first matrix */
double b[N][N]; /* second matrix */
double c[N][N]; /* sum of matrices */
double d[N][N]; /* product of matrices */
void input(void); /* to take input */
void output(void); /* to display output */
void add(void); /* to add matrices */
void multiply(void); /* to multiply matrices */
void main()
{
input();
add();
multiply();
output();
}
void input(void)
{
int i, j;
clrscr();
printf("\n Enter the elements of Matrix A\n");
for(i = 0; i < N; i++)
for(j = 0; j < N; j++)
{
printf("\n A[%d][%d] = ", i, j);
scanf("%lf",&a[i][j]);
}
printf("\n Enter the elements of Matrix B\n");
for(i = 0; i < N; i++)
for(j = 0; j < N; j++)
{
printf("\n B[%d][%d] = ", i, j);
scanf("%lf",&b[i][j]);
}
for(i = 0; i < N; i++)
for(j = 0; j < N; j++)
{
c[i][j] = 0.0;
d[i][j] = 0.0;
}
}
void add(void)
{
int i, j;
for(i = 0; i < N; i++)
for(j = 0; j < N; j++)
c[i][j] = a[i][j] + b[i][j];
}
void multiply(void)
{
int i, j, k;
for(i = 0; i < N; i++)
for(j = 0; j < N; j++)
for(k = 0; k < N; k++)
d[i][j] += a[i][k] * b[k][j];
}
void output(void)
{
int i, j;
printf("\n The SUM of Matrices\n");
for(i = 0; i < N; i++)
for(j = 0; j < N; j++)
{
printf("\n SUM[%d][%d] = %lf", i, j, c[i][j]);
}
printf("\n The Product of Matrices\n");
for(i = 0; i < N; i++)
for(j = 0; j < N; j++)
{
printf("\n PRODUCT[%d][%d] = %lf", i, j, d[i][j]);
}
printf("\nPress any key to exit");
getch();
}