MATHEMATICS: Mathematical Programming in C | FYUG 2025
UNIT-I: C Fundamentals
Question 1 (a)
Question: Write the syntax for variable declaration in C.
Solution:
data_type variable_name;
Example: int count; or float price;
Question 1 (b)
Question: Write the syntax to define a symbolic constant.
Solution:
#define CONSTANT_NAME value
Example: #define PI 3.14159
Question 1 (c)
Question: How will you write the arithmetic expression a² + 10a - 8 in C?
Solution:
a * a + 10 * a - 8;
Alternatively, using the math library: pow(a, 2) + 10 * a - 8;
Question 1 (d)
Question: How will you assign the value 100 to the variable x at the time of variable declaration?
Solution:
int x = 100;
Question 2 (a)
Question: Which of the following are valid variable names: Char, First_name, List one, 2int_type?
Solution:
- Char: Valid (C is case-sensitive;
charis a keyword, butCharis not). - First_name: Valid (contains letters and underscores).
- List one: Invalid (contains a space).
- 2int_type: Invalid (cannot start with a digit).
Question 3 (a)
Question: Write the rules for naming identifiers.
Solution:
- An identifier can only contain alphabets (uppercase and lowercase), digits, and underscores (
_). - The first character must be an alphabet or an underscore. It cannot be a digit.
- Keywords (like
int,while, etc.) cannot be used as identifiers. - Identifiers are case-sensitive (e.g.,
Totalandtotalare different). - No special characters or spaces are allowed except for the underscore.
UNIT-II: Operators and Control Flow
Question 4 (a)
Question: What are the relational operators in C?
Solution:
Relational operators are used to compare two values. They are:
==(Equal to)!=(Not equal to)>(Greater than)<(Less than)>=(Greater than or equal to)<=(Less than or equal to)
Question 5 (a)
Question: What is the error in: int x=10; float y=4.25; x=y%x;?
Solution:
The error lies in the expression x = y % x;.
Error: The modulo operator (%) can only be used with integer operands. Sinceyis afloat, this operation is illegal in C.
Question 6 (a)
Question: Write a C program to read two integers m and n and to decide and print whether m is a multiple of n.
Solution:
#includeint main() { int m, n; printf("Enter two integers (m and n): "); scanf("%d %d", &m, &n); if (n != 0 && m % n == 0) { printf("%d is a multiple of %d\n", m, n); } else { printf("%d is not a multiple of %d\n", m, n); } return 0; }
UNIT-III: Loops and Logic
Question 7 (a)
Question: Write the general syntax of for loop.
[span_30](end_span)Solution:
for (initialization; condition; increment/decrement) { // Statements to be executed } Question 9 (a)
Question: Write the rules for switch statement.
[span_32](end_span)Solution:
- The
switchexpression must be an integral type (int or char). - Each
caselabel must be a unique constant expression. - The
breakstatement is optional but used to exit the switch block; otherwise, execution "falls through" to the next case. - The
defaultcase is optional and executes if no case matches. - Case labels must end with a colon (
:).
UNIT-IV: Functions and Recursion
Question 10 (a)
Question: Every program must have a ______ function.
[span_39](end_span)Solution:
main
Question 11 (b)
Question: What is recursion?
[span_41](end_span)Solution:
Recursion is a programming technique where a function calls itself, either directly or indirectly, to solve a problem.
It must have a base case to terminate the calls.Question 12 (a)
Question: Write a C program to compute the sum of first n natural numbers using function.
[span_45](end_span)Solution:
#includeint findSum(int n) { return (n * (n + 1)) / 2; } int main() { int n; printf("Enter a positive integer: "); scanf("%d", &n); printf("Sum of first %d natural numbers is %d\n", n, findSum(n)); return 0; }
UNIT-V: Arrays
Question 13 (a)
Question: Write the syntax for declaring a two-dimensional array.
Solution:
data_type array_name[row_size][column_size];
Example: int matrix[3][3];
Question 13 (c)
Question: What is the first subscript of one-dimensional array in C?
Solution:
0
Question 15 (a)
Question: Write a program to find the largest element in an integer array.
Solution:
#includeint main() { int arr[100], n, i, max; printf("Enter number of elements: "); scanf("%d", &n); printf("Enter %d elements:\n", n); for(i = 0; i < n; i++) { scanf("%d", &arr[i]); } max = arr[0]; for(i = 1; i < n; i++) { if(arr[i] > max) { max = arr[i]; } } printf("Largest element = %d\n", max); return 0; }
Exam Focus Enhancements
Exam Tips
- When writing programs, always include
#include <stdio.h>and basic indentation for full marks. - For short syntax questions, always provide an example.
Common Mistakes
- Confusing
=(assignment) with==(equality) inifconditions. - Forgetting that array indices start at 0, not 1.
Important Formulas List
- Sum of n natural numbers: n(n+1)/2
- Condition for multiple:
m % n == 0