n সংখ্যক নোড দেওয়া থাকলে, সিঙ্গলি লিংকড লিস্টের সব নোডের গুণফল প্রিন্ট করতে হবে। প্রোগ্রামটি প্রথম নোড থেকে NULL না পাওয়া পর্যন্ত সব নোড ট্রাভার্স করবে।
উদাহরণ
Input: 1 2 3 4 5 Output: 120
উপরের উদাহরণে, প্রথম নোড থেকে সব নোড ট্রাভার্স করা হয়েছে: 1, 2, 3, 4, 5, 6 এবং তাদের গুণফল ১×২×৩×৪×৫×৬ = ৭২০।

অ্যালগরিদম
Start
Step 1: Create structure of a node with temp, next, head pointers
Step 2: Declare function to insert a node in list
Step 3: Declare function to display list
Step 4: Declare function to find product of nodes
void product_nodes() {
int product = 1;
temp = head;
while (temp != NULL) {
product = product * (temp->data);
temp = temp->next;
}
Print product
}
Step 5: In main()
Create nodes, insert values, display list, call product_nodes()
Stop
সি প্রোগ্রাম
#include <stdio.h>
#include <stdlib.h>
// Structure of a node
struct node {
int data;
struct node *next;
} *head, *temp;
// Function for inserting nodes into a list
void insert(int val) {
struct node* newnode = (struct node*)malloc(sizeof(struct node));
newnode->data = val;
newnode->next = NULL;
if (head == NULL) {
head = newnode;
temp = head;
} else {
temp->next = newnode;
temp = temp->next;
}
}
// Function for displaying a list
void display() {
if (head == NULL)
printf("no node ");
else {
temp = head;
while (temp != NULL) {
printf("%d ", temp->data);
temp = temp->next;
}
}
}
// Function for finding product
void product_nodes() {
int product = 1;
temp = head;
while (temp != NULL) {
product = product * (temp->data);
temp = temp->next;
}
printf("\nproduct of nodes is: %d", product);
}
int main() {
struct node* head = NULL;
insert(1);
insert(2);
insert(3);
insert(4);
insert(5);
insert(6);
printf("linked list is: ");
display();
product_nodes();
return 0;
}
আউটপুট
linked list is: 1 2 3 4 5 6 product of nodes is: 720