0% found this document useful (0 votes)
73 views

Jul 2021 AN Answer Key

Uploaded by

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

Jul 2021 AN Answer Key

Uploaded by

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

01EST102052002 B

F Pages: 2
Reg No.:_______________ Name:__________________________

APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY


Second Semester B.Tech Degree Examination July 2021 (2019 scheme)
Course Code: EST102
Course Name: PROGRAMMING IN C
(AN Session)
Max. Marks: 100 Duration: 3 Hours
PART A
Answer all Questions. Each question carries 3 Marks Marks
1 Differentiate between system software and application software. (3)
2 Write an algorithm to find the largest of three numbers (3)
3 What is the difference between assignment and equality operators? (3)
4 What is a static variable? When should it be used? (3)
5 Write a C program to find length of a string without using string handling (3)
functions.
6 What is an array? Illustrate using an example, how a single dimensional array (3)
is initialised.
7 Differentiate between structure and union using an example. (3)
8 Illustrate the purpose of return statement using an example. (3)
9 Differentiate between char name[] and char *name in C. (3)
10 Explain the use of fseek() function. (3)
PART B
Answer any one Question from each module. Each question carries 14 Marks
11 a) Draw a flowchart to find the factorial of a number. (6)
b) With the help of a neat diagram explain the functional units of a computer. (8)
OR
12 a) List five important registers in CPU. Also state the purpose of each register. (6)
b) Write algorithm and draw flowchart to perform swapping of two numbers. (8)
13 a) Explain arithmetic, logical and bitwise operators with examples. (7)
b) Write a C Program to check if a given number is a strong number or not. A (7)
strong number is a number in which the sum of the factorial of the digits is
equal to the number itself.
Eg:- 145=1!+4!+5!=1+24+120=145
OR
14 a) Write C program to convert the given decimal number into binary number. (7)

Page 1 of 2
01EST102052002 B

b) What do you mean by Formatted Input? Explain in detail the prototype of (7)
‘scanf()’ function in C including its argument list and return type.
15 a) Explain any 4 string handling functions in C programming. (7)
b) Write a C program to perform linear search on an array of numbers (7)
OR
16 a) Write a C program to find second largest element in an array. (7)
b) Write a C program to check whether a string is palindrome or not without using (7)
string handling functions.
17 a) What are different storage classes in C? Give examples for each. (7)
b) Write a C program to: (7)
(i) Create a structure with fields: Name, Address, Date of birth.
(ii) Read the above details for five students from user and display the details
OR
18 a) What is recursion? Write a C program to display Fibonacci series using (7)
recursive function.
b) Write a C program to sort N numbers using functions. (7)
19 a) Explain any 5 file handling functions in C. (7)
b) Write a C program to reverse a string using pointers. (7)
OR
20 a) Differentiate between array of pointers and pointer to an array. (7)
b) Write a C program to count number of lines in a text file. (7)
****

Page 2 of 2
01EST102052002 B

Scheme of Valuation/Answer Key


(Scheme of evaluation (marks in brackets) and answers of problems/key)
APJ ABDUL KALAM TECHNOLOGICAL UNIVERSITY
SECOND SEMESTER B.TECH DEGREE EXAMINATION(2019 SCHEME), JULY 2021
Course Code: EST 102
Course Name: PROGRAMMING IN C (Common to all programs)
Max. Marks: 100 (AN Session) Duration: 3 Hours
PART A
Answer all Questions. Each question carries 3 Marks Marks
1 Difference-3 Marks (3)
1. System Software is the type of software which is the interface between
application software and system. On other hand Application Software is
the type of software which runs as per user request. It runs on the
platform which is provide by system software.
2. System software is used for operating computer hardware. On other hand
Application software is used by user to perform specific task.

3.Some examples of system software’s are compiler, assembler, debugger,


driver, etc. Some examples of application software’s are word processor, web
browser, media player, etc.
2 Correct algorithm-3 Marks (3)
Step 1: start.
Step 2: input a, b, c
Step 3: let Max=a.
Step 4: is b > Max? then Max = b
Step 5: is c > max? then Max = c
Step6: print Max
Step7: stop
3 Difference-3 Marks (3)
The “=” is an assignment operator is used to assign the value on the right to the
variable on the left. The '==' operator checks whether the two given operands
are equal or not.
4 static variable-2 marks use- 1 mark (3)
Static variables are initialized only once. The compiler persists with the variable
till the end of the program. Static variables can be defined inside or outside the
01EST102052002 B

function. They are local to the block. The default value of static variables is zero.
The static variables are alive till the execution of the program.
1. Static defined local variables do not lose their value between function
calls. In other words they are global variables, but scoped to the local
function they are defined in.
2. Static global variables are not visible outside of the C file they are
defined in.

5 Correct Program-3 Marks (3)


#include <stdio.h>
void main()
{
char str[100],i;
printf("Enter a string: \n");
scanf("%s",str);
for(i=0; str[i]!='\0'; ++i);
printf("\nLength of input string: %d",i);

6 Array definition-1 mark . Illustration-2 marks (3)


7 Difference-2 Marks Example-1 mark (3)
A structure is a user-defined data type available in C that allows to combining
data items of different kinds. Structures are used to represent a record. Each
member is assigned unique storage. To define a structure, you must use
the keyword struct .
A union is a special data type available in C that allows storing different data
types in the same memory location. Memory allotted is shared by union
members. You can define a union with many members, but only one member can
contain a value at any given time. Unions provide an efficient way of using the
same memory location for multiple purposes. To define a union, you must use
the keyword union
8 Illustration using example - 3marks (3)
A return statement ends the execution of a function, and returns control to the
calling function. Execution resumes in the calling function at the point
immediately following the call. A return statement can return a value to the
calling function.
#include <stdio.h>
01EST102052002 B

void Print()
{
printf("Welcome to Programming");
}

int main()
{
Print();
return 0;
}

9 Difference-3 Marks (3)


One is an array that refers to an array of characters. The other is a pointer to a
character.
10 fseek()- Syntax-1 mark Use- 2 Marks (3)
int fseek(FILE *pointer, long int offset, int position)

pointer: pointer to a FILE object that identifies the stream.


offset: number of bytes to offset from position
position: position from where offset is added.

The fseek() function seeks in an open file. This function moves the file pointer
from its current position to a new position, forward or backward, specified by the
number of bytes.
PART B
Answer any one Question from each module. Each question carries 14 Marks
11 a) Flowchart- 6 Marks (6)
b) Any 4 functional units.2 marks each (8)
OR
12 a) Registers-1 Mark (6)
five important registers in CPU along with functions (5 marks)
b) Algorithm- 4 marks Flowchart -4 marks (8)
13 a) Arithmetic operators with example -2.5 marks (7)
Logical operators with example - 2.5 marks
Bitwise operators with example - 2marks

b) Correct Program-7 Marks (7)


01EST102052002 B

#include <stdio.h>

int main()
{
int i, originalNum, num, lastDigit, sum;
long fact;

printf("Enter any number to check Strong number: ");


scanf("%d", &num);

originalNum = num;

sum = 0;

/* Find sum of factorial of digits */


while(num > 0)
{

/* Get last digit of num */


lastDigit = num % 10;

/* Find factorial of last digit */


fact = 1;
for(i=1; i<=lastDigit; i++)
{
fact = fact * i;
}

/* Add factorial to sum */


sum = sum + fact;

num = num / 10;


}

/* Check Strong number condition */


if(sum == originalNum)
{
printf("%d is STRONG NUMBER", originalNum);
}
else
{
printf("%d is NOT STRONG NUMBER", originalNum);
}

return 0;
}
OR
01EST102052002 B

14 a) Correct Program-7 Marks (7)


#include <stdio.h>
#include <math.h>

long decimalToBinary(int decimalnum)


{
long binarynum = 0;
int rem, temp = 1;

while (decimalnum!=0)
{
rem = decimalnum%2;
decimalnum = decimalnum / 2;
binarynum = binarynum + rem*temp;
temp = temp * 10;
}
return binarynum;
}

int main()
{
int decimalnum;
printf("Enter a Decimal Number: ");
scanf("%d", &decimalnum);
printf("Equivalent Binary Number is: %ld", decimalToBinary(decimalnum));
return 0;
}

b) Formatted Input – 2marks (7)


prototype of ‘scanf()’ function – 5marks
15 a) any 4 string handling functions with syntax and explanation-7 marks (7)
strcat(), strrev(), strcpy(),strlen()
b) Correct Program-7 Marks (7)
#include <stdio.h>
int main()
{
int array[100], search, c, n;
printf("Enter number of elements in array\n");
scanf("%d", &n);
printf("Enter %d integer(s)\n", n);
for (c = 0; c < n; c++)
scanf("%d", &array[c]);
printf("Enter a number to search\n");
scanf("%d", &search);
for (c = 0; c < n; c++)
{
if (array[c] == search) /* If required element is found */
{
printf("%d is present at location %d.\n", search, c+1);
01EST102052002 B

break;
}
}
if (c == n)
printf("%d isn't present in the array.\n", search);
return 0;
}

OR
16 a) Correct Program-7 Marks (7)
#include <stdio.h>

void main(){
int arr1[50],n,i,j=0,lrg,lrg2nd;

printf("\n\nFind the second largest element in an array :\n");


printf("-------------------------------------------------\n");

printf("Input the size of array : ");


scanf("%d", &n);
/* Stored values into the array*/
printf("Input %d elements in the array :\n",n);
for(i=0;i<n;i++)
{
printf("element - %d : ",i);
scanf("%d",&arr1[i]);
}
/* find location of the largest element in the array */

lrg=0;
for(i=0;i<n;i++)
{
if(lrg<arr1[i])
{
lrg=arr1[i];
j = i;
}
}

/* ignore the largest element and find the 2nd largest element in the array */

lrg2nd=0;
for(i=0;i<n;i++)
{
if(i==j)
{
i++; /* ignoring the largest element */
i--;
}
01EST102052002 B

else
{
if(lrg2nd<arr1[i])
{
lrg2nd=arr1[i];
}
}
}

printf("The Second largest element in the array is : %d \n\n", lrg2nd);


}
b) Correct Program-7 Marks (7)
#include <stdio.h>
#include <string.h>

void main()
{
char string[25], reverse_string[25] = {'\0'};
int i, length = 0, flag = 0;

printf("Enter a string \n");


gets(string);
/* keep going through each character of the string till its end */
for (i = 0; string[i] != '\0'; i++)
{
length++;
}
printf("The length of the string '%s' = %d\n", string, length);
for (i = length - 1; i >= 0 ; i--)
{
reverse_string[length - i - 1] = string[i];
}
/* Check if the string is a Palindrome */

for (flag = 1, i = 0; i < length ; i++)


{
if (reverse_string[i] != string[i])
flag = 0;
}
if (flag == 1)
printf ("%s is a palindrome \n", string);
else
printf("%s is not a palindrome \n", string);
}

17 a) Storage class definition -1 mark. (7)


Any 3 storage classes- 1 mark each.
Example – 1 Mark each
01EST102052002 B

b) Structure Creation -3Marks (7)


Function to read data- 2 Marks
Function to display data- 2 Marks.
OR
18 a) Recursion – 2 marks (7)
Correct Program-5 Marks
b) Correct Program-7 Marks (7)
19 a) 5 file handling functions. (7)
Explanation of
fopen()
fgets()
fprintf()
fclose()
fseek()

b) Correct Program-7 Marks (7)


#include <stdio.h>
int main()
{
char str1[50];
char revstr[50];
char *stptr = str1;
char *rvptr = revstr;
int i=-1;
printf("\n\n Pointer : Print a string in reverse order :\n");
printf("------------------------------------------------\n");

printf(" Input a string : ");


scanf("%s",str1);
while(*stptr)
{
stptr++;
i++;
}
while(i>=0)
{
stptr--;
*rvptr = *stptr;
rvptr++;
--i;
}
*rvptr='\0';
printf(" Reverse of the string is : %s\n\n",revstr);
return 0;
}

OR
01EST102052002 B

20 a) Differentiate using sample program fragments – 7 marks (7)


b) Correct Program-7 Marks (7)
#include<iostream>
using namespace std;
#define FILENAME "test.txt"
int main() {
FILE *fp;
char ch;
int linesCount=0;
//open file in read more
fp=fopen(FILENAME,"r");
if(fp==NULL) {
printf("File \"%s\" does not exist!!!\n",FILENAME);
return -1;
}
//read character by character and check for new line
while((ch=fgetc(fp))!=EOF) {
if(ch=='\n')
linesCount++;
}
//close the file
fclose(fp);
//print number of lines
printf("Total number of lines are: %d\n",linesCount);
return 0;
}

NOTE: Marks may be awarded for programs conveying correct logic. Sample programs
are included in scheme.

You might also like