QP : May-2023 – PPS [MID SEM]

Ans 1(A)>

Ans 1(A)>

  • scanf : Reads input from the user, allowing you to specify the format and store the values.
  • printf : Displays output to the user, with options for formatting and printing data.
  • gets : Reads a line of text from the user, but it’s considered unsafe and deprecated.
  • puts : Writes a string to the output, followed by a newline character.
  • getch : Reads a single character directly from the keyboard, without displaying it.
  • putch : Displays a single character on the screen, without moving to the next line.

Ans 1(C)> Implicit type conversion, also known as type coercion, is an automatic conversion that occurs when a value of one data type is assigned to a variable of another data type without the programmer explicitly specifying the conversion. For example: 

int num1 = 10;  
float num2 = num1;

Explicit type conversion, also known as type casting, is a manual conversion that is explicitly specified by the programmer using casting operators. For example:

float num1 = 10.5;  
int num2 = (int)num1;

Ans 2(A)

  1. Arithmetic Operators
  2. Relational Operators.
  3. Logical Operators
  4. Assignment Operators
  5. increment and Decrement Operators
  6. Bitwise Operators
  7. Conditional Operators
  8. Special Operators

We use the ternary operator in C to run one code when the condition is true and another code when the condition is false.

The syntax of ternary operator is :

Test Condition ? expression1 : expression 2;
#include<stdio.h>
#include<conio.h>
void main() {
  int age;
  clrscr();
  printf("Enter your age: ");
  scanf("%d", &age);

  (age >= 18) ? printf("You can vote") : printf("You cannot vote");

  getch();
}

OR

Ans 2(A)> The initialization step is executed only once at the beginning of the loop. The condition is checked before each iteration of the loop, and if it is true, the code inside the loop is executed is called entry controlled loop.

The entry controlled loop are for and while.

For Loop: 

The for loop is used to execute a block of code repeatedly for a fixed number of times.  

The syntax of a for loop is as follows: 

The initialization step is executed only once at the beginning of the loop. The condition is checked before each iteration of the loop, and if it is true, the code inside the loop is executed. After each iteration, the increment/decrement step is executed. The loop stops when the condition becomes false. 

Example: 

While Loop: 

The while loop is used to execute a block of code repeatedly as long as a certain condition is true.  

The syntax of a while loop is as follows: 

The condition is checked at the beginning of each iteration of the loop, and if it is true, the code inside the loop is executed. The loop continues until the condition becomes false. 

Example: 

Ans:2(B)

#include <stdio.h>
#include<conio.h>
void main()
{
    int n;
    clrscr();
    printf("Enter a number :");
    scanf("%d",&n);
    if (n >= 0)
        printf("%d is a positive number \n", n);
    else
        printf("%d is a negative number \n", n);
getch();
}

OR

Ans 2(B)

#include<stdio.h>
#include<conio.h>
void main()
{
	float p,y,r,si;
	clrscr();
	printf("Enter the valve:");
	scanf("%f",&p);
	printf("Enter the rate of interest:");
	scanf("%f",&r);
	printf("Enter the year:");
	scanf("%f",&y);
	si=(p*r*y)/100;
	printf("simple interset=%f",si);
	getch();
}

Ans 3(A)

#include<stdio.h>
#include<conio.h>
void main()
{
  int a,b;
  clrscr();
 printf("\nEnter first value : ");
  scanf("%d", &a);
  printf("Enter second value : ");
  scanf("%d", &b);
  printf("\nbefore swape first value : %d " ,a);
  printf("\nbefore swape second value : %d " ,b);
  a=a+b;
  b=a-b;
  a=a-b;
  printf("\nAfter swap First value : %d " ,a);
  printf("\nAfter swap Second value : %d " ,b);
getch();
}

OR

Ans 3(A)

#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("enter the character;");
scanf("%c" ,&ch);
printf("the ASCII_value is :%d" ,ch);
getch();
}

Ans 3(B)

In C programming, a switch statement is used to evaluate an expression against a set of predefined cases. The syntax of the switch statement is as follows:

switch (expression) {
   case constant1:
      // code to be executed if expression is equal to constant1
      break;
   case constant2:
      // code to be executed if expression is equal to constant2
      break;
   .
   .
   .
   default:
      // code to be executed if expression doesn't match any of the constants
}

Here, the expression is evaluated against a set of constants defined by the cases. If the expression matches a particular constant, the code inside that case is executed. If no match is found, the code inside the default case is executed.

The switch statement is often used as an alternative to multiple if-else statements. It can make code more concise and easier to read in situations where there are multiple possible values for a variable.

A flowchart of the switch statement might look something like this :

Ans 3(C)

#include<stdio.h>
#include<conio.h>
void main()
{
	int i,j,n;
	clrscr();
	printf("enter the rows:");
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		for(j=1;j<=i;j++)
		{
			printf("%d",i);
		}
		printf("\n");
	}
	getch();
}

Leave a Comment

Your email address will not be published. Required fields are marked *

error: Content is protected !!
Scroll to Top