PPS GTU Paper Solution Winter 2021 | 310003

Here, We provide Programming For Problem Solving GTU Paper Solution Winter 2021. Read the Full PPS GTU Paper Solution Winter 2021 given below.

PPS GTU Old Paper Winter 2021 [Marks : 70] : Click Here 

Question: 1

(a) Define the following terms:
1) Application Software 2) System Software 3) Algorithm 4) Flowchart.

Application Software: Application software is a type of computer software designed to perform specific tasks for end-users. Examples of application software include word processors, spreadsheets, web browsers, and video games.

System Software: System software is a type of computer software that manages and controls the hardware and other software resources of a computer. Examples of system software include operating systems, device drivers, and utilities.

Algorithm: An algorithm is a set of instructions or steps that are followed in a specific order to solve a problem or perform a specific task. It is a step-by-step procedure for solving a problem or performing a task. 

Flowchart: A flowchart is a diagram that represents a process or workflow. It uses a variety of symbols and shapes to represent different parts of the process, such as inputs, outputs, decisions, and actions. 

(b) Draw the flow chart to find the largest of the given three numbers –
A, B, and C

(c) Explain different types of operators used in c language with their
precedence and associativity.

Question: 2

(a) Discuss the use of break and continue statements in C with examples.

  1. The break statement is used to immediately exit a loop or a switch statement. When a break statement is encountered inside a loop or a switch, the execution of the loop or switch is immediately terminated, and the control is transferred to the statement immediately following the loop or switch.

Example: 

  • for (int i = 0; i < 10; i++) {
  • if (i == 5) {
  •         break;
  •     }
  •     printf(“%d\n”, i);
  • }

In this example, the loop will iterate from 0 to 4 and print the numbers, but when the value of i becomes 5, the break statement will be executed, and the loop will be terminated, so the number 5 will not be printed.

2. The continue statement is used to skip the current iteration of a loop and continue with the next iteration. When a continue statement is encountered inside a loop, the current iteration of the loop is skipped and the control is transferred to the next iteration.

  • int i = 0;
  • while (i < 10) {
  •     i++;
  •     if (i % 2 == 0) {
  •         continue;
  •     }
  •     printf(“%d\n”, i);
  • }

In this example, the loop will iterate from 1 to 10 and print the odd numbers only, because the continue statement will be executed when the value of i is even, so the current iteration will be skipped and the control will be transferred to the next iteration.

(b) Compare and contrast while and do while loop with example.

(c) Write a C program to print the following pattern.
1
2 2
3 3 3

(c) Write a C program to print following pattern.
1
2 3
4 5 6

Question: 3

(a) Write a program to check whether entered character is a vowel or not?

  • #include <stdio.h>
  • int main() {
  •     char ch;
  •     printf(“Enter a character: “);
  •     scanf(“%c”, &ch);
  •     if (ch == ‘a’ || ch == ‘e’ || ch == ‘i’ || ch == ‘o’ || ch == ‘u’ || ch == ‘A’ || ch == ‘E’ || ch == ‘I’ || ch == ‘O’ || ch == ‘U’) {
  •         printf(“The character is a vowel.\n”);
  •     } else {
  •         printf(“The character is not a vowel.\n”);
  •     }
  •     return 0;
  • }

(b) Explain getch(), getchar(), gets(), puts() 

(c) Develop a menu-based program to perform addition, multiplication,
subtraction and division using a user-defined function.

Question: 3

(a) Write an algorithm for finding odd and even numbers from given two numbers.

Here is an algorithm for finding all odd and even numbers between two given numbers:

  1. Begin
  2. Input the first number (let’s call it “start”) and the second number (let’s call it “end”)
  3. Initialize two variables, one for storing odd numbers and another for storing even numbers
  4. Set a loop variable “i” to the value of “start”
  5. While “i” is less than or equal to “end” do the following:

a) Check if “i” is odd or even:

if “i” is odd, add “i” to the list of odd numbers

if “i” is even, add “i” to the list of even numbers

b) increment “i” by 1

  1. Print the list of odd numbers
  2. Print the list of even numbers
  3. End

(b) Write a program to check whether the entered number is prime or not with the help of the user-defined function check-prime().

(c) Write a program to find out the largest of an array.

Question: 4

(a) What is structure? Explain with an example how to declare a structure and how to initialize it.

A Structure is a user-defined data type that groups together different types of data (such as integers, strings, etc.) under a single name. A structure can be used to represent a real-world object, such as a student, where the object has different properties (name, age, etc.).

Here is an example of how to declare a structure in C:

struct student {
    char name[50];
    int age;
    char major[50];
};

You can also initialize the members individually like this:

struct student s1;
strcpy(s1.name, "John Doe");
s1.age = 21;
strcpy(s1.major, "Computer Science");

(b) Explain the following string manipulation function. strcat( ), strcpy( ) ,strcmp( ) and strlen( )

(c) Write a program in c for multiply two matrices A and B of dimensions pXq and qXr respectively and store the result in third matrix C

Question: 4

(a) Demonstrate the declaration and initialization of a two-dimensional array with a suitable example.

Here is an example of declaring and initializing a 2-dimensional array in C:

#include <stdio.h>

int main() {
    // Declare a 2-dimensional array with 3 rows and 4 columns
    int my_array[3][4];

    // Initialize the array with some values
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            my_array[i][j] = i * j;
        }
    }

    // Print the array
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 4; j++) {
            printf("%d ", my_array[i][j]);
        }
        printf("\n");
    }

    return 0;
}

Output:

0 0 0 0 
0 1 2 3 
0 2 4 6 

(b) Explain nested if else ladder with a suitable example.

(c) Write a program in c using structure to enter rollno, marks of the three
subject for 3 student and find total obtained by each student

Question: 5

(a) What do you mean by recursive function? What care must be taken while writing a program with a recursive function?

A recursive function is a function that calls itself in order to solve a problem. It breaks the problem down into smaller and smaller sub-problems until it reaches a point where the problem can be solved without recursion.

Here are a few things to keep in mind when writing a program with a recursive function:

  • Base case: A recursive function must have a base case, which is a condition that stops the recursion. If the base case is not defined, the function will continue to call itself indefinitely, resulting in an infinite loop.
  • Recursive case: The recursive case is the part of the function that calls itself. It must be written in such a way that it will eventually reach the base case.
  • Simplifying the problem: The recursive case must simplify the problem in some way. If the problem is not simplified, the function will not make progress toward the base case.

(b) Explain fopen() and its mode with example. 

(c) Describe different categories of user-defined functions. 

Question: 5

(a) What is a pointer? Explain how pointers are declared and initialized

A pointer is a variable that stores the memory address of another variable. In C, a pointer is a variable that holds the memory address of another variable of a specific data type. 

Pointers allow you to indirectly access and manipulate variables, which can be useful for a variety of tasks, such as dynamic memory allocation and passing variables to functions.

int x = 10;
int *ptr;   // declare a pointer to an integer
ptr = &x;   // initialize the pointer with the address of variable x

You can also declare and initialize pointer in single line like this:

int x = 10;
int *ptr = &x;

You can also use the malloc() function to dynamically allocate memory for a pointer and assign its address to the pointer. Here is an example:

int *ptr = (int *) malloc(sizeof(int));

(b) Compare malloc() and calloc() functions for dynamic memory
allocation.

(c) Develop a program in C to check whether the entered number is prime or not by creating a user-defined function named check_prime().

Read More : PPS GTU Paper Solution Summer 2022
Read More : BEE GTU Paper Solution Winter 2021

“Do you have the answer to any of the questions provided on our website? If so, please let us know by providing the question number and your answer in the space provided below. We appreciate your contributions to helping other students succeed.