URI Online Judge Solution 1186 Below the Secundary Diagonal Using C, Python Programming Language.
Read an uppercase character that indicates an operation that will be performed in an array M[12][12]. Then, calculate and print the sum or average considering only that numbers that are below of the Secundary diagonal of the array, like shown in the following figure (green area).

Input
The first line of the input contains a single uppercase character O ('S' or 'M'), indicating the operation Sum or Average (Média in portuguese) to be performed with the elements of the array. Follow 144 floating-point numbers of the array.
Output
Print the calculated result (sum or average), with one digit after the decimal point.
Input Sample | Output Sample |
S | 12.6 |
Solution Using C:
#include <stdio.h>
int main()
{
double a=0.0, M[12][12];
char T[2];
int x,y,c=0;
scanf("%s", &T);
for(x=0;x<=11;x++)
{
for(y=0; y<=11; y++)
{
scanf("%lf", &M[x][y]);
}
}
for(x=11; x>0; x--)
{
for(y=11; y>c; y--)
a += M[x][y];
c++;
}
if(T[0]=='S')
printf("%.1lf\n",a);
else if(T[0]=='M')
{
a=a/66.0;
printf("%.1lf\n",a);
}
return 0;
}
Comments
Post a Comment