Answer to Question #220964 in C for Flux

Question #220964
A man goes for shopping to buy vegetables. He picks up the basket and goes to the shelf of vegetables. The tray can hold up to 10kg only. So he carefully picks up the vegetables needed for one week and fills his basket. When he reaches the end of shelf, he finds he had filled only 8.5 kg. So he decides to refill with some more vegetables for his need. Write a C program to implement the refilling process using linked list.
1
Expert's answer
2021-07-28T02:59:22-0400
#include <stdio.h>
#include <stdlib.h>
struct Node {
  int item;
  struct Node *next;
};
struct Node *node = NULL;
void insert_at_begin(int);
int count = 0;
int main(){
      int i, data;
    printf("Insert the element that is remaining to make it 10kg.\n");
    printf("Enter value of element\n");
      scanf("%d", &data);
      if(data<1.5){
          insert_at_begin(data);
        printf("Inserted successfully.\n");
      }
      else{
           printf("Item must be less than or equal to 1.5.\n");
         main();
      }
      
    
}
void insert_at_begin(int x) {
  struct Node *t;
  t = (struct Node*)malloc(sizeof(struct Node));
  t->item= x;
  count++;
  if (node == NULL) {
    node = t;
    node->next = NULL;
    return;
  }
  t->next = node;
  node = t;
}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS