0% found this document useful (0 votes)
17 views5 pages

1 IA Scheme

The document outlines the first internal assessment for the Principles of Programming using C course, detailing the structure of the assessment, including questions on identifiers, computer characteristics, C program structure, constants, variables, data types, operators, arrays, and control flow statements. Each question includes a solution and a marking scheme, with a total of 50 marks available. The assessment is scheduled for November 26, 2024, and is part of the academic year 2024-25 for the odd semester.

Uploaded by

apoorva dv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

1 IA Scheme

The document outlines the first internal assessment for the Principles of Programming using C course, detailing the structure of the assessment, including questions on identifiers, computer characteristics, C program structure, constants, variables, data types, operators, arrays, and control flow statements. Each question includes a solution and a marking scheme, with a total of 50 marks available. The assessment is scheduled for November 26, 2024, and is part of the academic year 2024-25 for the odd semester.

Uploaded by

apoorva dv
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 5

FIRST INTERNAL ASSESSMENT

Semester I Section: A/B/C/D/E


Subject Principles of Programming using C Subject Code BPOPS103
Date 26-11-2024 Time 09-10.30am
AY 2024-25(Odd Semester) Max. Marks 50

Solution and Scheme 5 X 8 = 40


Q.No. Solution Marks
1 Identifiers are names used in programming to identify variables, functions, arrays, -2-
etc. They are the labels given to elements in a program.

Rules for forming identifier names: -4-

1. An identifier must start with a letter (a-z, A-Z) or an underscore (_).


2. The rest of the identifier name can consist of letters, digits (0-9), or under-
scores.
3. Identifiers cannot be C keywords or reserved words (e.g., int, if, while).
4. Identifiers are case-sensitive (i.e., variable and Variable are different).
5. They cannot contain spaces or special characters like @, #, $.

Valid and Invalid identifiers:


-4-
 a. gmit — Valid. It starts with a letter and contains only letters.
 b. 1_cse — Invalid. It starts with a digit (identifiers cannot start with a
digit).
 c. continue — Invalid. continue is a reserved keyword in C.

 d. Pop lab — Invalid. It contains a space, which is not allowed in identi-


fiers.
2. A computer is an electronic device that can process, store, and retrieve data. It fol- -3-
lows instructions to perform a wide range of tasks, such as calculations, data analy-
sis, and interaction with other systems.

Characteristics of computers:

1. Speed: Computers can process millions of instructions per second, perform- -7-
ing tasks far faster than humans.
2. Accuracy: Computers provide precise results without errors (unless caused
by hardware or software malfunctions).
3. Automation: Once programmed, computers can perform tasks without hu-
man intervention.
4. Storage: Computers can store vast amounts of data, which can be retrieved
quickly and accurately.
5. Versatility: Computers can perform a wide variety of tasks and adapt to dif-
ferent applications.

6. Diligence: Unlike humans, computers don't tire and can work 24/7 without
loss of performance.
3. A basic C program structure includes the following parts: -6-
1. Preprocessor directives: These are lines of code that are processed before
the actual compilation (e.g., #include).
2. Global declaration section: Variables or functions declared outside of any
function.
3. Main function: Every C program must have a main() function, which is the
entry point of the program.
4. Local declaration section: Variables specific to a function are declared
here.
5. Statements/Expressions: These are the operations that the program will ex-
ecute.
6. Return statement: Ends the program and returns a value to the operating
system.

Example program:

c
Copy -4-
#include <stdio.h>

int main() {
// Local variables
int a, b, sum;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
sum = a + b;
printf("Sum: %d\n", sum);
return 0;
}

4. i. Constants ii. Variables iii. Datatypes

Answer: -3-

 i. Constants: Constants are fixed values that do not change during program
execution.
o Example: const int MAX = 100;
 ii. Variables: Variables are identifiers used to store data that can change -3-
during execution.
o Example: int age = 25;
 iii. Datatypes: Datatypes define the type of data that a variable can hold.
-4-
o Example:
 int: for integers (e.g., 5, -3)
 float: for decimal numbers (e.g., 3.14, -2.5)
 char: for characters (e.g., 'a', 'Z')

5 Here is a simple calculator program in C: -10-


c
Copy
#include <stdio.h>

int main() {
int num1, num2, result;
char operator;

printf("Enter first number: ");


scanf("%d", &num1);
printf("Enter operator (+, -, *, /): ");
scanf(" %c", &operator);
printf("Enter second number: ");
scanf("%d", &num2);

switch (operator) {
case '+': result = num1 + num2; break;
case '-': result = num1 - num2; break;
case '*': result = num1 * num2; break;
case '/': result = num1 / num2; break;
default: printf("Invalid operator\n"); return 1;
}

printf("Result: %d\n", result);


return 0;
}
 Complete C program (7 marks)
 Explanation of the code (3 marks)
6 #include <stdio.h> -5-

int main() {
int num1, num2, sum;
printf("Enter first number: ");
scanf("%d", &num1);
printf("Enter second number: ");
scanf("%d", &num2);

sum = num1 + num2;

printf("Sum: %d\n", sum);


return 0;
}

Algorithm:

1. Start -3-
2. Input two numbers (num1, num2).
3. Add the numbers and store the result in sum.
4. Output the sum.
5. End

Flowchart:
-2-
bash
Copy
Start
|
Input num1, num2
|
sum = num1 + num2
|
Output sum
|
End

7  Arithmetic Operators: Used to perform basic mathematical operations. -5-


 + (Addition): Adds two values.
 - (Subtraction): Subtracts the second value from the first.
 * (Multiplication): Multiplies two values.
 / (Division): Divides the first value by the second.
 % (Modulus): Finds the remainder after division.

Example:

c -5-
Copy
int a = 5, b = 3;
printf("%d", a + b); // Output: 8

 Relational Operators: Used to compare two values.

 ==: Equal to
 !=: Not equal to
 >: Greater than
 <: Less than
 >=: Greater than or equal to
 <=: Less than or equal to

Example:

c
Copy
int a = 5, b = 3;
printf("%d", a > b); // Output: 1 (true)

8 One-Dimensional Array: An array that stores elements of the same type in a sin- -3-
gle row (i.e., a linear list of elements).

C Program:

c
Copy -7-
#include <stdio.h>

int main() {
int n, i;
float sum = 0, average;

printf("Enter the number of elements: ");


scanf("%d", &n);

int arr[n]; // Declare an array of size 'n'

printf("Enter the elements:\n");


for(i = 0; i < n; i++) {
scanf("%d", &arr[i]);
sum += arr[i]; // Add the element to sum
}

average = sum / n; // Calculate average

printf("Sum: %.2f\n", sum);


printf("Average: %.2f\n", average);

return 0;
}

9  i. simple if: Executes a block of code if the condition is true. -5-


c
Copy
if (a > b) {
printf("a is greater than b");
}

 ii. if else: Executes one block of code if the condition is true, and another block
if it is false.

c -5-
Copy
if (a > b) {
printf("a is greater than b");
} else {
printf("b is greater than a");
}
10  i. do-while: A loop that guarantees the body will run at least once before check- -5-
ing the condition.
do {
printf("Hello\n");
} while (condition);

 ii. for: A loop used when the number of iterations is known beforehand.

c
Copy
for (int i = 0; i < 5; i++) {
printf("%d\n", i); -5-
}

You might also like