SRM Institute of Science and Technology College of Engineering and Technology School of Computing Department of Computing Technologies
SRM Institute of Science and Technology College of Engineering and Technology School of Computing Department of Computing Technologies
SRM Institute of Science and Technology College of Engineering and Technology School of Computing Department of Computing Technologies
CLR-2 : Utilize the appropriate operators and control statements to solve engineering problems
CLR-3 : Store and retrieve data in a single and multidimensional array
CLR-4 : Create custom designed functions to perform repetitive tasks in any application
CLO-2 : To use appropriate data types in simple data processing applications. To create programs using the concept
of arrays.
CLO-3 : To create string processing applications with single and multi-dimensional arrays.
CLO-4 : To create user-defined functions with required operations. To implement pointers in applications with
dynamic memory.
NOTE:
● For each 5 mark question, 2 marks logic (as seen in program irrespective of syntax errors) and 3
marks for program.
● Based on number of syntax errors in program, program marks (3) may be allotted.
● There is no need to write #inlcude<stdio.h> for all programs
● There are many ways of writing the same program!
Part - A
(1 x 25 = 25 Marks)
Instructions: This section has only ONE question with internal choice.
Q. Question Marks BL CO PO PI
No Code
1 National Highways Department announces a scheme for the
four-wheeler in the toll gate for 50th year celebration. If the 5 2 2 2 2.6.3
vehicle number is divisible by both 7 and 3 then they should
pay one-third of the fee. If the vehicle number is divisible by 7
or 3 then they should pay half of the fee. Otherwise, they have
to pay full fees. Write a c program for the same.
ANSWER:
#include <stdio.h>
int main()
{
int vehicleno;
int pay,tollfee=100;
printf("enter the vehicle number");
scanf("%d",&vehicleno);
if (vehicleno%7==0 && vehicleno%3==0)
pay=tollfee/3;
else if (vehicleno%7==0 || vehicleno%3==0)
pay=tollfee/2;
else
pay=tollfee;
printf("the payable amount is %d",pay);
return 0;
}
OUTPUT:
enter the vehicle number2304
the payable amount is 50
2.6.3
2 Mrs. Ninu wants to teach her five-year-old daughter on “ 5 2 2 2
seasons and months”. If Ninu tells her daughter the name of the
month, she must tell her the season for that month. Given the
month number M, the task is to print the season name of the
year based on the month number. Write a C program to
implement the same.
ANSWER:
#include <stdio.h>
void main()
{
// Checks out the season according
// to the month number entered by the user
int M;
printf("enter the number of month");
scanf("%d",&M);
switch (M)
{
case 12:
case 1:
case 2:
printf("\nWINTER");
break;
case 3:
case 4:
case 5:
printf("\nSPRING");
break;
case 6:
case 7:
case 8:
printf("\nSUMMER");
break;
case 9:
case 10:
case 11:
printf("\nAUTUMN");
break;
default:
// Handles the condition if number entered
// is not among the valid 12 months
printf("\nInvalid Month number");
break;
}
}
OUTPUT:
enter the number of month3
SPRING
7
3 Mr. Bob has been deputed as the Election officer for the Tamil
Nadu State Election. He wanted to perform an analysis to check
whether a candidate is eligible for voting when he/she enters
his/her age. Write a C program to read the age of a candidate
and determine whether it is eligible for casting his/her own
vote. 5 2 2 2.6.3
2
ANSWER:
#include <stdio.h>
void main()
{
int vote_age;
printf("Input the age of the candidate : ");
scanf("%d",&vote_age);
if (vote_age<18)
{
printf("Sorry, You are not eligible to caste your vote.\n");
printf("You would be able to caste your vote after %d
year.\n",18-vote_age);
}
else
printf("Congratulation! You are eligible for casting your
vote.\n");
}
OUTPUT:
Input the age of the candidate: 21
Congratulation! You are eligible for casting your vote.
4
Divya is interested to walk on the number line. She started from
1 and will go on walking along the number line in the positive
direction. She got a bag to collect those numbers from 1, 2, 3,
and so on up to N. Help her to find the sum of that numbers by
writing C code.
2.6.3
ANSWER: 2
5 3 2
#include <stdio.h>
int main()
int i, n, sum = 0;
scanf("%d", &n);
*/
sum += i
}
printf(“%d\n”, sum);
return 0;
Output
10
5
Ms. Ahalya is a C programmer and she has been assigned work
on Student Grade Calculation. She is familiar with control flow
statements. Assist her in developing a C program to compute
student grades based on the following criteria:
Mark Grade
2.6.3
2
Mark<50 F
5 1 2
50<=marks<60 C
60<=marks<70 B
70<=marks<80 B+
80<=marks<90 A
90<=marks<=100 A+
ANSWER:
#include <stdio.h>
int main(void)
{
int num;
printf("Enter your mark ");
scanf("%d",&num);
printf(" You entered %d Marks \n", num); // printing outputs
if(num >= 90)
{
printf(" You got A+ grade \n"); // printing outputs
}
else if ( num >=80)
{
printf(" You got A grade \n");
}
else if ( num >=70)
{
printf(" You got B+ grade \n");
}
else if ( num >=60)
{
printf(" You got B grade \n");
}
else if ( num >=50)
{
printf(" You got C grade \n");
}
else if ( num < 50)
{
printf(" You Failed in this exam \n");
printf(" Better Luck Next Time \n");
}
return 0;
}
OUTPUT:
Enter your mark 56
You entered 56 Marks
You got C grade
(OR)
6 Mr. John is a trainee at XYZ Software company and he has
been assigned with the following tasks to find the solutions.
Help him to find the output from the following program.
#include<stdio.h>
void main ( )
{
int num[26], temp ; 3.5.1
num[0] = 100 ; 3
5 3 2
num[25] = 200 ;
temp = num[25] ;
num[25] = num[0] ;
num[0] = temp ;
printf ( "\n %d %d", num[0], num[25] ) ;
}
OUTPUT
200 100
ANSWER:
#include<stdio.h>
#include<conio.h>
#define FIRST 360
# define SECOND 240
void main()
{
int n, m, i, j, roll number, marks, total;
printf(“Enter number of students and subjects”);
scanf(“%d%d”, &n,&m);
printf(“\n”);
for(i=1; i<=n; ++i)
{
printf(“Enter roll number:”);
scanf(“%d”, &roll_number);
total=0;
printf(“Enter marks of %d subjects for ROLL NO”, m, roll
number);
for(j=1; j<=m; j++)
{
scanf(“%d”, &marks);
total=total+marks;
}
printf(“TOTAL MARKS =%d”, total);
}
}
Output:
======
Enter number of students and subjects
36
Enter roll_number: 8701
Enter marks of 6 subjects for ROLL NO 8701
81 75 83 45 61 59
TOTAL MARKS =404 (First division)
Enter roll_number:8702
Enter marks of 6 subjects for ROLL NO 8702
51 49 55 47 65 41
TOTAL MARKS =308(Second division)
Enter roll_number: 8704
40 19 31 47 39 25
8 TOTAL MARKS=201
Help John to point out the errors, if any, in the following
program segment:
OUTPUT:
Error:
1. int followed by char is illegal
2. No ‘&’ sign in scanf function
9
After summer vacation, the University is reopening the college
for UG and PG courses. In the first day and first hour, the B.
Tech students are having Computer Programming class. As
soon as the Professor entered the class, he saw that students
were sitting in random order. So, he decided to arrange the
student in his class in ascending order (Height). Assist the
Professor to arrange the student in ascending order based on the
height of the students. Write a program for the above given
scenario.
2.6.3
HINT:
2
INPUT ARRAY: {123,112,130,145,162}
5 2 2
ANSWER:
#include <stdio.h>
void main()
{
int arr1[10];
int n, i, j, tmp;
printf("\n\nsort elements of array in ascending order :\n");
printf("----------------------------------------------\n");
printf("Input the size of array : ");
scanf("%d", &n);
printf("Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&arr1[i]);
}
for(i=0; i<n; i++)
{
for(j=i+1; j<n; j++)
{
if(arr1[i] < arr1[j])
{
tmp = arr1[i];
arr1[i] = arr1[j];
arr1[j] = tmp;
}
}
}
printf("\nElements of array is sorted in descending order:\n");
printf("\n\n");
}
10
Test Data :
Input the number of elements to store in the array :3
Input 3 number of elements in the array :
element - 0 : 2
element - 1 : 5
element - 2 : 7 2.6.3
2
Expected Output :
The values store into the array are :
5 1 2
257
The values store into the array in reverse are :
752
ANSWER:
#include <stdio.h>
void main()
{
int i,n,a[100];
Part – B
(1 x 25 = 25 Marks)
Instructions: This section has only ONE question with internal choice.
11 Mr. Adam is a software programmer at Orange Systems. He
wanted to assess the trainee's skillset in C language. Hence, he
has assigned some tasks to the trainees to complete in the
allotted time. Assist them in completing the tasks listed below.
3 3.6.1
Consider the fragment. 5 3 3
char str[] = “ I am Gr8DON”;
str[4] = ‘\0’;
printf(“%s”, str);
What is printed? Justify the answer.
ANSWER:
OUTPUT:
I am
12 Adam is willing to play with C strings. He would like to find
the length of a given string without using string functions. 5 2 3 2 2.6.3
Assist him to complete the task.
ANSWER:
#include <stdio.h>
#include <string.h>
void main()
{
char str1[50] = “Programming for Problem Solving”;
int i, l = 0;
ANSWER:
#include <stdio.h>
#include <stdlib.h>
void main()
{
char str[100]; /* Declares a string of size 100 */
int l= 0;
ANSWER:
STRINGS
A String in C is nothing but a collection of characters in a
linear sequence. ‘C’ always treats a string a single data even
though it contains whitespaces. A single character is defined
using single quote representation. A string is represented using
double quote marks.
Example, "Welcome to the world of programming!"
Input: 155342
ANSWER:
#include<stdio.h>
#include <stdlib.h>
int main() {
// Converting a numeric string
char str[10] = "155342";
int x = atoi(str);
printf("Converting '155342': %d\n", x);
Find the types of pointer used for the given cases and explain
a) Consider a scenario where a person living in country
16
A decides to move country B for his/her vacations,
where certain services like YouTube are not
accessible. Now, whenever he/she tries to hit
www.youtube.com, they would receive some HTTP
errors, which would mean that there is no pointer or
route available for www.youtube.com at that location.
ANSWER:
Dangling Pointers
The pointers pointing to a deallocated memory block or
unallocated memory block are known as Dangling Pointers.
This condition generates an error known as Dangling Pointer
Problem. Dangling Pointer occurs when a pointer pointing to a
variable goes out of scope or when an object/variable's memory
contains unitialized values or point to deallocated memory.
Void Pointers
Syntax
void *name_of_pointer;
Here, the void keyword acts as the pointer type, and it is 2.6.3
followed by the pointer name- to which the pointer type points
and allocates the address location in the code. The declaration 2
5 2 4
of a pointer happens with the name and type of pointer that
supports any given data type. Let us take a look at an example
to understand this better.
void *ptr
Here, the pointer is expecting a void type- not int, float, etc. It
is pointed by the ptr pointer here that includes the * symbol. It
denotes that this pointer has been declared, and it will be used
for dereferencing in the future.
ANSWER:
#include <stdio.h>
int main()
{
char str[100];
char *ptr;
int cntV,cntC;
cntV=cntC=0;
while(*ptr!='\0')
{
if(*ptr=='A' ||*ptr=='E' ||*ptr=='I' ||*ptr=='O' ||*ptr=='U'
||*ptr=='a' ||*ptr=='e' ||*ptr=='i' ||*ptr=='o' ||*ptr=='u') 3.6.2
cntV++;
else 5 3 4 3
cntC++;
//increase the pointer, to point next character
ptr++;
}
Mr. Charles wants to find the output of the following code 3.6.2
snippet. 3
1. int x = 5, y = 15; 5 3 4
18 2. int * p1, * p2;
3. p1 = &x;
4. p2 = &y;
5. *p1 = 10;
6. *p2 = *p1;
7. p1 = p2;
8. *p1 = 20;
9. printf("%d %d",x,y);
OUTPUT:
10 20
EXPLANATION:
Input 5 values
25 11 35 65 20
Expected Output :
return 0;
}
/*** Find maximum between two numbers.*/
int max(int num1, int num2)
{
return (num1 > num2 ) ? num1 : num2;
}
/*** Find minimum between two numbers.*/
int min(int num1, int num2)
{
return (num1 > num2 ) ? num2 : num1;
}
*Performance Indicators are available separately for Computer Science and Engineering in AICTE
examination reforms policy.