# Find Length of a Linked List (Iterative)

1,443.8K Views

Write a C function to count number of nodes in a given singly linked list.

For example, the function should return 6 for linked list 1->3->1->4->2->1.

SherlockHolmes Expert Asked on 4th August 2015 in

ITERATIVE SOLUTION-

``` /*
* File:   main.cpp
* Author: akash
*
* Created on 12 August, 2015, 4:57 PM
*/
#include <stdio.h>
#include <stdlib.h>
struct node
{
int data;
struct node* next;
};
{
struct node* add_node = (struct node*) malloc(sizeof(struct node));
}
return 0;
// count is 1 + count of remaining list
}
int main(){
return 0;
}
```

SherlockHolmes Expert Answered on 13th August 2015.

• ## More puzzles to try-

• ### Find the initial amount

One day when I was walking on the road in New Delhi, a group of boys approached me for donation ...Read More »
• ### In which year was the grandfather born?

Recently, somebody told: “My grandfather was born on the first sunday of the year. His seventh birthday was also on ...Read More »
• ### You can’t find out!!!

Fariha, Ononno, Richie each got a prime. Suppose the numbers are A,B,C. They permute the numbers in the following possible ...Read More »
• ### 10% brain riddle

What do you try to solve. A answer you need to think. To think about with your brain. The brain ...Read More »
• ### Police and Jail

A man is found unconscious in front of a store at two in the morning. His head is bleeding and ...Read More »
• ### Live in closed room

He has a little house in which he live all alone. It has no doors or windows, and if he ...Read More »
• ### How could i measure 45 minutes ?

I have two rectangular wires. Both of them have property that when i light the fire from one end , ...Read More »
• ### Who am I?

I am a 8 letter word Many wasted time in hunting me, rather I’m in the form of hardwork. 5,6,7,8 ...Read More »
• ### Countries without Alpha

Can you name some countries which do not have the alphabet \’A\’ in them?Read More »
• ### A Man with Medical Condition and 2 Pills

A man has a medical condition that requires him to take two kinds of pills, call them A and B. ...Read More »
• ### THE DISHONEST MERCHANT

An unscrupulous trader decided to make some extra profit on Coffee. He bought one type of coffee powder at Rs. ...Read More »
• ### In the Rain but hair didn’t wet puzzle

Jim and his mum and dad went out in the rain on their holiday but only two of them got ...Read More »
• ### Measuring 45 mts

You have two identical length wires which take an hour to burn. But, they do not burn at the same ...Read More »

Imagine that a farmer has a sack containing 100 lbs of potatoes. The potatoes, he discovers, are comprised of 99% ...Read More »

• ### Dance in the Concert

In a concert, Christina is performing a dance show with her group. At 11:00, she and her crew were dancing ...Read More »
• ### Always like you

He moves like you in every way. Look at him he wants to play. Be tricky, but the result is ...Read More »
• ### Unique Dating Puzzle

Katrina wants to go on a date and prefers her date to be tall, dark and handsome. Of the preferred ...Read More »
• ### Eating Chocolate Together

John can eat 27 chocolates in an hour, Jacob can eat 2 chocolates in 10 minutes, and Jolly can eat ...Read More »
• ### Cutting cheese

You’re given a 3x3x3 cube of cheese and a knife.  How many straight cuts with the knife do you need ...Read More »