Created
September 19, 2018 13:46
-
-
Save sbarisic/8cac1df0520c640193192c9fd24360a5 to your computer and use it in GitHub Desktop.
Vjezba
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define _CRT_SECURE_NO_WARNINGS | |
#include <stdio.h> | |
#include <math.h> // za sqrtf() | |
struct trokut { | |
float a; | |
float b; | |
float c; | |
}; | |
void ispisi_iteracije(int broj) { | |
for (int i = 0; i < broj; i++) | |
printf("%i\n", i); | |
} | |
float suma(float a, float b, float c) { | |
return a + b + c; | |
} | |
void suma2(int* a, int* b, int* c) { | |
*c = *a + *b; | |
} | |
int main(int argc, const char** argv) { | |
// 3. | |
float a; | |
float b; | |
float c; | |
printf("Unesi realan broj: "); | |
scanf("%f", &a); | |
printf("Unesi realan broj: "); | |
scanf("%f", &b); | |
printf("Unesi realan broj: "); | |
scanf("%f", &c); | |
printf("%f,%f,%f = %f\n", a, b, c, suma(a, b, c)); | |
// 4. | |
int i = 0; | |
int min; | |
int max; | |
while (i < 5) { | |
int broj; | |
printf("Molimo unesite broj: "); | |
scanf("%i", &broj); | |
// Postavi prvi uneseni broj kao najmanja i najveca unesena vrijednost | |
if (i == 0) { | |
min = broj; | |
max = broj; | |
} | |
// Ako je uneseni broj manji od trenutnog najmanjeg broja | |
// onda najmanji broj = trenutno uneseni broj | |
if (broj < min) | |
min = broj; | |
if (broj > max) | |
max = broj; | |
i++; | |
} | |
printf("Najmanji = %i\nNajveci = %i\n", min, max); | |
// 5. | |
int broj_iteracija; | |
printf("Unesite broj iteracija: "); | |
scanf("%i", &broj_iteracija); | |
ispisi_iteracije(broj_iteracija); | |
// 6. | |
struct trokut t; | |
printf("Unesi prvi katetu: "); | |
scanf("%f", &t.a); | |
printf("Unesi drugu katetu: "); | |
scanf("%f", &t.b); | |
t.c = sqrtf((t.a * t.a) + (t.b *t.b)); | |
printf("Hipotenuza: %f\n", t.c); | |
// 7. | |
FILE* F = fopen("datoteka.txt", "r"); | |
while (1) { | |
int znak = fgetc(F); | |
// Ako nije kraj datoteke, ispisi znak | |
// inace prekini petlju | |
if (znak != EOF) | |
printf("%c", znak); | |
else | |
break; | |
} | |
// 8. | |
int a_polje[5]; | |
int b_polje[5]; | |
int c_polje[5]; | |
for (int i = 0; i < 5; i++) | |
{ | |
printf("Unesi a element: "); | |
scanf("%i", &a_polje[i]); | |
printf("Unesi b element: "); | |
scanf("%i", &b_polje[i]); | |
} | |
for (int i = 0; i < 5; i++) | |
{ | |
c_polje[i] = a_polje[i] + b_polje[i]; | |
printf("%i + %i = %i\n", a_polje[i], b_polje[i], c_polje[i]); | |
} | |
// 9. | |
int broj_a; | |
int broj_b; | |
int broj_c; | |
printf("Unesi broj: "); | |
scanf("%i", &broj_a); | |
printf("Unesi broj: "); | |
scanf("%i", &broj_b); | |
suma2(&broj_a, &broj_b, &broj_c); | |
printf("Suma: %i\n", broj_c); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment