Professional Documents
Culture Documents
Instructions
There are 8questions in this assignment.
This evaluation instrument, if submitted after due date, will not be evaluated,
and a score of zero will be awarded if it is a graded instrument.
Email/paper/other modes of submissions will not be accepted.
Upload a pdfversion of this document.
Grading: 2 points
Questions:
ii. #include<stdio.h>
void main ()
{
int a, b;
a=10, b=20;
printf(“%d”, a, b);
}
4. Suppose a, b and c are integer variables that have assigned the values a=8, b=3 and c=-5. De-
termine the value of each of the following arithmetic expressions:
i. 2*b+3*(a-c)
NAME – Aditya Mishra ROLL NO. – 180102114 SAP ID - 1000011196
ii. #include<stdio.h>
void main ()
{
int x=20, y=20, z=20;
x==y=z;
printf (“%d”, x);
}
iii. #include<stdio.h>
void main ()
{
int x=5, y=6;
x=x==0;
y==y+1
printf (“%d%d”, x, y);
}
ii. #include<stdio.h>
void main ()
{
int x=5.3%2;
printf (“%d”, x);
}
Solutions –
Q1) The required C program is given below –
#include<stdio.h>
int main() {
float radius, area;
return (0);
}
NAME – Aditya Mishra ROLL NO. – 180102114 SAP ID - 1000011196
OUTPUT –
Q2) The algorithm for finding the factorial of a number is given below –
Step 1: Start
Step 2: Read a number n
Step 2: Initialize variables:
i = 1, fact = 1
Step 3: if i <= n go to step 4 otherwise go to step 7
Step 4: Calculate
fact = fact * i
Step 5: Increment the i by 1 (i=i+1) and go to step 3
Step 6: Print fact
Step 7: Stop
Q3 ) i) It has a syntax error, more appropriately a semantic error. “Void” is NOT a datatype AT
ALL, and specifically for variables in C language. Its just a keyword specifically created to
declare/identify procedures or functions which do not return a value, speaking in the context of
C language.
ii) The print statement will fetch the subsequent arguments for the ‘%d’ format specifier, since
‘a’ is the first argument thus the value corresponding to ‘a’ will get printed, rest of the arguments
will be ignored.
Therfore, OUTPUT - 10
Q4) Given, a = 8, b = 3, c = -5
i) 2*b+3*(a-c)
= 2*b+3*(a-(-5))
= 2*b+3*(8+5)
NAME – Aditya Mishra ROLL NO. – 180102114 SAP ID - 1000011196
= 2*b+3*13
= 2*3+3*13
= 6+39 = 45
ii) a*(c%b)
= 8*((-5)%3)
= 8*(-2) = 16
iii) a/c
= 8/(-5) = -1
iv) a*b/c
= 8*3/(-5) = 24/(-5) = -4
v) a-b*a+a*15/3
= 8-3*8+8*15/3
= 8-3*8+8*5
= 8-24+40
= -16+40 = 24
Q5) i) In the main function one of the unary decrement operators is syntactically deficient of
recognizing its operand in this statement.
If the compiler treats the operators as postfix because of greater precedence then since their
associativity is left to right thus, the operation couldn’t proceed since no leftmost
NAME – Aditya Mishra ROLL NO. – 180102114 SAP ID - 1000011196
ii) In main function, in the expression statement “x==y=z”, the assignment operator doesn’t has
a left operand of assignment. Since the relational operator “==” has higher precedence thus the
operands x and y are assigned to it and is evaluated first which has a constant value, therefore the
binary assignment operator “=” doesn’t has the valid left operand i.e. a variable.
iii) The only error is that the print statement isn’t preceeded by a semicolon.
#include<stdio.h>
int main()
{ float Fahrenheit, Celsius;
printf("Enter the scale in fahrenheit = ");
scanf("%f", &Fahrenheit);
Celsius = ((Fahrenheit-32)*5)/9;
printf("\n\n Temperature in Celsius is : %f",Celsius);
return (0);
}
OUTPUT –
NAME – Aditya Mishra ROLL NO. – 180102114 SAP ID - 1000011196
#include<stdio.h>
void main()
{
int x = 10;
int y = 15;
#include<stdio.h>
void main()
{
int n = 9, div = 0;
// wrong logic
// number is divided by 0,
// so this program abnormally terminates
div = n/0;
NO Output.
void main()
{
int a, b, c;
a + b = c;
}
Q8) i) In the arithmetic expression statement “x=x+x*++x”, the increment operator has the
highest precedence thus it will be evaluated first. Since the postfix has greater precedence thus it
needs a valid left operand which it doesn’t has, so the compiler will treat the operator as prefix.
Now since in prefix first the variable is incremented and then the expression is evaluated thus
The output will be –
x=3+3*3
x=3+9
x=12
ii) Syntax error, since the binary modulo operator can only be applied to interger datatypes and
not floating point or double.