Question: Write the syntax for variable declaration in C.
Solution:
data_type variable_name;
Example: int count; or float price;
Question: Write the syntax to define a symbolic constant.
Solution:
#define CONSTANT_NAME value
Example: #define PI 3.14159
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: How will you assign the value 100 to the variable x at the time of variable declaration?
Solution:
int x = 100;
Question: Which of the following are valid variable names: Char, First_name, List one, 2int_type?
Solution:
char is a keyword, but Char is not).Question: Write the rules for naming identifiers.
Solution:
_).int, while, etc.) cannot be used as identifiers.Total and total are different).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: 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: 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; }
Question: Write the general syntax of for loop.
[span_30](end_span)Solution:
for (initialization; condition; increment/decrement) {
// Statements to be executed
}
Question: Write the rules for switch statement.
[span_32](end_span)Solution:
switch expression must be an integral type (int or char).case label must be a unique constant expression.break statement is optional but used to exit the switch block; otherwise, execution "falls through" to the next case.default case is optional and executes if no case matches.:).Question: Every program must have a ______ function.
[span_39](end_span)Solution:
main
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: 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; }
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: What is the first subscript of one-dimensional array in C?
Solution:
0
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; }
#include <stdio.h> and basic indentation for full marks.= (assignment) with == (equality) in if conditions.m % n == 0Would you like me to create a flowchart for the "Largest element in an array" program or explain any of the logical operators in more detail?