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

Suma Elementelor Prime Dintr-O Matrice

The document contains code to calculate the sum of prime numbers in a two-dimensional matrix. It prompts the user to enter the number of rows and columns, then elements for the matrix. Two nested for loops iterate through the matrix, a separate loop checks if each element is prime, and prime elements are added to a running sum. Finally, the sum is printed.

Uploaded by

Ioan Martha
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)
372 views1 page

Suma Elementelor Prime Dintr-O Matrice

The document contains code to calculate the sum of prime numbers in a two-dimensional matrix. It prompts the user to enter the number of rows and columns, then elements for the matrix. Two nested for loops iterate through the matrix, a separate loop checks if each element is prime, and prime elements are added to a running sum. Finally, the sum is printed.

Uploaded by

Ioan Martha
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/ 1

/*

suma elementelor prime dintr-o matrice


*/

#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
int i, j, m, n;
int x[50][50];
printf("Introduceti numarul de linii si de coloane: ");
scanf("%d %d", &m, &n);
for (i = 0; i < m; i++)
{
for (j = 0; j < n; j++)
{
printf("Introduceti elementul de pe pozitia (%d,%d): ", i + 1, j + 1);
scanf("%d", &x[i][j]);
}
}

int s = 0;
int k, prim;

for (i = 0; i < m; i++)


{
for (j = 0; j < n; j++)
{
prim = 1;
for (k = 2; k <= ceil(x[i][j] / 2); k++)
{
if (x[i][j] % k == 0) prim = 0;
}
if (prim) s+= x[i][j];
}
}

printf("Suma elementelor prime = %d \n", s);

return 0;
}

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