Search
 
SCRIPT & CODE EXAMPLE
 

C

hourglass sum

#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int soln(int arr[6][6]) {
    int i, j, sum,temp_sum;
    temp_sum = 0;
    sum = -9999999;
    for(i=0; i<6-2;i++) {
        for(j=0; j<6-2;j++){
            temp_sum = arr[i][j] + arr[i][j+1] + arr[i][j+2] +
                                   arr[i+1][j+1] +
                       arr[i+2][j] + arr[i+2][j+1] + arr[i+2][j+2];
            //printf("%d %d %d
", arr[i][j], arr[i][j+1], arr[i][j+2]);
            //printf("  %d   
", arr[i+1][j+1]);
            //printf("%d %d %d
", arr[i+2][j] ,arr[i+2][j+1] ,arr[i+2][j+2]);
            //printf("temp sum: %d 

", temp_sum);
            if(temp_sum > sum) {
                sum = temp_sum;
            }
        }
    }
    return sum;
}

int main(){
    int arr[6][6];
    for(int arr_i = 0; arr_i < 6; arr_i++){
       for(int arr_j = 0; arr_j < 6; arr_j++){
          scanf("%d",&arr[arr_i][arr_j]);
       }
    }
    printf("%d
", soln(arr));
    return 0;
}
Comment

PREVIOUS NEXT
Code Example
C :: macos prevent disk mounting 
C :: pygramid program in c 
C :: c linked list 
C :: eliminare file in c 
C :: C program to input the month number and output the month name using switch statement 
C :: . Simulate MVT and MFT. 
C :: do while loop in c 
C :: what is type casting in c programming 
C :: Command to create a static library in C 
C :: ltoa in c 
C :: vifm preview images 
C :: define constant c 
C :: c unused variable 
C :: check for duplicates c 
C :: boolean operators in c 
C :: typedef c 
C :: C Pass Individual Array Elements 
C :: can we use logical operators in switch c 
C :: convert c to phyton 
C :: semicolong after for() loop stackoverflow 
C :: rand in c 
C :: c ausgabe 
C :: remove every appearance of char without malloc in c 
C :: man write c 
C :: which one is faster loop or recursive function? 
C :: variadic macros in c 
C :: wait system call 
C :: profile time bash script 
C :: C Relationship Between Arrays and Pointers 
C :: Word Processor, Spreadsheet and Presentation Software are the examples of 
ADD CONTENT
Topic
Content
Source link
Name
6+4 =