Advertisement
Guest User

Untitled

a guest
Jan 20th, 2020
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.17 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stddef.h>
  4. #include <math.h>
  5. #include <string.h>
  6.  
  7. int sum_greater(const int a, const int b, const int c){
  8.     if(a >= b && a >= c){
  9.         if(b >= c){
  10.             return a + b;
  11.         }
  12.         else{
  13.                 return a + c;
  14.         }
  15.     }
  16.     if(b >= a && b >= c){
  17.         if(a >= c){
  18.             return b + a;
  19.         }
  20.         else{
  21.                 return b + c;
  22.         }
  23.     }
  24.      if(c >= b && c >= a){
  25.         if(b >= a){
  26.             return c + b;
  27.         }
  28.         else{
  29.                 return a + c;
  30.         }
  31.     }
  32. }
  33.  
  34. int min_2d(const int size, int array[][size]){
  35.     int sum = array[0][0];
  36.     for(int i = 0; i < size; i++){
  37.         for(int j = 0; j < size; j++){
  38.             if(array[i][j] < sum){
  39.                 sum = array[i][j];
  40.             }
  41.         }
  42.     }
  43.     return sum;
  44. }
  45.  
  46. char last_letter(const char string[]){
  47.     char str;
  48.     for(int i = 0; i < strlen(string); i++){
  49.         if((string[i] >= 'a' && string[i] <= 'z') || (string[i] >= 'A' && string[i] <= 'Z')){
  50.             str = string[i];
  51.         }
  52.     }
  53.     return str;
  54. }
  55.  
  56. int longest_row(const int rows, const int cols, char array[rows]){
  57.     /*int arr[rows];
  58.     int max = 0;
  59.     printf("%d", rows);
  60.     for(int i = 0; i < rows; i++){
  61.         arr[i] = strlen(array[i]);
  62.     }
  63.     for(int i = 0; i < rows; i++){
  64.         if(arr[i] > max){
  65.             max = arr[i];
  66.         }
  67.     }
  68.     for(int i = 0; i < rows; i++){
  69.         if(arr[i] == max){
  70.             return i;
  71.         }
  72.     }*/
  73.     int result = 0;
  74.     int longest = 0;
  75.      for(int y = 0; y < rows; y++){
  76.         int len = strlen(array[y]);
  77.         if(result < len){
  78.             result = len;
  79.             longest = y;
  80.         }
  81.     }
  82.  
  83.     return longest;
  84. }
  85.  
  86. int main(){
  87.  
  88.     //printf("%d\n", sum_greater(2, 8, 8));
  89.  
  90.     //int array[2][2] = { {1, 2}, {0, -3} };
  91.     //printf("%d\n", min_2d(2, array));
  92.  
  93.     //printf("%c %c\n", last_letter("Once upon a time...."), last_letter("$a_b_c_d_1_2_3_4$"));
  94.     char array[3][31] = {"Hello","Hello, how are you?","I hope today is a lucky day..."};
  95.     printf("%d\n", longest_row(3,31,array));
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement