You are on page 1of 32

Solution to Model Question Paper_set_1

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.1 a)

Fig. Block diagram of a Computer


The basic organization of a computer involves the following components:
Central Processing Unit (CPU): This is the "brain" of the computer and is responsible for
processing and executing instructions. It consists of the control unit, arithmetic and logic unit
(ALU), and registers.
Memory (RAM): This is the primary form of storage in a computer and is used to temporarily
store data and instructions that the CPU needs to access quickly.
Input/output (I/O) devices: These are devices that allow the user to interact with the computer
and provide a means for data to enter and leave the system. Examples of I/O devices include
keyboards, mice, displays, and storage devices such as hard drives and flash drives.
Bus: This is a communication pathway that allows data to be transferred between the CPU,
memory, and I/O devices.
Operating System: This is a software program that manages the resources of the computer and
provides a user interface for the user to interact with the computer.
Overall, the CPU, memory, and I/O devices work together to allow the computer to execute
instructions, store and retrieve data, and interact with the user.

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.1 b)
The major parts of a computer and their functions are as follows:
Central Processing Unit (CPU): This is the brain of the computer and is responsible for
processing instructions. It consists of two main components: the control unit, which manages the
flow of data within the CPU, and the arithmetic and logic unit (ALU), which performs
calculations and logical operations.
Memory (RAM): This is the primary form of storage in a computer and is used to temporarily
store data and instructions that the CPU needs to access quickly.
Hard Disk Drive (HDD) or Solid State Drive (SSD): These are non-volatile storage devices that
are used to store data and programs permanently. An HDD uses spinning disks to store data
magnetically, while an SSD uses flash memory.
Input Devices: These are devices that allow the user to input data into the computer.
Ex: keyboards, mice, scanners, and microphones.

Output Devices: These are devices that allow the computer to display or output data to the user.
Ex: monitors, printers, and speakers.

Motherboard: This is the main circuit board that connects all the components of the computer
together.
Graphics Processing Unit (GPU): This is a specialized processor that is designed to handle
graphics and video processing.
Optical Drive: This is a device that reads and writes data to optical discs such as CDs, DVDs,
and Blu-ray discs.

Q.1 c)
In C programming language, there are several basic data types which are used to define
variables. These data types can be categorized into four categories:
 Basic data types
 Enumeration data types
 Derived data types
 Void data type
Following is a list of basic data types in C, along with their size in bytes and range of values:
 char: 1 byte
 int: 2 or 4 bytes
 float: 4 bytes
 double: 8 bytes

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

 short: 2 bytes
 long: 4 or 8 bytes
Identifiers are the names of variables, functions, and other user-defined items in a program. The
size of an identifier in C depends on the implementation. In most modern implementations, the
maximum length of an identifier is 31 characters. However, it is recommended to keep the length
of identifiers short and descriptive for better code readability.
Q.2 a)

Fig. SDLC Life cycle

The Software Development Life Cycle (SDLC) is a process used by software development teams
to design, develop, and maintain software. It consists of several phases that are typically
followed in a sequential order.
Following are the different phases in the SDLC:
Planning: This is the first phase of the SDLC, where the project team defines the scope of the
project, identifies the requirements of the software, and sets the project objectives.
Analysis: In this phase, the project team analyzes the requirements gathered in the planning
phase and develops a detailed understanding of the problem the software is meant to solve.
Design: The design phase involves creating a detailed design specification for the software that
includes data structures, algorithms, and user interface design.
Implementation: In this phase, the project team starts to develop the actual software using the
design specifications created in the previous phase.
Testing: This phase involves testing the software to ensure that it meets the requirements and is
free of bugs and errors.

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Deployment: This phase involves releasing the software to users, either internally or externally.
The software is installed and configured on the user's system, and user training is provided.
Maintenance: The maintenance phase involves updating the software to fix bugs, improve
performance, and add new features. This phase may also involve retiring the software when it is
no longer needed.
Q.2 b)
Input devices are essential hardware components that are used to feed data into a computer
system. Following are the different types of input devices:
 Keyboard
 Mouse
 Joystick
 Scanner
 Webcam
 Microphone
 Touchpad
 Trackball
 Gamepad
 Digital camera

Keyboard: The keyboard is the most commonly used input device. It is used to type text and
commands into a computer system.
Mouse: The mouse is another common input device used to move a cursor on the screen and
perform functions such as selecting text, clicking on icons, and opening files.
Joystick: A joystick is an input device used in gaming and simulation applications. It is typically
used to control the movement of objects, such as airplanes or cars, in a game or simulation.
Scanner: A scanner is an input device used to scan documents, photographs, or images and
convert them into digital files that can be stored on a computer.
Webcam: A webcam is a video camera used for capturing video and audio. It is commonly used
for video conferencing, live streaming, and recording video content.
Microphone: A microphone is an input device used to capture audio. It is commonly used for
recording audio content, voice recognition, and communication applications.
Touchpad: A touchpad is a flat surface that is used to control the cursor on a laptop or other
portable device.

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Trackball: A trackball is a stationary input device that is used to move the cursor on a computer
screen.
Digital camera: A digital camera is an input device used for capturing images and videos.

Q.2 c)
Input and output statements are fundamental components of any programming language. They
allow programs to interact with users and the outside world by reading input and displaying
output. In C programming language, the standard library provides several functions to perform
input and output operations.
Following are the different input and output statements in C with appropriate syntax:
1. printf(): The printf() function is used to print output to the console or standard output. It takes
a formatted string as input, and the format specifier placeholders within the string indicate where
the values should be inserted.
Syntax:
printf("format string",argument_list);
Ex: printf("%d", 42);

2. scanf(): The scanf() function is used to read input from the console or standard input. It takes a
format string as input and a list of variables to store the input.
Syntax:
scanf(format, arg1, arg2, ...);
Ex:
int num;
scanf("%d", &num);

3. getchar(): The getchar() function is used to read a single character from the console or
standard input.
Syntax:
int getchar(void);
Ex: int c = getchar();
printf("The ASCII code of the character is %d\n", c);

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

4. putchar(): The putchar() function is used to print a single character to the console or standard
output.
Syntax:
int putchar(int c);
Ex: putchar('A');
5. gets(): The gets() function is used to read a string of characters from the console or standard
input.
Syntax:
char *gets(char *str);
Ex: char str[100];
gets(str);
printf("You entered: %s\n", str);
6. puts(): The puts() function is used to print a string of characters to the console or standard
output.
Syntax:
int puts(const char *str);
Ex:
char *str = "Hello, world!";
puts(str);

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.3 a)
In C, there are three logical operators:
 && (logical AND),
 || (logical OR), and
 ! (logical NOT).
These operators are used to perform logical operations on boolean expressions. (expressions that
evaluate to either true or false).
&& (logical AND): This operator returns true if and only if both of its operands are true.
Otherwise, it returns false.
Ex:
int x = 5;
int y = 3;
if (x > 0 && y > 0)
{
printf("Both x and y are positive.\n");
}
|| (logical OR): This operator returns true if at least one of its operands is true. Otherwise, it
returns false.
Ex:
int x = 5;
int y = -3;
if (x > 0 || y > 0)
{
printf("At least one of x and y is positive.\n");
}
! (logical NOT): This operator returns the opposite of its operand. If the operand is true, it
returns false. If the operand is false, it returns true.
Ex:
int x = 5;
if (!(x == 3))
{
printf("x is not equal to 3.\n");
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.3 b)
In C, an if statement is used to execute a block of code only if a specified condition is true. The
syntax of an if statement is as follows:
if (condition)
{
// Code to execute if condition is true
}
The condition is a boolean expression that is evaluated to either true or false. If the condition is
true, then the code inside the curly braces is executed. If the condition is false, then the code
inside the curly braces is skipped.
Ex:
int x = 5;
if (x > 0)
{
printf("x is positive.\n");
}
Q.3 c)
#include <stdio.h>
#include <math.h>

int main()
{
float m, v, h, E;
printf("Enter the mass of the particle (in kg): ");
scanf("%f", &m);

printf("Enter the velocity of the particle (in m/s): ");


scanf("%f", &v);
printf("Enter the height of the particle (in m): ");
scanf("%f", &h);

E = m * 9.8 * h + 0.5 * m * pow(v, 2);


printf("The mechanical energy of the particle is %.2f J\n", E);

return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.4 a)
In C, a switch statement is used to execute different blocks of code depending on the value of a
variable or expression.
The syntax of a switch statement is as follows:
switch (expression)
{
case value1:
// Code to execute if expression == value1
break;
case value2:
// Code to execute if expression == value2
break;
// ...
default:
// Code to execute if expression doesn't match any of the cases
}
The expression is the variable or expression whose value will be tested against each case value.
The case labels specify the different values that the expression might take, and the code to
execute if the expression is equal to each value is enclosed in the corresponding block of code.

The break statement is used to exit the switch statement once a matching case has been found.
Without the break statement, the code would continue to execute through all of the subsequent
case blocks until the end of the switch statement or until another break statement is encountered.
Ex:
int day = 3;
switch (day) {
case 1:
printf("Monday\n");
break;
case 2:
printf("Tuesday\n");

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

break;
case 3:
printf("Wednesday\n");
break;
case 4:
printf("Thursday\n");
break;
case 5:
printf("Friday\n");
break;
default:
printf("Invalid day\n");
}
Q.4 b)
In C, do-while and while loops are used to execute a block of code repeatedly based on a specific
condition. However, there are some differences between the two.
The main difference between do-while and while loop is that the do-while loop executes the
block of code at least once, even if the condition is initially false, whereas the while loop may
not execute the block of code at all if the condition is initially false.
Ex:
// do-while loop example
int i = 0;
do {
printf("%d ", i);
i++;
} while (i < 5);

// while loop example


int j = 0;
while (j < 5) {
printf("%d ", j);
j++;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.4 c)

#include<stdio.h>
#include<stdlib.h>
int main()
{
char c;
printf("\nEnter a character to be checked : ");
scanf("%c", &c);
if(c >= 'a' && c <= 'z')
{
printf("\nThe character entered is a lower case character\n");
}
else if(c >= 'A' && c <= 'Z')
{
printf("\nThe character entered is a upper case character\n");
}
else if(c >= '0' && c <= '9')
{
printf("\nThe character entered is a digit\n");
}
else
{
printf("\nThe character entered is a special character\n");
}
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.5 a)
In C, an array is a collection of elements of the same type that are stored in a contiguous memory
location. Initializing an array means assigning an initial value to each of its elements.

There are several ways to initialize an array in C:


1. Initialize all elements at the time of declaration:
int arr[5] = { 10, 20, 30, 40, 50 };
2. Initialize only some of the elements at the time of declaration:
int arr[5] = { 10, 20 };
3. Initialize all elements to a default value:
int arr[5] = { 0 };
4. Initialize an array using a loop:
int arr[5];
for (int i = 0; i < 5; i++) {
arr[i] = i * 10;
}
Q.5 b)
In C, there are mainly three ways of passing parameters to a function:
Call by value: In this method, a copy of the value of the actual argument is passed to the function
parameter. Any changes made to the function parameter do not affect the value of the actual
argument. This method is suitable for simple data types, such as int, float, char, etc.
void add(int a, int b) {
int sum = a + b;
printf("Sum = %d\n", sum);
}

int main() {
int x = 10, y = 20;
add(x, y); // pass by value
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Call by reference using pointers: In this method, the address of the actual argument is passed to
the function parameter using a pointer. The function parameter now refers to the same memory
location as the actual argument, and any changes made to the function parameter will affect the
value of the actual argument.
void swap(int *a, int *b) {
int temp = *a;
*a = *b;
*b = temp;
}

int main() {
int x = 10, y = 20;
swap(&x, &y); // pass by reference using pointers
printf("x = %d, y = %d", x, y);
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.5 c)
#include<stdio.h>
#include<stdlib.h>
int main(void)
{
int Num, i, j, Arr[10], Temp;
printf("\n*\tPROGRAM TO IMPLEMENT BUBBLE SORT\t*\n");
printf("\nEnter no of elements\n");
scanf("%d",&Num);
printf("\nEnter the elements\n");
for(i=0;i<Num;i++)
scanf("%d",&Arr[i]);
for(i=0;i<Num;i++)
{
for(j=0;j<Num-i-1;j++)
{
if(Arr[j] > Arr[j+1])
{
Temp = Arr[j];
Arr[j] = Arr[j+1];
Arr[j+1] = Temp;
}
}
}
printf("\nThe Sorted array is \n");
for(i=0;i<Num;i++)
printf("%d\t",Arr[i]);
printf("\n");
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.6 a)
In C programming, storage class specifiers are used to determine the storage location and
duration of variables. There are four storage class specifiers in C: auto, register, static, and
extern.
Auto storage class specifier:
This is the default storage class specifier used in C. Variables declared with the auto specifier are
allocated memory on the stack, and their lifetime is limited to the scope in which they are
declared. The keyword "auto" is rarely used in modern C code, as it is implicit.
Register storage class specifier:
Variables declared with the register specifier are stored in the CPU's register, if available, for
faster access. The register keyword is a hint to the compiler, and it is not guaranteed that the
variable will be stored in a register.
Static storage class specifier:
The static keyword is used to declare variables that retain their values even after the scope in
which they were declared has ended. Variables declared with the static specifier are allocated
memory in the data segment of the program rather than the stack. Static variables can be
accessed within the file where they are declared.
Extern storage class specifier:
The extern keyword is used to declare a variable that is defined in another file. The variable's
memory allocation happens in the file where it is defined, and the extern keyword is used to
access that variable from other files.

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.6 b)
In C programming, an array is a collection of elements of the same data type, which are stored in
contiguous memory locations. To pass the value of individual array elements into a function, we
can use the array subscript operator [ ] and pass the array element's value by its index.

Following is an example that demonstrates how to pass an individual array element's value to a
function:
#include <stdio.h>
// function prototype
void printArrayElement(int);
int main() {
int arr[5] = {1, 2, 3, 4, 5};
// passing the value of 3rd element of the array to the function
printArrayElement(arr[2]);
return 0;
}
// function definition
void printArrayElement(int element) {
printf("The value of the array element is: %d\n", element);
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.6 c)
#include <stdio.h>
// Function to multiply two numbers
int multiply(int a, int b)
{
return a * b;
}
int main() {
int num1, num2, product;
printf("Enter the first number: ");
scanf("%d", &num1);
printf("Enter the second number: ");
scanf("%d", &num2);
// Call the multiply function and store the result
product = multiply(num1, num2);
printf("The product of %d and %d is %d\n", num1, num2, product);
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.7 a)
#include <stdio.h>
// Function to calculate factorial of a number
int factorial(int num) {
int fact = 1;
for(int i = 1; i <= num; i++) {
fact *= i;
}
return fact;
}
int main() {
int rows;
printf("Enter the number of rows: ");
scanf("%d", &rows);
// Generate Pascal's triangle
for(int i = 0; i < rows; i++) {
for(int j = 0; j <= i; j++) {
int coef = factorial(i) / (factorial(j) * factorial(i - j));
printf("%d ", coef);
}
printf("\n");
}
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.7 b)
In memory, a 2D array is represented as a contiguous block of memory, with each row of the
array stored one after the other. The elements within each row are stored in sequential order, with
the first element of each row located adjacent to the last element of the previous row.

Let's take an example of a 2D integer array with 3 rows and 4 columns, declared and initialized
as follows:
int arr[3][4] = {
{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}
};

This 2D array consists of 3 rows and 4 columns, where the first row contains the values 1, 2, 3,
4, the second row contains the values 5, 6, 7, 8, and the third row contains the values 9, 10, 11,
12.

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.7 c)
#include <stdio.h>

int main() {
int arr[2][2][2];
// Read values into the array
printf("Enter 8 integer values to fill the 2 x 2 x 2 array:\n");
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
for(int k = 0; k < 2; k++) {
scanf("%d", &arr[i][j][k]);
}
}
}
// Display the values in the array
printf("\nThe 2 x 2 x 2 array:\n");
for(int i = 0; i < 2; i++) {
for(int j = 0; j < 2; j++) {
for(int k = 0; k < 2; k++) {
printf("%d ", arr[i][j][k]);
}
printf("\n");
}
printf("\n");
}
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.8 a)
#include <stdio.h>

int main() {
int matrix[3][3], transpose[3][3];

// Read values into the matrix


printf("Enter the 3 x 3 matrix:\n");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
scanf("%d", &matrix[i][j]);
}
}
// Transpose the matrix
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
transpose[j][i] = matrix[i][j];
}
}
// Display the transposed matrix
printf("\nThe transposed matrix:\n");
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 3; j++) {
printf("%d ", transpose[i][j]);
}
printf("\n");
}
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.8 b)
In C programming language, a single row of a 2D array can be passed to a function by declaring
the formal parameter of the function as a pointer to the data type of the row. This means that the
function will receive a pointer to the first element of the row. The pointer can then be treated as a
1D array with the same number of columns as the original 2D array.
Ex:
#include <stdio.h>

// Function to print a single row of a 2D array


void print_row(int *arr, int cols) {
for(int i = 0; i < cols; i++) {
printf("%d ", *(arr + i));
}
printf("\n");
}
int main() {
int arr[3][4] = {{1, 2, 3, 4},
{5, 6, 7, 8},
{9, 10, 11, 12}};
// Pass the first row of the array to the print_row function
print_row(&arr[0][0], 4);
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.8 c)
#include<stdio.h>
#define N 50
int main()
{
int a[N][N],b[N][N],c[N][N],i,j,k,m,n,p,q,sum=0;
printf("Enter the order of 1st matrix:\n");
scanf("%d%d",&m,&n);
printf("Enter the 1st matrix elements:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("The 1st matrix elements:\n");
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
printf("%d\t",a[i][j]);
}
printf("\n");
}
printf("Enter the order of 2nd matrix:\n");
scanf("%d%d",&p,&q);
printf("Enter the 2nd matrix elements:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("The 2nd matrix elements:\n");
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
{
printf("%d\t",b[i][j]);
}
printf("\n");
}
if(n!=p)

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

{
printf("\nMultiplication is not possible!!!\n");
}
else
{
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
sum=0;
for(k=0;k<m;k++)
{

sum=sum+(a[i][k]*b[k][j]);
}
c[i][j]=sum;

}
}
printf("\nMultiplication result is :\n");
{
for(i=0;i<m;i++)
{
for(j=0;j<q;j++)
{
printf("\n%d\t",c[i][j]);
}
printf("\n");
}
}
}
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.9 a)
Arrays
Arrays are used to store a collection of elements of the same data type in a contiguous block of
memory. The elements of an array can be accessed using an index, which is an integer value that
specifies the position of the element in the array. Arrays can be used to store data of primitive
data types or composite data types.
Ex:
int arr[5] = {1, 2, 3, 4, 5};

Structure:
Structs, on the other hand, are used to store a collection of related data items of different data
types. Structs allow you to group related data items into a single unit, making it easier to manage
and manipulate the data. The individual data items within a struct are referred to as members or
fields, and they can be of different data types. Structs can be used to create complex data types
that represent real-world entities.
Ex:
struct person {
char name[50];
int age;
float height;
};

struct person p1 = {"Alice", 25, 1.68};

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.9 b)
#include<stdio.h>
#include<stdlib.h>
#define STRSIZE 30

typedef struct
{
char Name[STRSIZE];
char USN[11];
int Marks;
}STUDENT_TYPE;

int main(void)
{
STUDENT_TYPE students[100];
int Num, i;
double dAvg = 0.0;
printf("\nEnter the number of students : ");
scanf("%d", &Num);

printf("\nEnter the Student details\n");


for(i=0;i<Num;i++)
{
printf("\nName : ");
scanf("%s", students[i].Name);
printf("\nUSN : ");
scanf("%s", students[i].USN);
printf("\nMarks : ");
scanf("%d", &students[i].Marks);
dAvg += students[i].Marks;
}
dAvg /= Num;
printf("\nThe average marks for the class is : %g\n", dAvg);
for(i=0;i<Num;i++)
{
printf("\nName\t: %s", students[i].Name);
printf("\nUSN\t: %s", students[i].USN);
printf("\nMarks\t: %d", students[i].Marks);
if(students[i].iMarks < dAvg)
printf("\nThe student has scored below average\n");
else
printf("\nThe student has scored above average\n");
}
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.9 c)
#include <stdio.h>
#include <ctype.h>

#define MAX_LEN 100

int main() {
char sentence[MAX_LEN];
int word_count = 0;

printf("Enter a sentence: ");


fgets(sentence, MAX_LEN, stdin);

// Iterate over the sentence and count the number of words


for(int i = 0; sentence[i] != '\0'; i++) {

if(isspace(sentence[i])) {
word_count++;
}
}

word_count++;

printf("The sentence contains %d words.\n", word_count);

return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.10 a)

In C programming language, the members of a structure can be accessed using the dot (.)
operator. The dot operator is used to access the individual members of the structure.

Ex:
#include <stdio.h>

struct student {
char name[50];
int roll_no;
float marks;
};

int main() {
struct student s1 = {"John", 101, 85.5};

// Accessing structure members using dot operator


printf("Name: %s\n", s1.name);
printf("Roll Number: %d\n", s1.roll_no);
printf("Marks: %f\n", s1.marks);

return 0;

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.10 b)
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
int main(void)
{
int i,Num;
float fMean = 0.0f, fVariance = 0.0f, fSd = 0.0f,faArray[100],fSum=0.0f;

float *fptr;

printf("\nEnter the number of Values : ");


scanf("%d",&Num);
fptr = faArray;

printf("\nEnter %d values\n", Num);


for(i=0; i<Num; i++)
{
scanf("%f",fptr+i);
fSum += *(fptr+i); //fSum += fptr[i]; this is also valid
}
fMean = fSum/Num;

for(i=0; i<Num; i++)


{
fVariance += (fptr[i] - fMean)*(fptr[i] - fMean);
}
fVariance /= Num;
fSd = sqrt(fVariance);
printf("\nThe values entered are");
for(i=0; i<Num; i++)
{
printf("\t%g",fptr[i]);
}
printf("\n");
printf("\tSum\t = \t%g\n\tMean\t = \t%g\n\tVariance = \t%g\nStandard
Deviation =\t%g",fSum,fMean,fVariance,fSd);
return 0;
}

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki
Solution to Model Question Paper_set_1

Q.10 c)

#include <stdio.h>

void swap(int *a, int *b);

int main() {
int num1, num2;

printf("Enter two integer values: ");


scanf("%d %d", &num1, &num2);

printf("Before swapping: num1 = %d, num2 = %d\n", num1, num2);

// Call the swap function to swap the values


swap(&num1, &num2);

printf("After swapping: num1 = %d, num2 = %d\n", num1, num2);

return 0;
}

void swap(int *a, int *b) {


int temp;

temp = *a;
*a = *b;
*b = temp;
}

***********END***********

Prepared By: Prof. Allamaprabhu & Prof. Bhimrao Patil, Dept. of AIML and CSE, BKIT Bhalki

You might also like