C# programiranje-Ciklusi(for,While)-2 primera primene naredbi for i while
Programiraj sa Flinom
0:00 / 0:00
C# programiranje-Ciklusi(for,While)-2 primera primene naredbi for i while
115 просмотров · 1 год назад
Programiraj sa Flinom
2,07 тыс. подписчиков
115 просмотров · 1 год назад
Programiranje u C# - Tutorijal
U ovom videu ćemo pokazati kako se mogu koristiti petlje for i while u C++ za rešavanje dva zadatka koji se tiču rada sa ciframa broja.
Zadatak 1: Brojanje učestalosti svake cifre u broju
Prvi zadatak je da za dati prirodni broj n ispišemo koliko puta se svaka cifra pojavljuje u tom broju. Ovaj zadatak rešavamo bez korišćenja nizova, koristeći samo petlju za prolazak kroz cifre broja.
Rešenje: Koristićemo while petlju koja će prolaziti kroz cifre broja n tako što ćemo broj deliti sa 10 dok ne dođemo do nule. Svaku cifru ćemo proveriti i brojaćemo koliko puta se svaka cifra pojavljuje.
Zadatak 2: Provera da li su sve cifre u broju iste
Drugi zadatak zahteva proveru da li su sve cifre unetog broja iste. Na primer, za broj 111 treba ispisati "Sve cifre su iste", a za broj 123 treba ispisati "Cifre nisu iste".
Rešenje: Koristićemo for petlju koja će prolaziti kroz sve cifre broja. Ako u bilo kom trenutku naiđemo na cifru koja se razlikuje od prve, odmah ćemo ispisati "Cifre nisu iste". Ako se sve cifre poklapaju, ispisujemo "Sve cifre su iste".
Cilj videa: Cilj ovog videa je da vas nauči kako efikasno koristiti petlje u C++ za rešavanje problema koji se odnose na cifre broja, uz objašnjenje osnovnih principa rada sa brojevima i petljama.
Dat je prirodan broj n. Ispisati koliko se puta pojavljuje svaka cifra u broju n. (ne koristiti nizove)
Napiši program koji proverava da li su sve cifre unetog broja iste (npr. za broj 111 ispisuje "Sve cifre su iste", za broj 123 ispisuje "Cifre nisu iste").
Rešeni zadaci u programskom jeziku C#
Koliko se puta pojavljuje svaka cifra u broju n (bez nizova, bez funkcija) koristeći samo 4 promenljive u programu
In this video, we'll show you how to use for and while loops in C++ to solve two tasks that involve working with the digits of a number.
Task 1: Counting the frequency of each digit in a number
The first task is to print for a given natural number n how many times each digit appears in that number. We solve this problem without using strings, using only a loop to pass through the digits of the number.
Solution: We will use a while loop that will loop through the digits of n by dividing the number by 10 until we reach zero. We will check each digit and count how many times each digit appears.
Task 2: Check if all the digits in the number are the same
The second task requires checking whether all the digits of the entered number are the same. For example, for the number 111 you should write "All digits are the same", and for the number 123 you should write "The digits are not the same".
Solution: We will use a for loop that will go through all the digits of the number. If at any time we come across a digit that is different from the first one, we will immediately print "The digits are not the same". If all digits match, we print "All digits are the same".
Video Objective: The objective of this video is to teach you how to effectively use loops in C++ to solve problems involving the digits of a number, while explaining the basic principles of working with numbers and loops.
A natural number n is given. Print the number of times each digit appears in the number n. (don't use strings)
Write a program that checks whether all the digits of the entered number are the same (eg for the number 111 it prints "All the digits are the same", for the number 123 it prints "The digits are not the same").
Solved tasks in the programming language C#
How many times each digit appears in the number n (no strings, no functions) using only 4 variables in the program
C# programming tutorial
Loops-Introduction (while)
Konzolne aplikacije - Console applications