Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- char* umnoz(char* el1, char* el2){
- int length = strlen(el1);
- char *res = (char*) calloc(30, sizeof (char));
- for (int i = 0; i < length; ++i) {
- if(el1[i] == el2[i]){
- res[i] = el1[i];
- } else if(el1[i] != el2[i] && el1[i] != 'x' && el2[i] != 'x'){
- res[i] = 'y';
- } else if(el1[i] != el2[i] && (el1[i] == 'x' || el2[i] != 'x')){
- res[i] = el2[i];
- } else if(el1[i] != el2[i] && (el1[i] != 'x' || el2[i] == 'x')){
- res[i] = el1[i];
- }
- }
- return res;
- }
- int main() {
- int amount;
- printf("enter amount of elements\n");
- scanf("%d", &amount);
- char* elements[amount];
- char* table[amount][amount];
- for (int i = 0; i < amount; ++i) {
- elements[i] = (char*) calloc(50, sizeof (char));
- }
- getchar();
- for (int i = 0; i < amount; ++i) {
- printf("enter element #%d\n", i + 1);
- fflush(stdin);
- gets(elements[i]);
- }
- for (int i = 0; i < amount; ++i) {
- for (int j = 0; j < amount; ++j) {
- table[i][j] = (char*) calloc(50, sizeof (char));
- }
- }
- for (int i = 0; i < amount; ++i) {
- for (int j = 0; j < amount; ++j) {
- table[i][j] = umnoz(elements[i], elements[j]);
- }
- }
- for (int i = 0; i < amount; ++i) {
- for (int j = i; j < amount; ++j) {
- table[i][j] = "-----";
- }
- }
- for (int i = 0; i < amount; ++i) {
- printf("%s:\t", elements[i]);
- for (int j = 0; j < amount; ++j) {
- printf("%s\t", table[i][j]);
- }
- printf("\n-----------------------------------------\n");
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment