0% found this document useful (0 votes)
34 views8 pages

RHS-FPL Prelim Exam

The document outlines an examination paper for the Fundamentals of Programming Languages course, covering various topics related to the C programming language. It includes questions on program design tools, operators, control statements, arrays, functions, and structures, along with sample code for practical programming tasks. The exam consists of multiple-choice questions where students must attempt specific pairs of questions within a 2.5-hour duration for a total of 70 marks.

Uploaded by

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

RHS-FPL Prelim Exam

The document outlines an examination paper for the Fundamentals of Programming Languages course, covering various topics related to the C programming language. It includes questions on program design tools, operators, control statements, arrays, functions, and structures, along with sample code for practical programming tasks. The exam consists of multiple-choice questions where students must attempt specific pairs of questions within a 2.5-hour duration for a total of 70 marks.

Uploaded by

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

Subject : [ ESC_105_COMP_Th ] Fundamentals of Programming Languages

Year : FIRST YEAR - Sem-I FE Marks : 70 Date : December, 2024


ATTEMPT Q1 or Q2, Q3 or Q4, Q5 or Q6, Q7 or Q8, Q9 or Q10 Duration : 2 ½ hours

Q1.A Explain the importance of program design tools like algorithms and flowcharts. [5]
B Write an algorithm and draw a flowchart to calculate the factorial of a number [5]
C What are C tokens? List and explain different types of C tokens with examples. [4]

OR
Q2. A Discuss the history and importance of the C programming language. [5]
B Define Symbolic Constants, declaring a Variable as Constant [5]
C What is the difference between constants and volatile variables in C? [4]

Q3. A What are arithmetic operators? Explain with examples. [5]


B What is operator precedence and associativity in C? Explain with an example
involving multiple operators. [5]
C Define relational operators and provide examples of their usage. [4]

OR
Q4. A What are the different types of operators in C? Explain each type with examples. [5]
B Differentiate prefix and postfix operators with example [5]
C Write difference between Logical Operators and Assignment Operators with program
code. [4]

Q5. A Explain the use of if, else-if, and switch statements in C with examples. [5]
B Write a program using a switch statement to find the day of the week based on an [5]
Integer input.
C Write a program to find given number is positive or negative. [4]

OR
Q6. A Write a program to print the multiplication table of a given number using a for loop. [5]
B What are loops in C? Explain while, do-while, and for loops with examples. [5]
C What is the purpose of break and continue statements in C? Explain with examples [4]
Q7. A Explain the declaration and initialization of one-dimensional arrays in C with [5]
examples.
B Write a program to find the largest element in an array of integers. [5]
C Define a two-dimensional array in C. Write a program to multiply two matrices. [4]

OR
Q8. A How are strings handled in C? Explain how to declare and initialize strings. Write a [5]
program to compare two strings using strcmp().
B Write a simple Program to calculate the result of any five subjects using an array. [5]
C Write any 4 Characteristics of Arrays and Strings [4]

Q9. A What is the need for user-defined functions in C? Explain with an example. [5]
B What is recursion? Write a recursive function to calculate the factorial of a number. [5]
C Explain the different categories of functions in C with examples: [4]

o No Arguments, No Return Value


o Arguments, No Return Value
o Arguments with Return Value
o No Arguments but Return a Value

OR
Q10. A Define a structure in C. Write a program to store information about a student (name, [5]
roll number, and marks) using structures and display it.
B What is User Defined Functions: write in brief about Definition of Functions, Return [5]
Values and their Types, Function Calls, Function Declaration,
C Differentiate between Call by Value & Call by Reference with Example. [4]

Q.No.5B:

/**
* C program to print day of week using switch case
*/

#include <stdio.h>

int main()
{
int week;

/* Input week number from user */


printf("Enter week number(1-7): ");
scanf("%d", &week);

switch(week)
{
case 1:
printf("Monday");
break;
case 2:
printf("Tuesday");
break;
case 3:
printf("Wednesday");
break;
case 4:
printf("Thursday");
break;
case 5:
printf("Friday");
break;
case 6:
printf("Saturday");
break;
case 7:
printf("Sunday");
break;
default:
printf("Invalid input! Please enter week number between 1-
7.");
}

return 0;
}

Q.No.5C:

#include <stdio.h>

int main() {

double num;
printf("Enter a number: ");
scanf("%lf", &num);
if (num <= 0.0) {
if (num == 0.0)
printf("You entered 0.");
else
printf("You entered a negative number.");
}
else
printf("You entered a positive number.");

return 0;
}

Q.No.6A:

#include <stdio.h>
int main() {
int n;
printf("Enter an integer: ");
scanf("%d", &n);

for (int i = 1; i <= 10; ++i) {


printf("%d * %d = %d \n", n, i, n * i);
}
return 0;
}
Q.NO.7B:

#include <stdio.h>
int main() {
int n;
double arr[100];
printf("Enter the number of elements (1 to 100): ");
scanf("%d", &n);

for (int i = 0; i < n; ++i) {


printf("Enter number%d: ", i + 1);
scanf("%lf", &arr[i]);
}

// storing the largest number to arr[0]


for (int i = 1; i < n; ++i) {
if (arr[0] < arr[i]) {
arr[0] = arr[i];
}
}

printf("Largest element = %.2lf", arr[0]);

return 0;
}
Run Code

Output

Enter the number of elements (1 to 100): 5


Enter number1: 34.5
Enter number2: 2.4
Enter number3: -35.5
Enter number4: 38.7
Enter number5: 24.5
Largest element = 38.70

This program takes n number of elements from the user and stores it in the arr array.
To find the largest element,

 the first two elements of array are checked and the largest of these two elements are
placed in arr[0]

 the first and third elements are checked and largest of these two elements is placed
in arr[0] .

 this process continues until the first and last elements are checked

 the largest number will be stored in the arr[0] position


Q.No.7C:

1. #include<stdio.h>
2. #include<stdlib.h>
3. int main(){
4. int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
5. system("cls");
6. printf("enter the number of row=");
7. scanf("%d",&r);
8. printf("enter the number of column=");
9. scanf("%d",&c);
10. printf("enter the first matrix element=\n");
11. for(i=0;i<r;i++)
12. {
13. for(j=0;j<c;j++)
14. {
15. scanf("%d",&a[i][j]);
16. }
17. }
18. printf("enter the second matrix element=\n");
19. for(i=0;i<r;i++)
20. {
21. for(j=0;j<c;j++)
22. {
23. scanf("%d",&b[i][j]);
24. }
25. }
26.
27. printf("multiply of the matrix=\n");
28. for(i=0;i<r;i++)
29. {
30. for(j=0;j<c;j++)
31. {
32. mul[i][j]=0;
33. for(k=0;k<c;k++)
34. {
35. mul[i][j]+=a[i][k]*b[k][j];
36. }
37. }
38. }
39. //for printing result
40. for(i=0;i<r;i++)
41. {
42. for(j=0;j<c;j++)
43. {
44. printf("%d\t",mul[i][j]);
45. }
46. printf("\n");
47. }
48. return 0;
49. }
QNO 8B:

#include <stdio.h>

int main()
{
float eng, phy, chem, math, comp;
float total, average, percentage;

printf("Enter marks of five subjects: :- ");


scanf("%f%f%f%f%f", &eng, &phy, &chem, &math, &comp);

total = eng + phy + chem + math + comp;


average = total / 5.0;
percentage = (total / 500.0) * 100;

printf("Total marks = %.2f\n", total);


printf("Average marks = %.2f\n", average);
printf("Percentage = %.2f", percentage);

return 0;
}

QNO 9B:

#include<stdio.h>
long int multiplyNumbers(int n);
int main() {
int n;
printf("Enter a positive integer: ");
scanf("%d",&n);
printf("Factorial of %d = %ld", n, multiplyNumbers(n));
return 0;
}

long int multiplyNumbers(int n) {


if (n>=1)
return n*multiplyNumbers(n-1);
else
return 1;
}
QNO 10 A:
// C Program to Store Information of Students Using Structure
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

// Create the student structure


struct Student {
char* name;
int roll_number;
int age;
double total_marks;
};

int main() {

// Create an array of student structure variable with


// 5 Student's records
struct Student students[5];
int n = sizeof(students)/sizeof(struct Student);

// Get the students data


students[0].roll_number = 1;
students[0].name = "Geeks1";
students[0].age = 12;
students[0].total_marks = 78.50;

students[1].roll_number = 5;
students[1].name = "Geeks5";
students[1].age = 10;
students[1].total_marks = 56.84;

students[2].roll_number = 2;
students[2].name = "Geeks2";
students[2].age = 11;
students[2].total_marks = 87.94;

students[3].roll_number = 4;
students[3].name = "Geeks4";
students[3].age = 12;
students[3].total_marks = 89.78;

students[4].roll_number = 3;
students[4].name = "Geeks3";
students[4].age = 13;
students[4].total_marks = 78.55;

// Print the Students information


printf("========================================\n");
printf(" Student Records \n");
printf("========================================\n");

for (int i = 0; i < n; i++) {


printf("\nStudent %d:\n", i + 1);
printf(" Name : %s\n", students[i].name);
printf(" Roll Number : %d\n", students[i].roll_number);
printf(" Age : %d\n", students[i].age);
printf(" Total Marks : %.2f\n", students[i].total_marks);
}
printf("========================================\n");

You might also like