<< Chapter < Page Chapter >> Page >
Се прикажуваат повеќе задачи за чија програмска реализација се користат структури за повторување-циклуси.

Пример 1.

Да се состави програма која ќе ги испечати првите 10 природни броја.

Програма:

#include<stdio.h>main() {int i=1; while (i<= 10) {printf ("i e %i\n", i); i++} }

Пример 2.

Да се испечатат сите едноцифрени парни броеви.

Програма:

#include<stdio.h>main() {int i=1;while (i<= 10) {if (i%2==0) printf ("i e %i\n", i); i++} }

Пример 3.

Да се состави програма која ќе ја пресмета средната вредност на пет броеви кои се внесуваат преку тастатура.

Програма:

#include<stdio.h>int main() {int n = 1; int broj, suma= 0;while( n<= 5 ) {printf( "Vnesi broj: "); scanf("%d",&broj); suma+= broj;n++; }printf("\nSredna vrednost na vnesenite broevi " “e %f\n", (float)suma/(n-1));return(0); }

Пример 4.

Да се испечатат сите броеви деливи со 3 и помали од 1000. Да се преброи колку такви броеви има:

Програма:

#include<stdio.h>int main() {int n = 1; int vkupno = 0;while( n<= 1000 ) {if (n%3==0) {printf(“%d\n”,n); vkupno++;} }printf(“Vlupno takvi broevi ima %d\n”,vkupno); return(0);}

Пример 5.

Да се напише програма за пресметување на y = x n за даден природен број n и релаен број x.

Програма:

#include<stdio.h>int main() {int brojac, n; float x, y;printf(“vnesi vrednost za osnovata: “);scanf(“%f”,&x); printf(“vnesi vrednost za eksponentot: “);scanf(“%d”,&n); y = x;brojac = 1; while (brojac<n) {y *= x; brojac++;} printf(“%f^%d = %f\n”, x, n, y);return 0; }

Пример 6.

Да се напише програма која од n броеви (внесени од тастатура) ќе го определи бројот на броеви што се деливи со 3, како и бројот на броеви за кои при делењето со 3 имаат остаток 1, односно 2.

Програма:

#include<stdio.h>int main() {int n, i, broj, del, os1, os2; del = os1 = os2 = 0;printf(“Kolku broevi treba da se proveruvaat za delivost so 3?\n”); scanf(“%d”,&n); i = 1;do {printf(“Vnesete broj za proverka: “); scanf(“%d”,&broj); if ( broj % 3 == 0) del++;else if ( broj % 3 == 1) os1++; else os2++;i++; }while (i<= n); printf(“%d broevi se delivi so 3.\n“, del);printf(“%d broevi imaat ostatok 1, pri delenje so 3.\n“, os1); printf(“%d broevi imaat ostatok 2, pri delenje so 3.\n“, os2);return 0; }

Пример 7.

Да се напише програма која за даден природен број m ќе ги испише сите броеви помеѓу 1 и 1000 за кои сумата на цифрите изнесува m.

Програма:

#include<stdio.h>int main () {int m, i, j, pom, suma, cifra; printf(“Vnesete go brojot m za sporedba: “);scanf(“%d”,&m); if (m>27) printf(“Ne postoi broj od 1 do 1000 so suma %d.\n”, m); else{ printf(“Broevi cij zbir na cifri e %d se: \n”, m);i = 1; while (i<=1000) {pom = i; suma = 0; while (n>0) {cifra = pom % 10; suma += cifra;pom /= 10;} if (suma == m) printf(“%d\t”, i);i++; }} return 0;}

Важна забелешка!!!

Да се нагласи зошто е потребно користењето на променливата pom.

Пример 8.

Да се испечатат сите броеви од 1000 до 100000 кои се деливи со 9.

Програма:

#include<stdio.h>int main () {int i; for(i=1000; i<10000; i++) if (i%9==0)printf(“%d\n”, i); return 0;}

Пример 9.

Да се испечатат и избројат сите природни броеви деливи со 3 чиј квадрат е помал од 1000.

Програма:

#include<stdio.h>int main () {int i; int vkupno = 0;for(i=1; i*i<1000; i++) if (i%3==0){ printf(“%d\n”, i);vkupno++; }printf(“Vkupno broevi ima %d\n”, vkupno); return 0;}

Пример 10.

Сите целобројни вредности за Целзиусови степени од 0 до 100 да се претстават во Келвини.

Програма:

#include<stdio.h>int main () {int i; for(i=1; i<= 100; i++) printf(“%d\n”, i+273);return 0; }

Пример 11.

Да се напише програма која ќе ги испечати сите броеви од зададен опсег кои исто се читаат и од лево на десно и од десно на лево.

Програма:

#include<stdio.h>int main () {int i, odb, dob, pom, prev, cifra; printf(“Vnesete vrednost za opsegot.\n”);printf(“Od koj broj?\n”); scanf(“%d”,&odb); printf(“Do koj broj?\n”); scanf(“%d”,&dob); for (i = odb; i<= dob; i++) {pom = i; prev = 0;while (pom>0) {cifra = pom % 10; prev=prev*10 + cifra;pom /= 10; }if (prev == i) printf(“%d\t”, i); }return 0; }

Пример 12.

Да се напише програма која ќе ги испечати сите броеви помали од број N составени само од парни цифри и ќе врати колку такви броја има.

Програма:

#include<stdio.h>int main () {int i, n, pom, prov, cifra, brojac; printf(“Do koj broj treba da se proveruva?\n”);scanf(“%d”,&n); brojac = 0;for (i = 1; i<= n; i++) {prov = 1; pom = i;while ((pom>0)&&prov) {cifra = pom % 10; if (cifra % 2) prov = 0;pom /= 10; }if (prov) {printf(“%d\t”, i); brojac++;} }printf(“\nIma vkupno %d broevi so samo parni cifri\n”, brojac); return 0;}

Questions & Answers

With the aid of diagrams,compare the short run equilibrium positions of a perfect competitor and an imperfect competitors
Monlay Reply
What is the term consultation in economics?
Nthabiseng Reply
why is it that the long run Average cost curve does not touch that of the short run curve at its minimum?
Baah Reply
In few words, what is the role of interest rate in economy?
Carlos Reply
what is population
Nyakeh Reply
total number of people in a given area or country
Clement
the total number of people at a given area or country
Clement
total number of people in a given area or country
okhiria
What is price Elasticity of demand?.
Samuel
The responsiveness of the quantity of a commodity demanded to a change in its price, expressed as the percentage change in quantity demanded divided by the percentage change in price.
EMMANUEL
why is it that the long run Average cost doesn't touch the short run cost curve at its minimum?
Baah
what is supply
Precious
please rice and beans will be what type of demand but note we mostly cook it together
Oladosu Reply
complementary or joint demand
Yillah
but did you know you can demand for rice without beans so how is it joint or complementary
Oladosu
From my point of view, rice and beans are replaceable goods, hence they can't be complementary.
Carlos
what are the money value
Wisdom Reply
Nothing more than a purchase power, in other words, $100 now, must have the same value after 1 year.
Carlos
what is Monopoly
Rebecca Reply
what is money
Lawal Reply
It can be define as a big transaction that can control any business for one place to another base.
Akinlo
money is recognisable note to accept both parties selling and buying
Hassan
i don still understan
Rene
hey
Abdul
hi
Rene
money is anything generally accepted as a medium of exchange
Awwal
Money is anything generally accepted as a medium of exchange and for the settlement of goods and services .
Korda
hi good ppl, pls help out
Tumi
discuss human and natural resources as develop strategies ro improving living condition of citizens in developing countries.
Tumi
I don't understand the question.
Naomi
it's a form of currency used for 2 or more individuals or parties in order to reach their amicable personal or business attainment. one must understand that money itself can manifest in multiple fashions for which the individuals or parties adheres.
are u trying to say we shld discuss ways in which human natural resources help in improving living condition of citizens in developing countries?
Naomi
money is a legal thunder generally accepted as a medium of exchange for the payment of debt ,goods and services
Naomi
money is a way of payment.
Carlos
money is any thing that is generally accepted as a medium of exchange good for good and settlement of debt and means of payment
Yillah
money is nothing but a object which is used for exchange of goods and services.
Harshita
money is anything that is generally accepted as payment of goods and services and settlement of debt
Rebecca
what is demand
Melissa Reply
demand is where the customer is willing and able to buy goods and services during a given period of time
idk
demand is the ability and willingness of an individual to buy goods and services at a given price in a particular period of time
Alpha
demand is the ability to buy a specific quantities of goods and services at a given price and at a specific period of time
rosemary
what are the rules of demand
rosemary
Rosemary Nsebon, Do you mean laws of demand?
Alpha
what are the rules of demand
Rene
the rule of demand is the higher the price the lower the quantity demanded and the lower the price the higher the quantity demanded
mbi
thank
Rene
what is unemployment
Rebecca
unemployment is a scenario or a phenomenon in an economy whereby people are willing are able to work but cannot a job
mbi
Suppose you have a team of two workers: one is a baker and one is a chef. Explain why the kitchen can produce more meals in a given period of time if each worker specializes in what they do best than if each worker tries to do everything from appetizer to dessert. please I need a urgent answer
Oladosu Reply
Enables individuals and countries to consume a variety of goods and services
Iddrisu
what is the meaning of competency
Oladosu Reply
competency is an ability and courage to do something perfectly
Abdullahi
ability to perform some task
Segun
rival
Ray
thanks 🙏 it is also the same with the core competency
Oladosu
A sufficient supply
Ebenezer
Ebenezer you mean the (core competency) right?
Oladosu
what is mean,median and mode
Ikeh Reply
mean is the average number of a given data
Gallant
median is the middle number of a given data
Gallant
in a given data sorry
Mitchel
hi
Sajib
Pls am new here
Physcal
what are development bank in Nigeria
Adedigba Reply
.hi
Physcal
hi
Adedigba
hw
Physcal
and cool
Rosie
nice to meet everyone
Rosie
hi how are dears
Mumtaz
how can we development economic in our country
Mumtaz
hi
Charm
Payroll and​ 4p
Wasuroj
Agriculture
Wasuroj
Export
Wasuroj
Transport
Wasuroj
Change management​ and​ cerrancy
Wasuroj
Empoyee
Wasuroj
Lawyer army and​ Lawyer​
Wasuroj
animal husbandry essay
Rakuane Reply
what's the primary location of capital and money market respectively
ALIMI
Difference between extinct and extici spicies
Amanpreet Reply
While the American heart association suggests that meditation might be used in conjunction with more traditional treatments as a way to manage hypertension
Beverly Reply
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get the best Algebra and trigonometry course in your pocket!





Source:  OpenStax, Вовед во програмирање. OpenStax CNX. Oct 28, 2013 Download for free at http://cnx.org/content/col11379/1.12
Google Play and the Google Play logo are trademarks of Google Inc.

Notification Switch

Would you like to follow the 'Вовед во програмирање' conversation and receive update notifications?

Ask