Union, intersection and difference of three arrays - c

In this code I try to create three arrays. With these three arrays I successflly tried to make the union. But when I want to make an Intersection and the difference I couldn't.
#include <stdio.h>
int main()
{
int dizi1Sinir, dizi1Deger; // ilk alt kumenin degiskenleri
int dizi2Sinir, dizi2Deger; // ikinci alt kumenin degiskenleri
int dizi3Sinir, dizi3Deger; // ucuncu alt kumenin degiskenleri
// BIRINCI ALT KUME TANIMLAMA ISLEMLERI
printf("ilk alt kumen kac elemanli olsun?\n");
scanf("%d", &dizi1Sinir);
int alt_kume_1[dizi1Sinir]; // ilk alt kume
for(dizi1Deger = 0; dizi1Deger < dizi1Sinir; dizi1Deger++)
{
printf("dizinin elemanlarini gir.\n %dnci eleman = ", dizi1Deger + 1);
scanf("%d", &alt_kume_1[dizi1Deger]);
}
// -------------------------------------------------------------------------------
//IKINCI ALT KUME TANIMLAMA ISLEMLERI
printf("ikinci alt kumen kac elemanlı olsun?\n");
scanf("%d", &dizi2Sinir);
int alt_kume_2[dizi2Sinir]; // ikinci alt kume
for(dizi2Deger = 0; dizi2Deger < dizi2Sinir; dizi2Deger++)
{
printf("dizinin elemanlarini gir.\n %dnci eleman = ", dizi2Deger + 1);
scanf("%d", &alt_kume_2[dizi2Deger]);
}
//UCUNCU ALT KUME TANIMLAMA ISLEMLERI
printf("ucuncu alt kumen kac elemanli olsun?\n");
scanf("%d", &dizi3Sinir);
int alt_kume_3[dizi3Sinir]; // ucuncu alt kume
for(dizi3Deger = 0; dizi3Deger < dizi3Sinir; dizi3Deger++)
{
printf("dizinin elemanlarini gir.\n %dnci eleman = ", dizi3Deger + 1);
scanf("%d", &alt_kume_3[dizi3Deger]);
}
//---------------------------------
int azami=dizi1Sinir+dizi2Sinir+dizi3Sinir;
int birlesim[azami];
int i;
for(i=0;i<azami;i++)
{
if(i<dizi1Sinir)
birlesim[i]=alt_kume_1[i];
else if(i-dizi1Sinir<dizi2Sinir)
birlesim[i]=alt_kume_2[i-dizi1Sinir];
else
birlesim[i]=alt_kume_3[i-dizi1Sinir-dizi2Sinir];
}
//-----------------------------
//Ayni Elemanlari Sil (-1)
for(i=0;i<azami;i++)
{
int tempSayi=birlesim[i];
int j;
for(j = 0;j<i;j++)
{
if(birlesim[j]==tempSayi)
{
birlesim[i]=-1;
}
}
}
printf("\nbirlesim = ");
for(i = 0; i < azami; i++)
{
if(birlesim[i]!=-1)
printf("%d ", birlesim[i]);
}

int main() {
//************************
printf("\ninsertion dizi_1 and dizi_2 : ");
intersection_two_arrays(alt_kume_1,dizi1Sinir,alt_kume_2,dizi2Sinir);
printf("\ninsertion dizi_1 and dizi_3 : ");
intersection_two_arrays(alt_kume_1,dizi1Sinir,alt_kume_3,dizi3Sinir);
printf("\ninsertion dizi_2 and dizi_3 : ");
intersection_two_arrays(alt_kume_2,dizi2Sinir,alt_kume_3,dizi3Sinir);
printf("\ninsertion dizi_1 dizi_2 and dizi_3 : ");
intersection_three_arrays(alt_kume_1,dizi1Sinir,alt_kume_2,dizi2Sinir,alt_kume_3,dizi3Sinir);
//...etc
//*************************
printf("\nDifference dizi_1 - dizi_2 : ");
differenceX_Y(alt_kume_1,dizi1Sinir,alt_kume_2,dizi2Sinir);
printf("\nDifference dizi_2 - dizi_1 : ");
differenceX_Y(alt_kume_2,dizi2Sinir,alt_kume_1,dizi1Sinir);
printf("\nDifference dizi_2 - dizi_3 : ");
differenceX_Y(alt_kume_2,dizi2Sinir,alt_kume_3,dizi3Sinir);
printf("\nDifference dizi_1 - dizi_2 and dizi_3 : ");
differenceX_YandZ(alt_kume_1,dizi1Sinir,alt_kume_2,dizi2Sinir,alt_kume_3,dizi3Sinir);
//...etc
//*************************
}
function 1 : Intersection of two sets
void intersection_two_arrays(int kume_1[], int sinir1 , int kume_2[] , int sinir2)
{
int i,j;
int value;
if(sinir1>sinir2) value=sinir2;
else value=sinir1;
int hold[value];
int h=0;
for(i=0; i<sinir1; i++) {
for(j=0; j<sinir2; j++) {
if(kume_1[i] == kume_2[j]) {
hold[h++] = kume_1[i];
continue;
}
}
}
if(h==0) {
printf("There is not common value");
}
else {
for(i=0; i<h; i++) {
printf("%d ", hold[i]);
}
}
}
function 2 : Intersection of three sets
void intersection_three_arrays(int kume_1[], int sinir1 , int kume_2[] , int sinir2,
int kume_3[], int sinir3)
{
int i,j;
int value;
if(sinir1>sinir2) value=sinir2;
else value=sinir1;
int hold[value];
int h=0;
for(i=0; i<sinir1; i++) {
for(j=0; j<sinir2; j++) {
if(kume_1[i] == kume_2[j]) {
hold[h++] = kume_1[i];
continue;
}
}
}
intersection_two_arrays(hold,h, kume_3,sinir3);
}
function 3 : Difference X-Y
void differenceX_Y(int kume_1[], int sinir1 , int kume_2[] , int sinir2)
{
int i,j;
int value;
if(sinir1>sinir2) value=sinir1;
else value=sinir2;
int hold[value];
int h=0;
int findEqual=0;
for(i=0; i<sinir1; i++) {
for(j=0; j<sinir2; j++) {
if(kume_1[i] == kume_2[j]) {
findEqual++;
continue;
}
}
if(findEqual==0) hold[h++] = kume_1[i];
findEqual=0;
}
if(h==0) {
printf("There is not different value.");
}
else {
for(i=0; i<h; i++) {
printf("%d ", hold[i]);
}
}
}
function 4 : Difference X-(Y and Z)
void differenceX_YandZ(int kume_1[], int sinir1 , int kume_2[] , int sinir2, int
kume_3[], int sinir3)
{
int i,j;
int value;
if(sinir1>sinir2) value=sinir1;
else value=sinir2;
int hold[value];
int h=0;
int findEqual=0;
for(i=0; i<sinir1; i++) {
for(j=0; j<sinir2; j++) {
if(kume_1[i] == kume_2[j]) {
findEqual++;
continue;
}
}
if(findEqual==0) hold[h++] = kume_1[i];
findEqual=0;
}
differenceX_Y(hold, h , kume_3, sinir3);
}

Related

Maze by recursive division not working - C

I'm having some trouble with my recursive division generated maze. I know there's something wrong about the recursion, but I just can't find a way to solve it.
I also know the code is really big and not optimized at all, but I'm working better on this issue later.
The red maze is what I'm generating and the purple one is what I'm trying to do:
What should I be doing to correct that?
Tnks.
#include <stdio.h>
#include <stdbool.h>
#include <time.h>
#define MAX 41
#define FUNDO 0
#define PAREDE 1
#define SAIDA 2
#define SOLUCAO 3
int num_aleat(int min, int max)
{
return rand()%(max-min+1)+min;
}
void paredes(int m[][MAX], int FINAL_i, int FINAL_j, int INICIO_i, int INICIO_j)
{
int i=0, j=0;
for(i=0; i<MAX; i++)
{
if (i!=FINAL_i && i!=INICIO_i)
m[i][j]=PAREDE;
}
i=0;
for(j=0; j<MAX; j++)
{
if (j!=INICIO_j)
m[i][j]=PAREDE;
else
m[i][j]=SAIDA;
}
j=0;
for(i=0; i<MAX; i++)
{
if (j!=FINAL_j && j!=INICIO_j)
m[i][j+MAX-1]=PAREDE;
}
i=0;
for(j=0; j<MAX; j++)
{
if (j!=FINAL_j)
m[i+MAX-1][j]=PAREDE;
else
m[i+MAX-1][j]=SAIDA;
}
j=0;
}
void pardede_gener(int m[][MAX], int min, int max, int x, int dir)
{
int i=0, passagem=0;
switch (dir)
{
case 1:
passagem=num_aleat(min, max);
printf("\nc\n");
for(i=min; i<=max; i++)
{
if(i!=passagem)
m[i][x]=PAREDE;
printf("\nd_%i_%i\n", i, x);
}
return;
break;
case 2:
passagem=num_aleat(min, max);
for(i=min; i<=max; i++)
{
if(i!=passagem)
m[x][i]=PAREDE;
}
return;
break;
}
return;
}
void div(int m[][MAX], int i, int j, int max_i, int max_j, int dir)
{
int parede_i=MAX, parede_j=MAX, flag=0;
if(dir==1)
{
while(1)
{
parede_j=num_aleat(j, max_j);
if (parede_j%2==0 && m[i+1][parede_j]==FUNDO && m[i+1][parede_j-1]!=PAREDE && m[i+1][parede_j+1]!=PAREDE || m[i+2][parede_j]!=PAREDE)
break;
else
break;
}
if(m[i+1][parede_j]!=PAREDE && m[i+1][parede_j-1]!=PAREDE && m[i+1][parede_j+1]!=PAREDE)
{
pardede_gener(m, i+1, max_i-1, parede_j, dir);
dir=2;
div(m, i, j, max_i, parede_j, dir);
div(m, i, parede_j, max_i, max_j, dir);
}
else
return;
}
else if(dir==2)
{
while(1)
{
parede_i=num_aleat(j, max_j);
if (parede_i%2==0 && m[parede_i][j+1]==FUNDO && m[parede_i-1][j+1]!=PAREDE && m[parede_i+1][j+1]!=PAREDE || m[parede_i][j+2]==PAREDE)
break;
else
break;
}
if(m[parede_i][j+1]!=PAREDE && m[parede_i-1][j+1]!=PAREDE && m[parede_i+1][j+1]!=PAREDE)
{
pardede_gener(m, j, max_j-1, parede_i-1, dir);
dir=1;
div(m, i, j, parede_i, max_j, dir);
div(m, parede_i, j, max_i, max_j, dir);
}
else
return;
}
}
bool resolve(int *m, int i, int j, int fi, int fj)
{
*(m + i*MAX + j)=SOLUCAO;
if(i==fi-1 && j==fj)
return true;
if (i+1<MAX && *(m + (i+1)*MAX + j)==FUNDO)
{
if(resolve(m, i+1, j, fi, fj))
return true;
}
if (i-1>=0 && *(m + (i-1)*MAX + j)==FUNDO)
{
if(resolve(m, i-1, j, fi, fj))
return true;
}
if (j+1<MAX && *(m + i*MAX + (j+1))==FUNDO)
{
if(resolve(m, i, j+1, fi, fj))
return true;
}
if (j-1>=0 && *(m + i*MAX + (j-1))==FUNDO)
{
if(resolve(m, i, j-1, fi, fj))
return true;
}
*(m + i*MAX + j)=FUNDO;
return false;
}
int main()
{
int lab[MAX][MAX];
int FINAL_i=0, FINAL_j=0, INICIO_i=0, INICIO_j=0, i=0, j=0;
srand(time(NULL));
FINAL_i=MAX-1;
while (INICIO_j%2==0 || FINAL_j%2==0)
{
INICIO_j=rand()%(MAX-2)+1;
FINAL_j=rand()%(MAX-2)+1;
}
zero(lab);
paredes(lab, FINAL_i, FINAL_j, INICIO_i, INICIO_j);
div(lab, 0, 0, MAX-1, MAX-1, 1);
// resolve(*lab, 1, INICIO_j, FINAL_i, FINAL_j);
return 0;
}

Ccrabble C program compiling but is not allowing the user to execute the file

The user is supposed to be prompted with several letters that they are to decode and then input their word which returns a score for that word.
I can get the program to compile but the program does not actually run. So I am not entirely sure where the issue lies within my code.I am relatively new at this.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>
#define num_letters_input 7
int main()
{
const int alphabet_count[26] = {8, 2, 2, 4, 12, 2, 3, 2, 9, 1, 1, 4, 2, 6, 8, 2, 1, 6, 4, 6, 4, 2, 2, 1, 2, 1};
const int alphabet_value[26] = {1,3,3,2,1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
int letter_set[26];
int size_letter_set = 26;
void generate_letter_set(int letter_set[], int size_letter_set, int num_letters) {
int random_a = rand() % 26;
int random_b = rand() % (alphabet_count[random_a]);
letter_set[random_a] = random_b;
printf("Your letters are: ");
for(int i=0; i < size_letter_set; i++) {
if(letter_set[i])
{
int num = letter_set[i];
while(num--)
printf("%c ", i+97);
}
}
printf("\n");
}
int read_word(char word[], int max_size_word) {
printf("Enter your word: ");
scanf("%s", word);
printf("%s \n", word);
int size_word = strlen(word);
if(size_word > max_size_word)
read_word(word, max_size_word);
return size_word;
}
bool check_word(char word[], int size_word, int letter_set[], int size_letter_set) {
int count_array[26];
for(int i=0; i<size_word; i++) {
count_array[word[i]-97]++;
}
for(int i=0; i<size_letter_set; i++) {
if(count_array[i] <= letter_set[i])
continue;
else {
return false;
}
return true;
}
int compute_word_value(char word[], int size_word) {
int word_value = 0;
for(int i=0; i<size_word; i++) {
word_value = word_value + alphabet_value[word[i]-97];
}
return word_value;
}
int main(void) {
int max_size_word = 7;
int size_word, word_value;
bool validity = false;
char word[95];
printf("This program plays the game of scrabble.\n");
for(int i=0; i < size_letter_set; i++) {
letter_set[i] = 0;
}
generate_letter_set(letter_set, size_letter_set, num_letters_input);
while(!validity) {
size_word = read_word(word, max_size_word);
validity = check_word(word, size_word, letter_set, size_letter_set);
if(!validity)
{
printf("The word is not valid. Use your letters: ");
for(int i=0; i < size_letter_set; i++) {
if(letter_set[i])
{
int num = letter_set[i];
while(num--) {
printf("%c ", i+97);
}
}
printf("\n");
}
}
printf("The value of your word is: ");
word_value = compute_word_value(word, size_word);
printf("%d", word_value);
printf("Thank you for playing.");
}
}
}
return 0;
}
It may be somewhat different from what you intend,
I think it will be useful to start with the following modifications.
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <time.h>
#define num_letters_input 7
const int alphabet_count[26] = {8,2,2,4,12,2,3,2,9,1,1,4,2,6,8,2, 1,6,4,6,4,2,2,1,2, 1};
const int alphabet_value[26] = {1,3,3,2, 1,4,2,4,1,8,5,1,3,1,1,3,10,1,1,1,1,4,4,8,4,10};
void generate_letter_set(int letter_set[], int size_letter_set, int num_letters) {
printf("Your letters are: ");
for(int i = 0; i < num_letters; i++){
int random_a = rand() % 26;
int random_b = rand() % alphabet_count[random_a];
letter_set[random_a] = random_b;
}
for(int i = 0; i < size_letter_set; ++i){
if(letter_set[i]){
int num = letter_set[i];
while(num--)
printf("%c ", 'a' + i);
}
}
printf("\n");
}
int read_word(char word[], int max_size_word) {
int size_word = 0;
do {
printf("Enter your word: ");
scanf("%s", word);
size_word = strlen(word);
} while(size_word > max_size_word);
return size_word;
}
bool check_word(char word[], int size_word, int letter_set[], int size_letter_set) {
int count_array[26] = {0};
for(int i = 0; i < size_word; i++) {
count_array[word[i]-'a']++;
}
for(int i=0; i < size_letter_set; i++) {
if(count_array[i] <= letter_set[i])
continue;
else
return false;
}
return true;
}
int compute_word_value(char word[], int size_word) {
int word_value = 0;
for(int i=0; i<size_word; i++) {
word_value += alphabet_value[word[i]-97];
}
return word_value;
}
int main(void){
int letter_set[26] = {0};
int size_letter_set = 26;
int max_size_word = num_letters_input;
int size_word, word_value;
bool validity = false;
char word[96];
srand(time(NULL));
printf("This program plays the game of scrabble.\n");
generate_letter_set(letter_set, size_letter_set, num_letters_input);
while(!validity) {
size_word = read_word(word, max_size_word);
validity = check_word(word, size_word, letter_set, size_letter_set);
if(!validity){
printf("The word is not valid.\nUse your letters: ");
}
}
printf("The value of your word is: ");
word_value = compute_word_value(word, size_word);
printf("%d\n", word_value);
printf("Thank you for playing.\n");
return 0;
}

Array rotation in C

I am trying to rotate an array that looks like this:
a a a a
a b a a
b b b a
a a a a
I am supposed to rotate it 5 times for 90 degrees. It is supposed to be done in C.
I appreciate every help because I am just a beginner and am stuck on this.
Thanks in advance.
#include <stdio.h>
int main()
{
char array_1[4][4] = { {'-','-','-','-'},
{'-','o','-','-'},
{'o','o','o','-'},
{'-','-','-','-'}};
char array_2[4][4] = { {'-','-','-','-'},
{'-','o','o','-'},
{'o','o','-','-'},
{'-','-','-','-'}};
char array_3[4][4] = { {'-','-','-','-'},
{'-','o','-','-'},
{'-','o','-','-'},
{'-','o','o','-'}};
char array_4[4][4] = { {'-','-','o','-'},
{'-','-','o','-'},
{'-','-','o','-'},
{'-','-','o','-'}};
int counter = 0;
int counter_1 = 0;
for(counter = 0; counter < 4; counter++)
{
for(counter_1 = 0; counter_1 < 4; counter_1++)
{
printf("%c ",array_1[counter][counter_1]);
}
printf(" ");
for(counter_1 = 0; counter_1 < 4; counter_1++)
{
printf("%c ",array_2[counter][counter_1]);
}
printf(" ");
for(counter_1 = 0; counter_1 < 4; counter_1++)
{
printf("%c ",array_3[counter][counter_1]);
}
printf(" ");
for(counter_1 = 0; counter_1 < 4; counter_1++)
{
printf("%c ",array_4[counter][counter_1]);
}
printf(" ");
printf("\n");
}
printf("\n");
for(counter= 0; counter < 4; counter++)
{
for(counter_1 = 3; counter_1 >= 0; counter_1--)
{
printf("%c ",array_1[counter_1][counter]);
}
printf(" ");
for(counter_1 = 3; counter_1 >= 0; counter_1--)
{
printf("%c ",array_2[counter_1][counter]);
}
printf(" ");
for(counter_1 = 3; counter_1 >= 0; counter_1--)
{
printf("%c ",array_3[counter_1][counter]);
}
printf(" ");
for(counter_1 = 3; counter_1 >= 0; counter_1--)
{
printf("%c ",array_4[counter_1][counter]);
}
printf(" ");
printf("\n");
}
printf("\n");
like this:
#include <stdio.h>
typedef struct point { int x, y; } Point;
void rotate(int n, char array[n][n]){
//rotate right 90 degrees
if(n == 1) return ;
int times = n / 2;
for(int i = 0; i < times; ++i){
Point base = { i, i };
for(int j = 0; j < n - 1; ++j){
Point transition[4] = { {j, n-1}, {n-1,n-1-j},{n-1-j,0},{0,j} };
char curr = array[base.x][base.y+j];//base + {0,j}
for(int k = 0; k < 4; ++k){
char temp = array[base.x + transition[k].x][base.y + transition[k].y];
array[base.x + transition[k].x][base.y + transition[k].y] = curr;
curr = temp;
}
}
n -= 2;
}
}
void display(int n, char array[n][n]){
for(int i = 0; i < n; ++i){
for(int j = 0; j < n; ++j){
if(j)
putchar(' ');
putchar(array[i][j]);
}
putchar('\n');
}
putchar('\n');
}
int main(void){
//demo
char array4[4][4] = {
{'1','2','3','4'},
{'5','6','7','8'},
{'9','A','B','C'},
{'D','E','F','0'}
};
display(4, array4);
int n = 4;
while(n--){
rotate(4, array4);
display(4, array4);
}
char array5[5][5] = {
{'A','B','C','D','E'},
{'F','G','H','I','J'},
{'K','L','M','N','O'},
{'P','Q','R','S','T'},
{'U','V','W','X','Y'}
};
display(5, array5);
n = 4;
while(n--){
rotate(5, array5);
display(5, array5);
}
}

How can I count the average separately for all rows

It's a basic program, but I need to find out how to calculate the average for each row separately. Should I use more counts or should I use another loop?
int main()
{
int r;
int Count=0;
double sum=0;
double Average=0;
double c,value;
for (r=1; r<11; r++)
{
for(c=1; c<5; c++)
{
value=(rand()%10000)/100.0;
if (value>=67.0)
{
Count++;
printf("%5.2f ",value);
sumTotal=sumRow/sumCol;
sum += value;
}
else
{
printf(" ");
}
}
Average=sum/Count;
if(Average == 0){
printf("| ");
}
else{
printf("| %6.2f ",Average);
}
printf("\n");
}
return 0;
}
make the counters in outer loop
int main()
{
int r;
double c,value;
for (r=1; r<11; r++)
{
int Count=0;
double sum=0;
double Average=0;
for(c=1; c<5; c++)
{
value=(rand()%10000)/100.0;
if (value>=67.0)
{
Count++;
printf("%5.2f ",value);
// sumTotal=sumRow/sumCol;
sum += value;
}
else
{
printf(" ");
}
}
Average=sum/Count;
if(Average == 0){
printf("| ");
}
else{
printf("| %6.2f ",Average);
}
printf("\n");
}
return 0;
}
I commented out broken code.

Function string_to_table is breaking on 3rd if c

I am trying to create program to add two matrixes. After typing input like [12 4] program crashes when function strcat starts.
I have no idea what is wrong. func.h consists of stdio.h, _mingw.h,stdlib.h and string.h
#include"func.h"
void string_to_table(double **matrix, char inpt[])/*problematic function*/
{
printf("convertion start");
int i=strlen(inpt);
printf("%i",i);
int j=1;
int k=0,l=0;
char num[128];
double converted=0;
printf("breakpoint1");
while(j<(i-1))
{
if(inpt[j]==' ')
{
printf("first if");
converted=atof(num);
num[0]='\0';
matrix[k][l]=converted;
++l;
printf("breakpoint2");
}
else if(inpt[j]==';')
{
printf("second if");
converted=atof(num);
num[0]='\0';
matrix[k][l]=converted;
++k;
l=0;
}
else
{
printf("third if");
strcat(num,inpt[j]);/*place when everything crashes*/
}
++j;
}
printf("convert0 end");
}
void add_matrix(double **matrix1, double **matrix2,int i,int j)
{
int k=0;
int l=0;
while(k<i)
{
while(l<j)
{
matrix1[k][l]+=matrix2[k][l];
++l;
}
l=0;
++k;
}
int matrixproccesing(int *i,int *j, char m[])/*sprawdzanie poprawnosci wejscia*/
{
printf("macro start");
int columnnum=0,rownum=0,x=0,piv=0,check=0;
int textsize=strlen(m);
printf("%i",i);
printf("loop start");
printf("%i",textsize);
while(x<(textsize-1))
{
printf("%i",x);
printf("\n");
if(x==0)/*czy poczatek to [*/
{
if(m[x]!='[')
return 0;
}
else if(x==(textsize-2))/*czy koniec to]*/
{
printf("kohec");
if(m[x]==']')
break;
return 0;
}
else if((m[x]>47&&m[x]<58)||(m[x]==' ')||(m[x]=='.')||(m[x]==';')||(m[x]=='-'))/*czy liczba*/
{
if(m[x]==';')/*czy ilosc liczb w rzedzie taka sama*/
{
if(check==0)
{
check=columnnum;
}
else if(check!=columnnum)
{
return 0;
}
printf("colnum");
columnnum=0;
rownum++;
}
else if(m[x]==' ')/*czy nowa liczba/kolumna */
{
columnnum++;
}
}
++x;
}
*i=(check+1);
*j=(columnnum+1);
printf("macro end");
return 1;
}
int is_same_size(int a, int b,int c ,int d)/*test rozmiaru*/
{
if((a==c)&(b==d))
return 1;
return 0;
}
void print_da_matrix(double **matrix, int i, int j)
{
int k=0,l=0;
printf("[ ");
while(k<i)
{
while(l<j)
{
printf("%f",matrix[k][l]);
printf(" ");
}
printf(";");
l=0;
if(k<(i-1))
++k;
}
printf("]");
}
void release_the_memory(double **matrix, int i)
{
int k=0;
while(k<i)
{
free(matrix[k]);
++k;
}
free(matrix);
matrix=NULL;
}
}
int main()
{
int i=0,j=0,m1=0,m2=0,tabcr=0;
char matrix[512];
fgets(&matrix,511,stdin);
double **matrix1;
double **matrix2;
if(!matrixproccesing(&i,&j,matrix))
{
printf("zle wejscie");
return 0;
}
matrix1=(double**)malloc(i*sizeof(double *));
while(tabcr<j)
{
matrix1[tabcr]=(double*)malloc(j*sizeof(double));
++tabcr;
}
string_to_table(matrix1,matrix);
printf("\n");
printf("podaj druga macierz");
fgets(&matrix,511,stdin);
if(!matrixproccesing(&m1,&m2,matrix))
{
printf("zle wejscie");
return 0;
}
tabcr=0;
if(!is_same_size(i,j,m1,m2))
{
printf("matrixes have different size.");
return 0;
}
matrix2=(double**)malloc(i*sizeof(double *));
while(tabcr<j)
{
matrix2[tabcr]=(double*)malloc(j*sizeof(double));
++tabcr;
}
string_to_table(matrix2,matrix);
add_matrix(matrix1,matrix2,i,j);
/* print_da_matrix(matrix1,i,j);
release_the_memory(matrix1,i);
release_the_memory(matrix2,i);*/
return 0;
}

Resources