0% found this document useful (0 votes)
36 views5 pages

Output:: LAB 1: Exercise

This document contains 3 coding exercises with the following summaries: 1. A C program that takes in two numbers from the user, multiplies them together, and divides them, printing out the results. 2. A C program that prints a triangle pattern of stars where the number of rows is input by the user. 3. A C program that multiplies two matrices together where the user inputs the sizes and elements of the matrices, calculates the product, and prints out the resulting product matrix.

Uploaded by

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

Output:: LAB 1: Exercise

This document contains 3 coding exercises with the following summaries: 1. A C program that takes in two numbers from the user, multiplies them together, and divides them, printing out the results. 2. A C program that prints a triangle pattern of stars where the number of rows is input by the user. 3. A C program that multiplies two matrices together where the user inputs the sizes and elements of the matrices, calculates the product, and prints out the resulting product matrix.

Uploaded by

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

Name: HSM OSAMA (9736)

CLASSID:106302

LAB 1: Exercise
QUESTIONNO1
Code
int main()

int first, second, multiply;

float divide;

printf("Enter two Number\n");

scanf("%d%d", &first, &second);

multiply = first * second;

divide = first / second;

printf("Multiplication = %d\n", multiply);

printf("Division = %.2f\n", divide); // "%.2lf" to print two decimal digits

return 0;

Output:
QUESTIONNO2
Code
#include <stdio.h>

int main()

int i, j, rows;

//Input rows from user

printf("Enter number of rows: ");

scanf("%d", &rows);

//Iterate through rows

for(i=1; i<=rows; i++)

//Print spaces in decreasing order of row

for(j=i; j<rows; j++)

{
printf(" ");

//Print star in increasing order

for(j=1; j<=i; j++)

printf("*");

// Move to next line

printf("\n");

return 0;

Output
QUESTIONNO3
Code:
#include <stdio.h>
int main()
{
int m, n, p, q, c, d, k, sum = 0;
int first[10][10], second[10][10], multiply[10][10];
printf("Enter number of rows and columns of first matrix\n");
scanf("%d%d", &m, &n);
printf("Enter elements of first matrix\n");
for (c = 0; c < m; c++)
for (d = 0; d < n; d++)
scanf("%d", &first[c][d]);
printf("Enter number of rows and columns of second matrix\n");
scanf("%d%d", &p, &q);
if (n != p)
printf("The multiplication isn't possible.\n");
else
{
printf("Enter elements of second matrix\n");
for (c = 0; c < p; c++)
for (d = 0; d < q; d++)
scanf("%d", &second[c][d]);
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++) {
for (k = 0; k < p; k++) {
sum = sum + first[c][k]*second[k]}
multiply[c][d] = sum;
sum = 0;
}
}
printf("Product of the matrices:\n");
for (c = 0; c < m; c++) {
for (d = 0; d < q; d++)
printf("%d\t", multiply[c][d]);
printf("\n");
}
}
return 0;
}

Output:

You might also like