Task 3-Correctness of square data - solution
Three integers are entered first. Correct data means that the number that represents the length of a page is positive. In order to be able to calculate the area and volume of a square, all three of its sides a, b, c need to be positive numbers. A complex condition should be set within the if statement: a > 0 && b > 0 && c > 0.
Problem solving:
Problem solving:
#include <stdio.h>
#include <stdlib.h>
int main()
{
double a,b,c,P,V; //a, b, c-sides of a square, P-area, V-volume
printf("Enter the lengths of the sides of the square a, b, c in cm");
scanf("%lf%lf%lf",&a,&b,&c);
/*Checking the correctness of the data, ie. whether the page lengths are positive numbers*/
if(a>0 && b>0 && c>0)
{
//the data are correct and the area and volume can be calculated
P=2*(a*b+b*c+a*c);
V=a*b*c;
printf("The area of the square is %.2f cm^2",P);
printf("The volume of the square is %.2f cm^2",V);
}
else{
printf("The data is incorrect because the page lengths cannot be negative numbers or zeros");
}
return 0;
}
#include <stdlib.h>
int main()
{
double a,b,c,P,V; //a, b, c-sides of a square, P-area, V-volume
printf("Enter the lengths of the sides of the square a, b, c in cm");
scanf("%lf%lf%lf",&a,&b,&c);
/*Checking the correctness of the data, ie. whether the page lengths are positive numbers*/
if(a>0 && b>0 && c>0)
{
//the data are correct and the area and volume can be calculated
P=2*(a*b+b*c+a*c);
V=a*b*c;
printf("The area of the square is %.2f cm^2",P);
printf("The volume of the square is %.2f cm^2",V);
}
else{
printf("The data is incorrect because the page lengths cannot be negative numbers or zeros");
}
return 0;
}