In: Computer Science
Q1: The expression A = (E – F)/((P + (3*Q))*((2*R) – (5*S))) is not a valid SPLan assignment statement. Write a sequence of assignment statements that will perform the equivalent calculation.
Q2: Write a program which asks the user to input an integer. If the integer is less than zero, the program should output the message “Negative, the absolute value is ”, followed by the absolute value of the number. If the input is zero, the program should output the message “Zero.” If the input is greater than zero, the program should output the message “Positive.”
Q1.
#include <stdio.h>
int main()
{
// Variable Declaration
int A,P,Q,R,E,F,S;
E=50;
F=10;
P=2;
Q=1;
R=2;
S=1;
//A=(E-F)/((P+(3*Q))*((2*R)-(5*S)));
Q=3*Q;
P=P+Q;
R=R*2;
S=S*5;
P=P*(R-S);
E=E-F;
E=E/P;
A=E;
printf("%d",A);
return 0;
}
Output Snapshots:
Q2
// C Code
#include <stdio.h>
int main()
{
int num;
printf("Enter an integer");
scanf("%d",&num);
if(num<0)
{
num=abs(num);
printf("Negative, the absolute value is %d",num);
}
else if(num==0)
printf("Zero");
else
printf("Positive");
return 0;
}
Output Snaphsot: