Practical Exam
Practical Exam
#include<stdio.h>
int main()
{
int sum = 0;
for(int i = 50;i<= 150; i++)
{
if(i%2 ==0)
{
sum += i;
}
}
printf("The sum of all even numbers between 50 and 150 is: %d\n",sum);
return 0;
}
/*……………………………………………………………………….OUTPUT………………………………………………………………………………….
The sum of all even numbers between 50 and 150 is: 5100
--------------------------------
Process exited after 0.05067 seconds with return value 0
Press any key to continue . . .*/
/*Question: Write any program to find the multiplication of two matrix */
#include <stdio.h>
int main()
{
int i, j, k, m, n, p, q;
int A[10][10],B[10][10],C[10][10];
printf("Enter the order of the 1st matrix in the format m n : ");
scanf("%d %d",&m,&n);
printf("Enter the order of the 2nd matrix in the format p q: ");
scanf("%d %d",&p,&q);
if(p==n)
{
printf("\nEnter a %d x %d matrix A:\n",m,n);
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
scanf("%d",&A[i][j]);
}
printf("\nEnter a %d x %d matrix B:\n",n,q);
for(i=0;i<n;i++)
{
for(j=0;j<q;j++)
scanf("%d",&B[i][j]);
}
printf("To multiply the matrix A\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
printf("%d\t",A[i][j]);
printf("\n");
}
printf("\nwith matrix B\n");
for(i=0;i<n;i++)
{
for(j=0;j<q;j++)
printf("%d\t",B[i][j]);
printf("\n");
}
printf("The product matrix AB is of order %d x %d, given as follows:\n",m,q);
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
for(k=0;k<n;k++)
C[i][j]+=A[i][k]*B[k][j];
printf("%d\t",C[i][j]);
}
printf("\n");
}
}
else
printf("\nThe matrices are not comfortable to multiplication");
}
/*……………………………………………………………………….OUTPUT………………………………………………………………………………….
Enter a 2 x 3 matrix A:
986584
Enter a 3 x 4 matrix B:
648470362891
To multiply the matrix A
9 8 6
5 8 4
with matrix B
6 4 8 4
7 0 3 6
2 8 9 1
The product matrix AB is of order 2 x 4, given as follows:
122 84 150 90
94 52 100 72
--------------------------------
Process exited after 49.16 seconds with return value 0
Press any key to continue . . .*/
/*……………………………………………………………………….OUTPUT………………………………………………………………………………….
#include<stdio.h>
int main()
{
float a1,b1,c1,a2,b2,c2,x,y,determinant;
printf("Enter coefficients a1,b1 and c1 for the first line: ");
scanf("%f %f %f",&a1,&b1,&c1);
printf("Enter coefficients a2,b2 and c2 for the second line: ");
scanf("%f %f %f",&a2,&b2,&c2);
determinant = a1*b2 - a2*b1;
if(determinant ==0)
{
printf("The lines are parallel or coincident.\n");
}
else
{
x=(b1*c2-b2*c1)/determinant;
y=(a2*c1-a1*c2)/determinant;
printf("The point of intersection is: (%2f,%2f)\n",x,y);
}
return 0;
}
/*……………………………………………………………………….OUTPUT………………………………………………………………………………….
--------------------------------
Process exited after 7.649 seconds with return value 0
Press any key to continue . . .*/