Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7645467
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T09:56:58+00:00 2026-05-31T09:56:58+00:00

i am trying to multiply a[2][3] with b[3][4] and put the answer in c[2][4].

  • 0

i am trying to multiply a[2][3] with b[3][4] and put the answer in c[2][4].
I have to use fork() and make 2 processes, each child for c[0][j] and c[1][j], parent will wait.
So each child process will calculate a row for c. This is my code :

//multiply a[2][3] * b[3][4] = c[2][4]
//with fork
//each child completes one c[2][4]'s row
#include<stdio.h>
#include<stdlib.h>

main()
{
  int a[2][3]={1,2,3, 
           4,5,6};
  int b[3][4]={1,2,3,4,
           5,6,7,8,
           9,10,11,12};
  int c[2][4];
      int i,j;
  int m;    //for the calculation
  int n;    //common 3
  int pid;  //fork

  for(i=0;i<2;i++)
  {
    pid=fork();
    if(pid==-1)
    {
      printf("Can't fork\n");
    }
    if(pid==0)//child
    {
      for(j=0;j<4;j++)
      {
    for(n=0;n<3;n++)
    {
      m=m+a[i][n]*b[n][j];
    }
    c[i][j]=m;
    m=0;
      }
      exit(EXIT_SUCCESS);
    }
    if(pid>0)//parent
    {
      wait(0);
    }
  }
  printf("C:\n");
  for(i=0;i<2;i++)
  {
    for(j=0;j<4;j++)
    {
      printf("%d\t",c[i][j]);
    }
    printf("\n");
  }        
}

I have no errors at compiling, but i get wrong numbers…awkward big numbers …
Any ideas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T09:56:59+00:00Added an answer on May 31, 2026 at 9:56 am

    Q: I have no errors at compiling, but i get wrong numbers…awkward
    big numbers … Any ideas?

    A: Yes – the moment you fork, you have two different processes with two completely independent address spaces 🙂

    One good solution is to use threads instead of fork():

    https://computing.llnl.gov/tutorials/pthreads/

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to multiply a double value by -1 to get the negative
I'm trying to use multiple attributes in my custom tag, e.g.: <mytaglib:mytag firstname=Thadeus lastname=Jones
I am trying to merge multiple excel files using DataTable.Merge() option For Each fileName
Here is an example xpage: I am trying to put multiple date pickers on
What I'm trying to do is have a clock widget of different sizes (i.e.
I'm trying to make the code below reusable. I need multiple toggle buttons in
I have been searching for the answer and have not been able to find
I have code like the following, class _Process(multiprocessing.Process): STOP = multiprocessing.Manager().Event() def __init__(self, queue,
I am trying to get a magento installation to run multiple websites I have
Background: I am trying to create a really simple iPhone app that will allow

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.