Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1.priklad
- #include <stdio.h>
- void nacitaj(double *a, double *b);
- double obsah(double a, double b);
- double obvod(double a, double b);
- int main(){
- double a, b, (*p_fn)();
- char c;
- nacitaj(&a, &b);
- while (getchar() != '\n');
- if ((c = getchar()) == 's')
- p_fn = obsah;
- else if (c == 'o')
- p_fn = obvod;
- else{
- printf("Neplatna volba\n");
- return 1;
- }
- printf("%g\n", (*p_fn)(a, b));
- return 0;
- }
- void nacitaj(double *a, double *b){
- scanf("%lf %lf", a, b);
- }
- double obsah(double a, double b){
- return (a*b);
- }
- double obvod(double a, double b){
- return (2 * a + 2 * b);
- }
- //2.priklad
- #include <stdio.h>
- #define NULL 0
- int cislica(char c);
- int male_pismeno(char c);
- int biely(char c);
- int velke_pismeno(char c);
- int zisti(FILE *fr, int(*p_fn)());
- void otvor(void **p_fr);
- int main(){
- int n, i, (*p_fn)();
- char volba;
- FILE *fr=NULL;
- otvor(&fr);
- if (fr == NULL)
- return 1;
- scanf("%d", &n);
- for (i = 0; i < n; i++){
- scanf("\n%c", &volba);
- switch (volba){
- case 'b': p_fn = biely; break;
- case 'v': p_fn = velke_pismeno; break;
- case 'm': p_fn = male_pismeno; break;
- case 'c': p_fn = cislica; break;
- default:
- printf("Neznama volba\n");
- continue;
- }
- printf("%d\n", zisti(fr, (*p_fn)));
- }
- if (fclose(fr) == EOF){
- printf("Subor sa nepodarilo zatvorit\n");
- return 1;
- }
- return 0;
- }
- void otvor(void **p_fr){
- *p_fr = fopen("ZNAKY.TXT", "r");
- }
- int zisti(FILE *fr, int(*p_fn)()){
- int pocitadlo = 0;
- char c;
- while ((c = getc(fr)) != EOF){
- pocitadlo += (*p_fn)(c);
- }
- rewind(fr);
- return pocitadlo;
- }
- int cislica(char c){
- if (c >= '0' && c <= '9')
- return 1;
- return 0;
- }
- int male_pismeno(char c){
- if (c >= 'a' && c <= 'z')
- return 1;
- return 0;
- }
- int biely(char c){
- if (c == '\n' || c == '\t' || c == ' ')
- return 1;
- return 0;
- }
- int velke_pismeno(char c){
- if (c >= 'A' && c <= 'Z')
- return 1;
- return 0;
- }
- //3.priklad
- #include <stdio.h>
- int main(){
- char *p_str;
- int i, n;
- scanf("%d\n", &n);
- p_str = (char*)malloc(n*sizeof(char));
- for (i = 0; i < n; i++)
- *(p_str + i) = getchar();
- for (--n; n >= 0; n--)
- putchar(*(p_str + n));
- putchar('\n');
- return 0;
- }
- //4.priklad
- #include <stdio.h>
- int scitaj();
- int odcitaj();
- int nasob();
- int del();
- int main(){
- int(*p_fn)();
- char volba;
- while ((volba = getchar()) != 'e'){
- while (getchar() != '\n');
- switch (volba){
- case 's': p_fn = scitaj; break;
- case 'o': p_fn = odcitaj; break;
- case 'n': p_fn = nasob; break;
- case 'd': p_fn = del; break;
- default:
- printf("Operacia nie je podporovana\n");
- continue;
- }
- printf("%d\n", (*p_fn)());
- while (getchar() != '\n');
- }
- return 0;
- }
- int scitaj(){
- int a, b;
- scanf("%d %d", &a, &b);
- return a + b;
- }
- int odcitaj(){
- int a, b;
- scanf("%d %d", &a, &b);
- return a - b;
- }
- int nasob(){
- int a, b;
- scanf("%d %d", &a, &b);
- return a * b;
- }
- int del(){
- int a, b;
- scanf("%d %d", &a, &b);
- return a / b;
- }
- //5.priklad
- #include <stdio.h>
- int main(){
- int *a, *b, c;
- a = (int*)malloc(sizeof(int));
- b = (int*)malloc(sizeof(int));
- scanf("%d %d %d", a, b, &c);
- printf("%d + %d + %d = %d\n", *a, *b, c, (*a) + (*b) + c);
- return 0;
- }
- //6.priklad
- #include <stdio.h>
- #include <math.h>
- #define STEP 0.2
- #define PREC 0.01
- #define PRESNOST 0.000001
- double f1(double x);
- double f2(double x);
- double deriv(double(*p_fn)(), double x);
- int main(){
- double r1, r2, (*p_f1)(), (*p_f2)();
- p_f1 = f1;
- p_f2 = f2;
- scanf("%lf %lf", &r1, &r2);
- printf("x f1(x) f1'(x) f2(x) f2'(x)\n");
- while (r1 <= r2 + PRESNOST){
- printf("%.2lf %.2lf %.2lf %.2lf %.2lf\n", r1, f1(r1), deriv((*p_f1), r1), f2(r1), deriv((*p_f2), r1));
- r1 += STEP;
- }
- return 0;
- }
- double f1(double x){
- return (exp(x) / (fabs(x) + 1));
- }
- double f2(double x){
- return (x * sin(x));
- }
- double deriv(double(*p_fn)(), double x){
- return ((*p_fn)(x + PREC) - (*p_fn)(x))/PREC;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement