Błąd w mnożeniu macierzy.

0

Witam. Mam problem z wymnożeniem macierzy [3][3] i macierzy 3-elementowej. Nie wiem w czym tkwi błąd, kompilator nie wyświetla mi liczb mnożenia i wyskakuje błąd.

#include <iostream>
using namespace std;
const int N = 3;
int main( void )
{
int tab[N], wynik[N];
int i,j,a, k;
cout<<"Podaj liczby do tablicy 3-elementowej:\n";
for(i=0;i<N;i++)
{
cout<<"tab["<<i<<"] = ";
cin>>tab[i];
}
for( i = 0 ; i <N ; i++ )
{
cout<<tab[i];
cout<<"\n";
}
cout<<"\nPodaj liczby do macierzy 3x3:\n";
int macierz[N][N];
for(a=0;a<N;a++)
{
for(j=0;j<N;j++)
{
cout<<"tab["<<a<<"]["<<j<<"] = ";
cin>>macierz[a][j];
}
}
for(a=0;a<N;a++)
{
for(j=0;j<N;j++)
{
cout << macierz[a][j];
cout << " ";
}
cout<<endl;
}
for(a=0; a<N; a++)
wynik[a]=0;
for(j=0; j<N; j++)
{
wynik[a] =wynik[a]+ macierz[a][j]* tab[j];
}
for(a=0; a<N; a++)
wynik[a]=0;
for(j=0; j<N; j++)
{
cout<<wynik[a];
cout<<"\n";
}
system("pause");
return 0;
}

0

wiem ze to nie ten temat ale potrzebuje pilnie programiku mam taki
//Kolejka FiFo

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

struct TElem
{
TElem *next;
char label[4];
};

TElem *head = 0;

int Pusta()
{
return head == 0;
}

TElem *last()
{
TElem *e = head;
if( e )
for( ; e->next; e = e->next);
return e;
}

TElem *find(char *s)
{
TElem *e = head;
for( ; e && stricmp(e->label, s) != 0; e = e->next);
return e;
}

int getCount()
{
int n;
TElem *e = head;
for(n = 0; e; e = e->next)
n++;
return n;
}

void list()
{
TElem *e = head;
for(int n = 0 ; e; e = e->next)
printf("%3d %s\n", ++n, e->label);
}

int add()
{
char s[256];
puts("Wpisz identyfikator: ");
gets(s);

if( !s[0] ) 
return 0; 

if( find(s) )  
{
    printf("ten już stoi w kolejce...\n");
    return 0;
}

TElem *e = (TElem*)malloc(sizeof(*e) - sizeof(e->label) + strlen(s)+1);
if( !e ) 
{ 
    puts("Brak pamięci!\n"); return -1; 
}

e->next = 0;
strcpy(e->label, s);

TElem *lst = last();
if( lst ) 
    lst->next = e; 
if( !head ) 
    head = e;  

return 1;
}

int del()
{
if( !head ) return 0;

TElem *e = head;
head = e->next;     

printf("%s - wychodzi\n", e->label);
free(e); 
return 1;

}

void manipuluj()
{
char s[80]; s[0] = '1';
while( s[0] )
{
if( s[0] >= '1' && s[0] <= '3' )
printf("1: Dodaj 2: Usun 3: Lista Enter: Wyjscie\n>");

    gets(s);
    switch( *s )
    {
        case '1': 
             add(); 
             break;
        case '2': 
             del(); 
             break;
        case '3': 
             list(); 
             break;
        case 27 : 
             s[0] = 0; 
             break;
    }
}

}

int main()
{
manipuluj();
return 0;
}

// Co to jest STL?
potrzebuje do niego zliczanie elementów

0

pawelek123: poprawiony kod:

#include <iostream>
#include <conio.h>
using namespace std;
const int N = 3;
int main() 
{
        int  tab[N], wynik[N];
        int i,j,a, k;
        cout<<"Podaj liczby do tablicy 3-elementowej:\n";
        for(i=0;i<N;i++)           
        {
        cout<<"tab["<<i<<"] = ";
        cin>>tab[i];
        }
        for( i = 0 ; i <N ; i++ ) 
        {
        cout<<tab[i];
        cout<<"\n";
        }
        cout<<"\nPodaj liczby do macierzy 3x3:\n";
        int macierz[N][N];
        for(a=0;a<N;a++)           
        {
        for(j=0;j<N;j++)
        {
        cout<<"tab["<<a<<"]["<<j<<"] = ";
        cin>>macierz[a][j];
        }
        }
        for(a=0;a<N;a++)           
        {
        for(j=0;j<N;j++)
        {
        cout << macierz[a][j];
    cout << "      ";
        }
        cout<<endl;
        }
        for(a=0; a<N; a++)
        {wynik[a]=0;
        for(j=0; j<N; j++)
        {
                wynik[a] =wynik[a]+ macierz[a][j]* tab[j];
        }
        }
   cout<<"wynik mnozenia: "<<endl;     
        for(a=0; a<N; a++)
//        wynik[a]=0;
//        for(j=0; j<N; j++)
        { 
                cout<<wynik[a];
                cout<<"\n";
        }
        system("pause");
        return 0;        
        }

 

1 użytkowników online, w tym zalogowanych: 0, gości: 1