Advertisement
Neo_Feo

Horor_CPP3_Done

Sep 17th, 2023
735
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.36 KB | Source Code | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. int suma(int lenght, int height,int array [lenght][height]){
  6.     if(height<2){
  7.         printf("\033[31m Nu exista  coloana cu numarul 2 \033[0m");
  8.         exit(-6);
  9.     }
  10.     int sum = 0;
  11.     for(int i = 0; i<lenght;++i){
  12.         sum += array[i][1];
  13.     }
  14.     return sum;
  15. }
  16.  
  17. int produsul (int row, int col,int array [row][col]){
  18.         if(col<2){
  19.             printf("\033[31m Nu exista  coloana cu numarul 2 \033[0m");
  20.             exit(-6);
  21.         }
  22.         int prod = 1;
  23.         for(int i = 0; i<row;++i){
  24.             prod *= array[i][1];
  25.         }
  26.         return prod;
  27. }
  28.  
  29. void input_into_Array(int row,int col, int array[row][col]){
  30.         for (int i = 0; i < row; i++){
  31.             printf("Introduceti elementele randului %i\n",i+1);
  32.             for(int j = 0; j < col; j++){
  33.                 printf("%i : ", j+1);
  34.                 scanf("%i",&array[i][j]);
  35.             }
  36.         }
  37. }
  38.  
  39. int main()
  40. {
  41.     int row, col;
  42.  
  43.     printf("Introduceti numarul de coloane: ");
  44.     scanf("%i",&col);
  45.     printf("Introduceti numarul de randuri: ");
  46.     scanf("%i",&row);
  47.  
  48.     row = abs(row);
  49.     col = abs(col);
  50.  
  51.     int i [row][col];
  52.  
  53.     input_into_Array(row,col,i);
  54.  
  55.     printf("suma este: %i\n",suma(row,col,i));
  56.     printf("produsul este: %i",produsul(row,col,i));
  57.     return 0;
  58. }
  59.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement