Code:
#include<stdio.h>
#include<math.h>
int inrange(int, int, int, int);
int cubesum(int, int, int, int);
int avsqrsum(int, int, int, int);
int squaresum(int, int, int, int);
int inrage(int, int, int, int);
int main()
{
int a, b, c, d;
char chr;
printf("Eisagete 4 arithmous\n");
scanf("%d%d%d%d", &a, &b, &c, &d);
printf("Tora dialekste ena gramma apo ta S, C, A\n");
scanf("%c", &chr);
while (chr != 'W') {
if (inrange(a, b, c, d) == 1) {
switch (chr) {
case 'S':
printf("SUM OF THE SQUARES %d\n", squaresum(a, b, c, d));
break;
case 'C':
printf("SUM OF THE CUBES %d\n", cubesum(a, b, c, d));
break;
case 'A':
printf("AVERAGE OF THE SQUARES %d\n", avsqrsum(a, b, c, d));
break;
} /*kleinei to switch */
} /* kleinei to if */
else
printf("INVALID DATA\n");
} /* kleinei to while */
return 0;
}
int inrange(int a, int b, int c, int d)
{
int flag = 1;
if ((a >= 10 || a <= 20) || (b >= 10 || b <= 20) || (c >= 10 || c <= 20) || (d >= 10 || d <= 20))
flag = 1;
return flag;
}
int squaresum(int a, int b, int c, int d)
{
return pow(a, 2) + pow(b, 2) + pow(c, 2) + pow(d, 2);
}
int cubesum(int a, int b, int c, int d)
{
return pow(a, 3) + pow(b, 3) + pow(c, 3) + pow(d, 3);
}
int avsqrsum(int a, int b, int c, int d)
{
return (pow(a, 2) + pow(b, 2) + pow(c, 2) + pow(d, 2)) / 4;
return 0;
}
%c is tricky, because it doesn't obey the usual "skip whitespace" rule that all the other conversions follow.