0% found this document useful (0 votes)
8 views1 page

Exercises Sheet N°7 - PW

Uploaded by

articlarticl3
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)
8 views1 page

Exercises Sheet N°7 - PW

Uploaded by

articlarticl3
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/ 1

College year :2023/2024

1st Mathematics and Computer Science


Module: Algorithmics and Data structures 2

Exercises sheet N°7 – PW

Exercise n° 1 :
int main() {
int N, M;
Consider a matrix of integers A(N, M) printf("Enter the number of rows (N <= 50): ");
(N<=50,M<=100) • Write a PA that calculates scanf("%d", &N);
the sum of the elements of a line i. • Write a printf("Enter the number of columns (M <= 100): ");
PA that calculates the product of the elements scanf("%d", &M);
of a column j.
• Using the previous actions, write a program int A[MAX_ROWS][MAX_COLS];
which for a given matrix A displays the sum
of the elements of each row and the product printf("Enter the elements of the matrix A:\n");
of the elements of each column. for (int i = 0; i < N; i++) {
for (int j = 0; j < M; j++) {
Solution : scanf("%d", &A[i][j]);
#include <stdio.h> }
}
#define MAX_ROWS 50
#define MAX_COLS 100 printf("Sum of elements of each row:\n");
for (int i = 0; i < N; i++) {
int rowSum(int A[MAX_ROWS][MAX_COLS], int printf("Row %d: %d\n", i+1, rowSum(A, N, M,
N, int M, int i) { i));
int sum = 0; }
for (int j = 0; j < M; j++) {
sum += A[i][j]; printf("Product of elements of each column:\n");
} for (int j = 0; j < M; j++) {
return sum; printf("Column %d: %lld\n", j+1,
} columnProduct(A, N, M, j));
}
long long columnProduct(int
A[MAX_ROWS][MAX_COLS], int N, int M, int j) { return 0;
long long product = 1; }
for (int i = 0; i < N; i++) {
product *= A[i][j];
}
return product;
}

A.Y

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy