0% found this document useful (0 votes)
6 views4 pages

Practical Exam

The document contains three C programs: one to calculate the sum of even numbers between 50 and 150, another to multiply two matrices, and a third to find the intersection point of two lines. Each program includes user input prompts, calculations, and outputs the results. The document also includes sample outputs demonstrating the functionality of each program.

Uploaded by

kavyan2112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views4 pages

Practical Exam

The document contains three C programs: one to calculate the sum of even numbers between 50 and 150, another to multiply two matrices, and a third to find the intersection point of two lines. Each program includes user input prompts, calculations, and outputs the results. The document also includes sample outputs demonstrating the functionality of each program.

Uploaded by

kavyan2112
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

/*Question: Write a program to find the sum of all even numbers within 50 and 150*/

#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 the order of the 1st matrix in the format m n : 2 3


Enter the order of the 2nd matrix in the format p q: 3 4

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………………………………………………………………………………….

Enter the order of the 1st matrix in the format m n : 2 3


Enter the order of the 2nd matrix in the format p q: 2 2

The matrices are not comfortable to multiplication


--------------------------------
Process exited after 8.499 seconds with return value 0
Press any key to continue . . .*/
/*Question: Write a program to find the point of intersection of two straight lines on a
plane*/

#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………………………………………………………………………………….

Enter coefficients a1,b1 and c1 for the first line: 1 2 1


Enter coefficients a2,b2 and c2 for the second line: 2 3 5
The point of intersection is: (-7.000000,3.000000)

--------------------------------
Process exited after 7.649 seconds with return value 0
Press any key to continue . . .*/

You might also like