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 9304983
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T23:49:46+00:00 2026-06-18T23:49:46+00:00

I have some piece of code in C: #include <stdio.h> #include <stdlib.h> int multiply(int);

  • 0

I have some piece of code in C:

#include <stdio.h>
#include <stdlib.h>

int multiply(int);

int main() {
    FILE *fp;
    int i, j, n, m,
        matrix[99][99],
        sum = 0,
        columnSums[99] = {0};

    fp = fopen("data.txt", "r");
    if(fp != NULL) {
        fscanf(fp, "%d", &n);
        fscanf(fp, "%d", &m);

        for(i = 0; i < n; i++) {
            for(j = 0; j < m; j++) {
                fscanf(fp, "%d", &matrix[i][j]);
            }
        }

        for(i = 0; i < m; i++) {
            for(j = 0; j < n; j++) {
                sum += multiply(matrix[j][i]);
            }
            columnSums[i] = sum;
            sum = 0;
        }
    } else {
        puts("Cannot read the file!");
    }
    puts("");
    system("pause");
    return 0;
}

int multiply(int thisNum) {
    return thisNum * thisNum *thisNum;
}

My tasks wants me to read multidimensional array from a text file, and then sort each column by the addition of each column member multiplied by itself three times.
Wasn’t so hard to read an array and find each columns addition and store it into other array that stores the addition of each column (hoped that would help), but I’m stuck with sorting it out. Any tips, please? 🙂

  • 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-06-18T23:49:48+00:00Added an answer on June 18, 2026 at 11:49 pm

    You can use qsort(). Don’t forget to include stdlib.h

    #define ARR_SIZE(a) (sizeof(a) / sizeof(*(a)))
    
    int comp(const void* a, const void* b)
    {
        return *(const int*)a - *(const int*)b;
    }
    
    ...
    
    for (i = 0; i < ARR_SIZE(matrix); i++)
    {
        qsort(matrix[i], ARR_SIZE(matrix[i]), sizeof matrix[i][0], comp);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this piece of code #include <stdio.h> #include <stdlib.h> #include <stdint.h> #include <string.h>
I wrote this piece of code #include <stdio.h> /* Input/Output */ #include <stdlib.h> /*
I have a Login.aspx page, and I wanna incude some piece of code in
If have a piece of code that gets some data from a sql database
I have the following piece of code that takes in some words, stores them
I have got a piece of code, that should countdown some number (in this
I am reading some book and I have encountered a piece of code that
I have some piece of code that behaves differently under Mac OSX and Linux
I have stumbled upon a piece of code that generates some interesting results while
I have a piece of code written in C where some pointer arithmetic is

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.