Professional Documents
Culture Documents
(8pts)
printf( "****\n***\n**\n*\n**\n***\n****\n" );
Answer 2:
#include <stdio.h>
int main( void )
{
int c = 5;
printf( "%d\n", c++ );
printf( "%d\n\n", c );
c = 8;
printf( "%d\n", ++c );
printf( "%d\n", c );
}
Answer 3:
Question 4 - What does the following program print? (8pts)
#include <stdio.h>
Answer 4:
Question 5 - Following C program that takes two integers and one of addition, subtraction, multiplication,
division, and remainder opeartions from the user as input, and calculates the entered operation between two
numbers. Complete the missing parts of the program given below by writing them in the boxes. (24pts)
Answer 5:
#include <stdio.h>
int main()
{
int num1, num2;
char option, control;
float result;
do{
printf("Enter 2 integer numbers : ");
scanf("%d%d", );
switch(option) {
case '+' :
result = num1 + num2;
printf("Operation : %d %c %d = %f \n",num1,option,num2,result);
break;
case '-' :
;
printf("Operation : %d %c %d = %f \n",num1,option,num2,result);
break;
case '*' :
;
printf("Operation : %d %c %d = %f \n",num1,option,num2,result);
break;
case '/' :
;
printf("Operation : %d %c %d = %f \n",num1,option,num2,result);
break;
case '%' :
;
printf("Operation : %d %c %d = %f \n",num1,option,num2,result);
break;
:
return 0;
}
Question 5 - Convert following Switch structure to corresponding if Else structure. (24pts)
switch (shape)
{
case '1':
printf("Please input the radius:\n");
scanf("%lf", &r);
area = r * r * 3.14159;
break;
case '2':
printf("Please input the side length:\n");
scanf("%lf", &x);
area = x * x;
break;
case '3':
printf("Please input the side lengths:\n");
scanf("%lf %lf", &x, &y);
area = x * y;
break;
default:
printf("Invalid input.");
return 0;
}
Answer 6 :
if (shape == '1')
{
printf("Please input the radius:\n");
scanf("%lf", &r);
area = r * r * 3.14159;
}
else if (shape == '2')
{
printf("Please input the side length:\n");
scanf("%lf", &x);
area = x * x;
}
else if (shape == '3')
{
printf("Please input the side lengths:\n");
scanf("%lf %lf", &x, &y);
area = x * y;
}
else
{
printf("Invalid input.");
return 0;
}