<< 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

what is mutation
Janga Reply
what is a cell
Sifune Reply
how is urine form
Sifune
what is antagonism?
mahase Reply
classification of plants, gymnosperm features.
Linsy Reply
what is the features of gymnosperm
Linsy
how many types of solid did we have
Samuel Reply
what is an ionic bond
Samuel
What is Atoms
Daprince Reply
what is fallopian tube
Merolyn
what is bladder
Merolyn
what's bulbourethral gland
Eduek Reply
urine is formed in the nephron of the renal medulla in the kidney. It starts from filtration, then selective reabsorption and finally secretion
onuoha Reply
State the evolution relation and relevance between endoplasmic reticulum and cytoskeleton as it relates to cell.
Jeremiah
what is heart
Konadu Reply
how is urine formed in human
Konadu
how is urine formed in human
Rahma
what is the diference between a cavity and a canal
Pelagie Reply
what is the causative agent of malaria
Diamond
malaria is caused by an insect called mosquito.
Naomi
Malaria is cause by female anopheles mosquito
Isaac
Malaria is caused by plasmodium Female anopheles mosquitoe is d carrier
Olalekan
a canal is more needed in a root but a cavity is a bad effect
Commander
what are pathogens
Don Reply
In biology, a pathogen (Greek: πάθος pathos "suffering", "passion" and -γενής -genēs "producer of") in the oldest and broadest sense, is anything that can produce disease. A pathogen may also be referred to as an infectious agent, or simply a germ. The term pathogen came into use in the 1880s.[1][2
Zainab
A virus
Commander
Definition of respiration
Muhsin Reply
respiration is the process in which we breath in oxygen and breath out carbon dioxide
Achor
how are lungs work
Commander
where does digestion begins
Achiri Reply
in the mouth
EZEKIEL
what are the functions of follicle stimulating harmones?
Rashima Reply
stimulates the follicle to release the mature ovum into the oviduct
Davonte
what are the functions of Endocrine and pituitary gland
Chinaza
endocrine secrete hormone and regulate body process
Achor
while pituitary gland is an example of endocrine system and it's found in the Brain
Achor
what's biology?
Egbodo Reply
Biology is the study of living organisms, divided into many specialized field that cover their morphology, physiology,anatomy, behaviour,origin and distribution.
Lisah
biology is the study of life.
Alfreda
Biology is the study of how living organisms live and survive in a specific environment
Sifune
Got questions? Join the online conversation and get instant answers!
Jobilize.com Reply

Get Jobilize Job Search Mobile App in your pocket Now!

Get it on Google Play Download on the App Store Now




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