# numeros
Write a C Program which reads a number from keyboard and determine how many digits has it
I am trying to teach myself math from scratch with Khan Academy and programming in C, and I have this exercise:
“In this task you will work with the linked list of digits we have created in the lectures up to this point. As you know, a linked list is a chain of objects where each object holds a number and a pointer to the next object of the list. In this task, your program will take as an input from the keyboar a natural number N. Then, it will create a linked list to store the digits of the entered number. Finally, it will traverse the linked list and print the number of digits in the number input at the keyboard.
Example: The user inputs 3462. Then the program creates a linked list, storing digit 2 at the beginning of the list and digit 6 next, followed by 4 and then digit 3 at the tail of the list. When traversing the list the program will print 4, indicating there are 4 digits in the number.”
In my program below, I am able to traverse the list but I cannot seem to figure out the correct syntax for it to continue traversing till the end and ultimately printing the correct number of digits in the number entered using linked list.
I suspect I traverse the list correctly but there might be a mistake in dereferencing the pointers or in looping till the end of the list.
Here is my code:
“`
#include
#include
struct lista
{
int cifra;
struct lista* sledeci;
};
struct lista* novi_element(int cifra)
{
struct lista* novi = (struct lista*)malloc(sizeof(struct lista));
if (novi == NULL)
{
printf(“nema dovoljno memorije”);
exit(EXIT_FAILURE);
}
novi->cifra = cifra;
novi->sledeci = NULL;
return novi;
}
void novi_element_na_kraju(struct lista pocetak, int cifra)
{
struct lista* novi = novi_element(cifra);
if (*pocetak == NULL)
{
*pocetak = novi;
}
else
{
struct lista* trenutni = *pocetak;
while (trenutni->sledeci != NULL)
{
trenutni = trenutni->sledeci;
}
trenutni->sledeci = novi;
}
}
void ispis(struct lista* trenutni_node)
{
while (trenutni_node != NULL)
{
printf(“%d “, trenutni_node->cifra);
trenutni_node = trenutni_node->sledeci;
}
printf(“n”);
}
int broj_cifri(struct lista* trenutna)
{
int brojac = 0;
while (trenutna != NULL)
{
brojac++;
trenutna = trenutna->sledeci;
}
return brojac;
}
int main()
{
struct lista* pocetak = NULL;
int broj;
scanf(“%d”, &broj);
while (broj > 0)
{
novi_element_na_kraju(&pocetak, broj % 10);
broj = broj / 10;
}
ispis(pocetak);
printf(“%dn”, broj_cifri(pocetak));
return 0;
}
“`
Any help would be greatly appreciated. I suspect where I am dereferencing the pointer to continue traversing the list, but I don’t know why it would produce an incorrect output at the end. Here is an example output(wrong):
The user input is 781294 and the program produces output that there is 3 digits in the number. When it clearly should be 6 (781294). Even when putting only one digit as input, the ouput is 0. Despite my efforts I cannot seem to figure out where I am wrong. Can anyone help me with this? Thanks in advance for reading it all and hopefully answering with your insights. Sorry for the long post.
In regards to my code, I have a separate function but I did not post it here because I am not dealing with that right now.
“`
struct suma
{
“`
};
“`
};
“`
Giới thiệu These are my 5 favorite Christmas movies I’ll be watching on Netflix, Prime Video, Max and more
: These are my 5 favorite Christmas movies I’ll be watching on Netflix, Prime Video, Max and more
Hãy viết lại bài viết dài kèm hashtag về việc đánh giá sản phẩm và mua ngay tại Queen Mobile bằng tiếng VIệt: These are my 5 favorite Christmas movies I’ll be watching on Netflix, Prime Video, Max and more
Mua ngay sản phẩm tại Việt Nam:
QUEEN MOBILE chuyên cung cấp điện thoại Iphone, máy tính bảng Ipad, đồng hồ Smartwatch và các phụ kiện APPLE và các giải pháp điện tử và nhà thông minh. Queen Mobile rất hân hạnh được phục vụ quý khách….
_____________________________________________________
Mua #Điện_thoại #iphone #ipad #macbook #samsung #xiaomi #poco #oppo #snapdragon giá tốt, hãy ghé [𝑸𝑼𝑬𝑬𝑵 𝑴𝑶𝑩𝑰𝑳𝑬]
✿ 149 Hòa Bình, phường Hiệp Tân, quận Tân Phú, TP HCM
✿ 402B, Hai Bà Trưng, P Tân Định, Q 1, HCM
✿ 287 đường 3/2 P 10, Q 10, HCM
Hotline (miễn phí) 19003190
Thu cũ đổi mới
Rẻ hơn hoàn tiền
Góp 0%
Thời gian làm việc: 9h – 21h.
KẾT LUẬN
Hãy viết đoạn tóm tắt về nội dung bằng tiếng việt kích thích người mua: These are my 5 favorite Christmas movies I’ll be watching on Netflix, Prime Video, Max and more
Like a lot of you out there, one of the enduring Yuletide traditions in my household is snuggling up with loved ones by the fire and revisiting some of our favorite Christmas movies.
Granted, the criteria for what makes a Christmas movie is a source of frequent debate around this time of year (looking at you, Die Hard fans). And with a new slate of Christmas movies rolling out every year to bring cheer (and revenue) to all, it can be difficult to sort out which ones are actually worth your time.
Max, Netflix, Prime Video and others. So no matter which of the best streaming services you subscribe to, you have some pretty good options of what to watch to get your holiday movie fix.
So once you’re done opening presents this Christmas, break out your slippers, pour some hot chocolate, and get cozy on the couch — it’s Christmas movie season.
Violent Night (Prime Video)
This is one Christmas movie I did not expect to like as much as I did. While its campy “What if John Wick, but with Santa?” premise isn’t everyone’s idea of holiday cheer, Violent Night is an entertaining and gory romp that never takes itself too seriously. It’s the perfect palette cleanser for this time of year.
Stranger Things’ David Harbour feels made for the role of a washed-up ol’ Kris Kringle with a bloody past. Centuries of delivering presents to snot-nosed kids and dealing with a world that increasingly doesn’t believe he exists have turned him into a bit of a Scrooge. But he’s forced to sober up and get his head in the game when he gets caught up in a home invasion on Christmas Eve.
A troupe of mercenaries led by John Leguizamo bust in to steal a rich family’s fortune, but get more than they bargained for when a hammer-wielding Santa starts hacking and slashing through their ranks, using the Christmas magic you’ll remember from storybooks to some truly gruesome ends. (I, for one, will never look at chimneys the same way again).
Watch it now on
Klaus (Netflix)
The first animated film from Netflix to be nominated for an Academy Award, Klaus is a refreshingly original take on the whole Santa Claus origin story. Both critics and viewers alike have sung its praises, calling it an instant classic for its heartfelt storytelling and inventive spin on well-trodden ground.
The reluctant postman at the center of it all, Jesper Johansen (Jason Schwartzman), gives me big Kuzco from The Emperor’s New Groove vibes. The spoiled son of the Royal Postmaster General, he’s kicked out to the remote, icy town of Smeerensburg with an ultimatum: deliver 6,000 letters before the end of the year or say goodbye to coasting off the family’s fortune.
But Smeerensburg is home to two feuding families who would rather trade blows than letters. With the odds stacked against him, Jesper finds an unlikely ally in the mysterious Klaus (voiced by J.K. Simmons in another A+ casting choice), a reclusive woodsman who lives alone in a house filled with handmade toys. Together, the two bring joy and a sense of community to the bitterly divided town, finding the true spirit of Christmas along the way.
Watch it now on
Krampus (Peacock)
Santa isn’t the only festive figure keeping tabs on who’s been naughty or nice. There’s also Krampus — a demonic, horned beast from European folklore said to punish non-believers and misbehaving children alike.
Unfortunately for the dysfunctional family at the center of this holiday tale, Krampus is set to pay them a visit they won’t soon forget. As if a major family feud, a raging blizzard outside, and a resulting power outage weren’t enough to ruin Christmas Eve, the family finds themselves being picked off one by one by a monster unlike anything they’ve ever seen. And it’s hungry for more than just milk and cookies.
With a brilliant cast that includes Toni Collette, Adam Scott and David Koechner, this black comedy-tinged monster slasher flick is a delightfully devilish holiday treat for horror fans.
Watch it now on
A Christmas Story (Max)
I’m a fan of more unconventional Christmas movies, in case that wasn’t already clear, but there are a few classics on my rolodex of holiday go-tos. I mean, is it even really Christmas if you don’t watch A Christmas Story?
This holiday staple is iconic, with Peter Billingsley as Ralphie Parker, Melinda Dillon as his father, Darren McGavin as his father, and Ian Petrella as his little brother Randy. Although it’s set in the 1940s, A Christmas Story’s timeless message resonates among audiences of every age.
A precocious young Ralphie wants one thing and one thing only for Christmas: a Red Ryder Range 200 Shot BB gun. He tells Santa, his parents, his teacher, and just about anyone else who would listen. Along the way, he gets up to wintry hi-jinks, faces off with schoolyard bullies, and gets up to all the kinds of ill-thought-out exploits kids do. Meanwhile, the family’s annual Christmas festivities keep ending in disaster, but they pull through to find the silver lining and celebrate what really matters.
Watch it now on
It’s A Wonderful Life (Prime Video)
Another movie that’s practically mandatory viewing around this time of year is It’s A Wonderful Life. Frank Capra’s enduring classic film tells the story of George Bailey (James Stewart), a businessman with wanderlust in his eye and a generous heart who nonetheless encounters a crisis on Christmas Eve.
When a series of unfortunate events ends in George losing a serious chunk of change and facing arrest, he begins to spiral. He believes he’s a failure, worth more dead than alive, and contemplates suicide.
That’s when Henry Traver’s Clarence, a guardian angel looking to earn his wings, shows up to take George down memory lane and see what the world would look like if he never existed. This movie has all the makings of a Christmas classic — the perfect blend of magic, courage, and heartwarming messages of gratitude and self-sacrifice that remain as poignant as ever. Just be warned: You’ll want to watch this one with a tissue box.
Watch it now on
More from Tom’s Guide
Xem chi tiết và đăng kýXem chi tiết và đăng ký
Khám phá thêm từ Phụ Kiện Đỉnh
Đăng ký để nhận các bài đăng mới nhất được gửi đến email của bạn.