n সংখ্যক নোড দেওয়া থাকলে, লিংকড লিস্টের বিকল্প নোডগুলোর গুণফল প্রিন্ট করতে হবে। প্রোগ্রামটি নোডগুলোর লোকেশন বদলে না, শুধু বিকল্প নোডগুলোর গুণফল প্রিন্ট করবে।
উদাহরণ
Input: 10 20 30 40 50 60 Output: 15000
উপরের উদাহরণে, প্রথম নোড ১০ থেকে বিকল্প নোডগুলো হলো ১০, ৩০, ৫০ এবং তাদের গুণফল ১০×৩০×৫০ = ১৫০০০।

উপরের ডায়াগ্রামে নীল রঙের নোডগুলো বিকল্প নোড (প্রথম নোড থেকে শুরু করলে) এবং লাল রঙের নোডগুলো বিবেচ্য নয়।
অ্যালগরিদম
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 alternate nodes product
void alternate() {
int product;
temp = head;
product = head->data;
while (temp->next != NULL && temp != NULL && temp->next->next != NULL) {
temp = temp->next->next;
product = product * (temp->data);
}
Print product
}
Step 5: In main()
Create nodes, insert values, display list, call alternate()
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;
if (head == NULL) {
head = newnode;
head->next = NULL;
} else {
temp = head;
while (temp->next != NULL) {
temp = temp->next;
}
newnode->next = NULL;
temp->next = newnode;
}
}
// 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 alternate elements
void alternate() {
int product;
temp = head;
product = head->data;
while (temp->next != NULL && temp != NULL && temp->next->next != NULL) {
temp = temp->next->next;
product = product * (temp->data);
}
printf("\nproduct of alternate nodes is: %d", product);
}
int main() {
struct node* head = NULL;
insert(10);
insert(20);
insert(30);
insert(40);
insert(50);
insert(60);
printf("linked list is: ");
display();
alternate();
return 0;
}
আউটপুট
linked list is: 10 20 30 40 50 60 product of alternate nodes is: 15000