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

The Archive Base Latest Questions

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

I wrote a program to generate monomials and polynomial and print monomials and polynomial.

  • 0

I wrote a program to generate monomials and polynomial and print monomials and polynomial. The data are input from keyboard. For example, first input the number of groups of data 3, then input the data: 1,3,2,4,3,6,3,4,2 (each group has 3 elements). I need output monomial Y^{1}{2,3}Y^{4}{3,6}Y^{3}_{4,2}. My program can work. But the output is not correct. I think the problem of the program is in the following part. I think the scanf is not good in the following. Are there other better input method to fix this problem? The whole program is in http://hi.baidu.com/lijr03/blog/item/51e17b0c63614bc863d98629.html

monomial create_monomial(int number) /* create a monomial */
{

   monomial m,s;
   monomial p;
   int i;


   printf("Please input the parameters (for example,  2, 2, 3 denotes the monomial P^{2}_{2,3}). The first subscripts i's of P's should be in increase order.");
   m=(monomial)malloc(sizeof(monomial_node));
   m->head=m->tail=(monomial)malloc(sizeof(monomial_node));

   if(m->head==NULL)
   {
     return NULL;
   }

   m->head->next=m->tail;

   m->tail->next=NULL;

   p=(monomial)malloc(sizeof(monomial_node));

   m->head->next=p;

   p->next=m->tail;   

   scanf("%d", &((p->y).l)); 
   scanf("%d", &((p->y).i));
   scanf("%d", &((p->y).k));

  if(number > 1)
  {
   for(i=0;i<number-1;i++)

   {

    s=(monomial)malloc(sizeof(monomial_node));

    scanf("%d", &((s->y).l)); 
    scanf("%d", &((s->y).i));
    scanf("%d", &((s->y).k));

    s->next=p->next;     /* insert the node a */

    p->next=s;

    free(s);            

   }
  }
   return m;
}
  • 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-23T09:58:14+00:00Added an answer on May 23, 2026 at 9:58 am

    The free(s) means that you are destroying the monomial that you’ve just created. The pointer that you create above it (from p) means that you’ll be pointing to a potentially invalid bit of memory when you process m.

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

Sidebar

Related Questions

I wrote a program using AutoIT to fetch information from a number of websites
I wrote a program which includes writing and reading from database. When I run
i was told to write program which generate unique 5 digit number ( for
i have application with client-server architecture. client (C program): generate various DER encoded data
How do you generate random numbers effectively? Every time a random number program boots
I wrote a program to generate large .SQL files for quickly populating very large
So far i wrote a code to download a file from ftp server then
I'm trying to write a program in Java that uses osql to generate a
I wrote a program in C with Ubuntu Linux and now I need to
I wrote a program out, which was all in one file, and the methods

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.