Acasa Tehnologie Matrice cifra de control

Matrice cifra de control

by Dragos Schiopu

>

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


void citire(int m, int n, int a[20][20],char c)
{
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
printf("%c[%i][%i]=",c,i,j);
scanf("%d",&a[i][j]);
}
}


void afisare(int m, int n, int a[20][20])
{
for(int i=1;i<=m;i++)
{
for(int j=1;j<=n;j++)
printf(" %d ",a[i][j]);
printf("n");
}
}

int suma_cifre(int nr)
{
int suma=0;
do
{
suma=suma+nr%10;
nr=nr/10;
}
while(nr!=0);
return suma;
}


main()
{
int m,n,ok,nr=0;
int a[20][20];

printf("m=");
scanf("%d",&m);

printf("n=");
scanf("%d",&n);

if(m==n)
{
printf("nCitire matricen");
citire(m,m,a,'A');
printf("Afisare matrice n");
afisare(m,m,a);
for(int i=1;i<=m-1;i++)
for(int j=i+1;j<=m;j++)
{
ok=1;
for(int k=2;k<=sqrt(a[i][j]);k++)
if(a[i][j]%k==0) ok=0;
if(ok==1) {nr=nr+1; printf(" %d ",a[i][j]);}
}

printf(" Nr cifra control: %d ",nr);
}
else printf("Eroare! m<>n!");
return 0;
}

s-ar putea sa-ti placa