Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1. priklad
- #include <stdio.h>
- void nasobok(double x, int n);
- int main(){
- int n;
- double x;
- scanf("%lf %d", &x, &n);
- nasobok(x, n);
- return 0;
- }
- void nasobok(double x, int n){
- int i, j;
- double vysledok = 0;
- for (i = 1; i <= n; i++){
- vysledok += x;
- printf("%.2lf * %d = %.2lf\n", x, i, vysledok);
- }
- return;
- }
- //2.priklad
- #include <stdio.h>
- void mocnina(double x, int n);
- int main(){
- double x;
- int n;
- scanf("%lf %d", &x, &n);
- mocnina(x, n);
- return 0;
- }
- void mocnina(double x, int n){
- int i, j;
- double vysledok = 1;
- for (i = 1; i <= n; i++){
- vysledok *= x;
- printf("%.2lf^%d = %.2lf\n", x, i, vysledok);
- }
- return;
- }
- //3.priklad
- #include <stdio.h>
- #include <stdlib.h>
- //#define LADENIE_ZAKLADNE
- #define LADENIE_PODROBNE
- int main() {
- FILE *fr;
- float suma, sucet=0, ciastka;
- #if defined (LADENIE_ZAKLADNE) || defined (LADENIE_PODROBNE)
- printf("Otvorenie suboru\n");
- #endif
- fr = fopen("suma.txt", "r");
- #ifdef LADENIE_PODROBNE
- printf("Subor otvoreny\n");
- #endif
- #if defined(LADENIE_ZAKLADNE) || defined (LADENIE_PODROBNE)
- printf("Kontrola sumy\n");
- #endif
- fscanf(fr, "%f", &suma);
- while (fscanf(fr, "%f", &ciastka)==1){
- sucet += ciastka;
- #ifdef LADENIE_PODROBNE
- printf("Suma: %g\n", sucet);
- #endif
- }
- printf("Suma je %s\n", (suma == sucet) ? "spravna" : "nespravna");
- #ifdef LADENIE_PODROBNE
- printf("Suma skontrolovana\n");
- #endif
- #if defined (LADENIE_ZAKLADNE) || defined (LADENIE_PODROBNE)
- printf("Zatvaranie suboru\n");
- #endif
- fclose(fr);
- #ifdef LADENIE_PODROBNE
- printf("Subor zatvoreny\n");
- #endif
- return 0;
- }
- //4.priklad
- #include <stdio.h>
- int main(){
- char c1, c2, *p_c;
- p_c = &c2;
- while ((c1 = getchar()) != '*'){
- *p_c = c1;
- printf("c1: %c (%p), c2: %c (%p), p_c: %c (%p)\n", c1, &c1, c2, &c2, *p_c, p_c);
- }
- return 0;
- }
- //5. priklad
- //Michal Kováčik Utorok 9:00
- #include <stdio.h>
- void zakladny_tvar(int a, int b);
- int main(){
- int a,b;
- scanf("%d %d", &a, &b);
- zakladny_tvar(a, b);
- return 0;
- }
- void zakladny_tvar(int a, int b){
- int nsd, prve, druhe, pom;
- if (a >= b){
- prve = a;
- druhe = b;
- }
- else{
- prve = b;
- druhe = a;
- }
- while (druhe){
- pom = druhe;
- druhe = prve % druhe;
- prve = pom;
- }
- nsd = prve;
- printf("Zakladny tvar zlomku: %d/%d\n", a / nsd, b / nsd);
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement