1 / 11

Struktura programa

Struktura programa. #include< >  popis predprocesorskih naredbi (stdio.h, stdlib.h, math.h, conio.h) main() { deklaracija naredbi sa inicijalizacijom naredbe }. C++ ULAZNO IZLAZNE NAREDBE. Ulazne naredbe. Upis znakova c = getchar(); (upis jednog znaka + enter)

jin
Download Presentation

Struktura programa

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Struktura programa #include< >  popis predprocesorskih naredbi (stdio.h, stdlib.h, math.h, conio.h) main() { deklaracija naredbi sa inicijalizacijom naredbe }

  2. C++ULAZNO IZLAZNE NAREDBE

  3. Ulazne naredbe • Upis znakova • c = getchar(); (upis jednog znaka + enter) • c = getch(); (upis jednog znaka - bez enter) • c = gets(); (upis niza znakova)

  4. Univerzalni upis scanf(“formati varijabli”,lista varijabli) Format Značenja %c učitava jedan znak %d učitava cijeli broj %ld učitava long int %f učitava realan broj %s učitava string, niz znakova

  5. Primjer 1 { int a; float b; char c; scanf(“%d,%f,%c”,&a,&b,&c); } ako upišemo 2,3.4,g  a=2 b=3.4 c=‘g’ Napomena: ako u scanf piše zarez(,) obavezno kod upisa koristimo (,)

  6. Primjer 2 { int a,b; char c[10]; scanf(“%2d %d %3s”,&a,&b,&c); } ako upišemo 123456proba  a=12 b=3456 c=“pro” Napomena: %2d – prve dvije znamenke

  7. Izlazne naredbe • Ispis znakova • putchar(c); (ispis jednog znaka) • putch(c); (ispis jednog znaka) • puts(c); (ispis niza znakova) • puts(“Ovo je samo primjer”)

  8. Univerzalni ispis printf(“tekst ili formati varijabli”,lista varijabli) Format Značenja %c ispisuje jedan znak %d ispisuje cijeli broj %ld ispisuje long int %f ispisuje realan broj %s ispisuje string, niz znakova \n prelazi u novi red

  9. Primjer 1 { printf(“Dobar dan”); } • Dobar dan (točka umetanja iza znaka ‘n’) Napomena: ako u printf stavimo “ “ ispisuje se niz znakova između navodnika { printf(“Dobar dan\n”); } • Dobar dan (točka umetanja u novi red)

  10. Primjer 2 { int a=345; float b=456.372; printf(“%d %f”,a,b); } • 345 456.372 { int a=345; float b=456.372; printf(“a=%d, b=%f”,a,b); } • a=345, b=456.372

  11. Primjer 3 { int a=345; float b=456.372; printf(“\na=%5d, b=%7.2f”,a,b); } • a= 345, b= 456.37

More Related