#include <stdio.h>
#include <stdlib.h>
#include <string.h>
struct node
{
int data;
struct node *next;
};
void display(struct node *r)
{
printf("elements of list are : ");
while (r)
{
printf("%d ---> ", r->data);
r = r->next;
}
printf("NULL\n");
}
int init_count(struct node *r)
{
int count = 0;
while (r)
{
r = r->next;
count++;
}
return count;
}
int tmul(struct node *r)
{
int i = 1;
while (r)
{
i = r->data * i;
r = r->next;
}
return i;
}
struct node *create(struct node *head)
{
struct node *t, *p;
int n;
if (head == NULL)
{
t = (struct node *)malloc(sizeof(struct node));
printf("enter the node: \n");
scanf("%d", &t->data);
t->next = NULL;
head = t;
}
if (head != NULL)
{
do
{
t = (struct node *)malloc(sizeof(struct node));
printf("enter the node: \n");
scanf("%d", &t->data);
t->next = NULL;
p = head;
while (p->next != NULL)
{
p = p->next;
}
p->next = t;
printf("do you want to add more node press 1 for yes, 0 for no. ");
scanf("%d", &n);
} while (n);
}
return head;
}
struct node *replaceprod(struct node *head)
{
int mul = tmul(head);
struct node *t = head;
while (t)
{
t->data = mul / t->data;
t = t->next;
}
return head;
}
int main()
{
struct node *head = NULL;
head = create(head);
display(head);
head = replaceprod(head);
display(head);
return 0;
}