Untitled

mail@pastecode.io avatar
unknown
plain_text
a year ago
3.2 kB
2
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

int creare(int n, int m, int **v){
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            v[i][j] = i + j;
}

int afisare(int n, int m, int **v){
     for(int i = 0; i < n; i++){
         for(int j = 0; j < m; j++){
             printf("%d;", v[i][j]);
         }
         printf("\n");
     }
}

int transpusa(int n, int m, int **v){
    for(int i = 0; i < m; i++){
        for(int j = 0; j < n ; j++){
            printf("%d;", v[j][i]);
        }
        printf("\n");
    }
}
    
    

int main(){
    int n, m;
    int **v;
    scanf("%d %d", &n, &m);
    v = (int**) malloc(n * sizeof(int*));
    
    for (int i = 0; i < n; i++)
        v[i] = (int*) malloc(m* sizeof(int));
    
    
    creare(n, m, v);
    afisare(n, m, v);
    printf("transpusa\n");
    transpusa(n, m, v);
    

}









#include "stdio.h"
#include "stdlib.h"

void max_min(int* v, int len, int* min, int* max) {
    *min = v[0];
    *max = v[0];
    for (int i = 0; i < len; i++) {
        if (v[i] > *max)
            *max = v[i];
        if (v[i] < *min)
            *min = v[i];
    }
}

int main() {
    int n;
    scanf("%d", &n);
    int* v = malloc(n * sizeof(int));
    for (int i = 0; i < n; i++)
        scanf("%d", &v[i]);

    int* min = malloc(sizeof(int)), *max = malloc(sizeof(int));
    max_min(v,n,min,max);
    printf("min=%d\nmax=%d\n",*min,*max);
}






#include <stdio.h>
#include <stdlib.h>

int cif_max(long nr) {
    int max = nr % 10, maxx = max;
    nr/=10;
    while (nr) {
        maxx = nr%10;
        if (maxx > max) max = maxx;
        nr /= 10;
    }
    return max;
}

int nr_cif(long nr) {
    int k = 0;
    while (nr) {
        k++;
        nr /= 10;
    }
    return k;
}

void sortare(int* v, int len, int (*f)(long)) {
    for (int i = 0; i < len; i++) {
        for (int j = i; j < len; j++) {
            int r1 = f(v[i]);
            int r2 = f(v[j]);
            if (r1 == r2) {
                if (v[i] > v[j]) {
                    int aux = v[i];
                    v[i] = v[j];
                    v[j] = aux;
                }
            }

            if (r1 > r2) {
                int aux = v[i];
                v[i] = v[j];
                v[j] = aux;
            }
        }
    }
}

void afisare(int* v, int len) {
    for (int i = 0; i < len; i++) {
        printf("%d;",v[i]);
    }
    printf("\n");
}

int main() {
    int n;
    scanf("%d", &n);
    int v[n];
    for (int i = 0; i < n; i++) {
        scanf("%d", &v[i]);
    }
    printf("cifra maxima: ");
    sortare(v, n, cif_max);
    afisare(v, n);
    printf("nr. cifre: ");
    sortare(v, n, nr_cif);
    afisare(v, n);
} 






#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int my_strlen(char *v){
    int k = 0;
    while(*v != '\0'){
        ++v;
        k++;
    }
    return k;
}

int main() {
    char* s;
    s = malloc(sizeof(char) *100);
    scanf("%s", s);
    printf("%d", my_strlen(s));
    return 0;
}