Primjeri programa u C – u

  1. #include <stdio.h>
    #include <math.h>

    double funkcija (double x);
    main() {
    double x,h, izv1, izv2, rel, aps,f;
    printf (“Unijeti xn”);
    scanf (“%f”,&x);
    h=0.1;
    while (h>0.00000001) {
    izv1=(funkcija(x+h)-funkcija(x))/h;
    izv2=exp(x)*cos(x)-exp(x)*sin(x);
    aps=fabs(izv2-izv1);
    rel=fabs(aps/izv2)*100;
    printf (“%f %f %f n”, h, aps, rel);
    h=h*0.9;
    }
    return (0);
    }

    double funkcija (double x) {
    double f;
    f=exp(x)*cos(x);
    return (f);
    }

     

    2.# include <stdio.h>
    # include <math.h>

    main() {
    int i,j,n,a[9][9],b[9][9],c[9][9],d[9][9],sk1,srn,trag,k,s1,s2;
    printf (“Unesi dimenzije matricen”);
    scanf (“%d”,&n);
    printf (“Unesi elemente matrice n”);
    for (i=0;i<n;i++) {
    for (j=0;j<n;j++) {
    scanf (“%d”,&a[i][j]);
    }
    }
    for (i=0;i<n;i++) {
    for (j=0;j<n;j++) {
    printf (“%d “,a[i][j]);
    }
    printf (“n”);
    }
    sk1=0;
    for (i=0;i<n;i++){
    sk1=sk1+a[i][0];
    }
    printf (“suma elemenata prve kolone je: %d n”, sk1);
    srn=0;
    for (i=0;i<n;i++){
    srn=srn+a[n-1][i];
    }
    printf (“suma elemenata n-tog reda je: %d n”, srn);
    trag=0;
    for (i=0;i<n;i++){
    trag=trag+a[i][i];
    }
    printf (“trag matrice je: %d n”, trag);
    printf (“transponovana matrican”);
    for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
    b[i][j]=a[j][i];
    printf (“%d “, b[i][j]);
    }
    printf (“n”);
    }
    for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
    c[i][j]=a[i][j]+b[i][j];
    }
    }
    printf (“suma matrice A i njene transponovane ATn”);
    for (i=0;i<n;i++) {
    for (j=0;j<n;j++) {
    printf (“%d “,c[i][j]);
    }
    printf (“n”);
    }
    for (i=0; i<n; i++) {
    for (j=0; j<n; j++) {
    d[i][j]=0;
    for (k=0; k<n; k++) {
    d[i][j]+=a[i][k]*b[k][j];
    }
    }
    }
    printf (“proizvod matrica A i ATn”);
    for (i=0;i<n;i++) {
    for (j=0;j<n;j++) {
    printf (“%d “,d[i][j]);
    }
    printf(“n”);
    }
    s1=0;
    for (i=0; i<n; i++) {
    for (j=i+1; j<n; j++) {
    s1+=a[i][j];
    }
    }
    printf (“suma elemenata iznad glavne dijagonale je: %d n”, s1);
    s2=0;
    for (i=0; i<n; i++) {
    for (j=0; j<i; j++) {
    s2+=a[i][j];
    }
    }
    printf (“suma elemenata ispod glavne dijagonale je: %d n”, s2);
    return(0);
    }

Share

Leave a Reply

Your email address will not be published. Required fields are marked *