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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:53:34+00:00 2026-05-22T01:53:34+00:00

So I got this task to make a program which will allow the user

  • 0

So I got this task to make a program which will allow the user to enter a number of integer elements in a double-linked list and I have to delete the ones which can be divided (remainder 0) with the sum of their digits.

#include <stdio.h>
#include <stdlib.h>
#define NEW(t) (t*)malloc(sizeof(t))

typedef int info_t;

typedef struct element {
  info_t info;
  struct element *next;
  struct element *prev;
} node;

typedef node* nodep;
void insert(nodep l, info_t x) {
  nodep t = NEW(node);
  t->info=x;
  t->next=l->next;
  l->next=t;
  t->prev=l;
}
void printList(nodep l) {
  nodep t=l->next;
  while(t!=l)
  {
      printf("->%d", t->info);
      t=t->next;
  }
  printf("\n");
}
void deletedividable(nodep l) {
  nodep t=l->next;
  nodep temp;
  while(t->next!=l)
  {
      int temporary=t->info;
      int sum=0;
      while(temporary>0)
      {
          sum+=(temporary%10);
          temporary/=10;
      }
      if(!(t->info%sum))
      {
          temp=t->next;
          t->next->prev=t->prev;
          t->prev->next=t->next;
          free(t);
          t=temp;
      }
      else
        t=t->next;
   }
}

int main() {
  // declaring a leader node
  nodep list = NEW(node);
  list->next = list;
  list->prev = list;

  printf("Enter elements:\n ");
  int a;
  //if the input isn't a number the loop will exit
  while(scanf("%d", &a)) {
    //elements input function call
    insert(list, a);
  }
  // print list function call
  printList(list);
  // delete elements which are dividable with the sum of their digits

  deletedividable(list);

  printList(list);

  return 0;
}

The problem is, after the deletedividable(list); function call, nothing is printed when the second printlist is called and I can’t seem to locate the problem, some of the pointers must be getting screwed up, but I’m not sure which ones.
Any help would be much appreciated.

  • 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-22T01:53:35+00:00Added an answer on May 22, 2026 at 1:53 am

    Seems an error exists in your insert() function. A hint: insertion into a circular double-linked list should set or change 4 pointers; you only set 3.

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

Sidebar

Related Questions

I've got the task of making a car rental program, which uses linked lists
I got this síngleton cache object and it exposes an IEnumerable property which just
Still working my way through this program. Next task on my to-do list is
I have just got a task in a new project which is implemented using
I got this ANT task: <javac verbose=on srcdir=${src.dir} destdir=${build.dir}/${context.path}/classes debug=${compile.debug} debuglevel=${javac.debuglevel} optimize=${compile.optimize} deprecation=${javac.deprecation} failonerror=true>
I got a tableview with guests(VM's) which i can turn on/off/reboot, this works perfectly
iv'e got an asp button which performs another task besides postback i have done
I got this error today when trying to open a Visual Studio 2008 project
I got this output when running sudo cpan Scalar::Util::Numeric jmm@freekbox:~/bfwsandbox/sa/angel/astroportal/dtu8e/resources$ sudo cpan Scalar::Util::Numeric [sudo]
I got this flash application where you can click a link while watching a

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.