Download as pdf or txt
Download as pdf or txt
You are on page 1of 21

Q1 A What is a computer? Write the characteristics of computer.

A computer is an electronic device, operating under the control of instructions stored in its own
memory that can accept data (input), process the data according to specified rules, produce
information (output), and store the information into memory for future use.

m
Input Processing Output

(Data) (Information)

co
Speed − Typically, a computer can carry out 3-4 million instructions per second.

Accuracy − Computers exhibit a very high degree of accuracy. Errors that may occur are
usually due to inaccurate data, wrong instructions or bug in chips – all human errors.
e.
Reliability − Computers can carry out same type of work repeatedly without throwing up
errors due to tiredness or boredom, which are very common among humans.
dg
Versatility − Computers can carry out a wide range of work from data entry and ticket
booking to complex mathematical calculations and continuous astronomical observations. If
you can input the necessary data with correct instructions, computer will do the processing.
ue

Storage Capacity − Computers can store a very large amount of data at a fraction of cost of
traditional storage of files. Also, data is safe from normal wear and tear associated with
paper.
vt

Q1 B. With the neat diagram, Explain the working of CRT monitor and LCD monitor.

CRT Monitor

CRT monitor work by firing charged electrons at phosphorous film. When electrons hit the
phosphorus-coated screen, they glow thereby enabling the user to see the output.

CRT monitor provide good quality image.

A CRT works by moving an electron beam back and forth across the back of the screen. Each
time the beam makes a pass across the screen, it lights up phosphor dots on the inside of the
glass tube, thereby illuminating the active portions of the screen. By drawing many such lines
from the top to the bottom of the screen, it creates an entire screen of images.

m
co
LCD Monitor

LCD monitor is a thin, flat electronic visual display that uses the light modulating properties of
e.
liquid crystals, which do not emit light directly.

LCD monitor are very compact and lightweight, they consume less power.
dg
LCD technology is based on the principle of blocking light. The LCD consists of two pieces of
polarizing filters that contain a liquid crystal material between them. A backlight which is made to
pass through both the layer creates the colors, and hence images are seen on the screen.
ue
vt
Q1 C. Write a structure of a C program with an example.

Structure of C program

Document Section

Link Section

m
Definition Section

Global Declaration Section

main ( ) function Section

co
{

Declaration part
Executable part
}

Sub program Section


e.
Function_1( )
Function_2( )
dg
--
--
Function_n( )
ue

- Document Section: The Documentation Section consists of a set of comment lines


giving the name of the program and other details.
- Link Section: provides instructions to the compiler to link functions from the system
library. C program depends upon some header files for function definition that are
used in the program. These files should be included using #include directive as given
vt

below

Example: #include<stdio.h>

- Definition Section: Defines all symbolic constants. Example: #define MAX 50


- Global Declaration Section: The variables declared in this section are visible or
available to whole program; such variables are called global variables.
- main() function: Every C program must have one main() function section. This
section has two sections 1) Declaration part declares all variables used in executable
part and 2) Executable part contains instructions to perform certain tasks. main( )
function can appear either as

void main(void) - main( ) function does not return any value

OR

int main(void) -main( ) function return an integer

OR

m
void main( ) - main( ) function does not return any value

OR

int main( ) -main( ) function return an integer

co
- Subprogram Section: This section contains all the user defined functions that are
called in the main function.

Q2 A. Define the following terms with an example


e.
i)Algorithm ii)Flowcharts iii) Pseudo code

Algorithm is sequence of steps written in English phrases, which specify the tasks that are performed while so
involves identifying variable names with their types that would be used for solving the problem.
dg
Characteristics of a good algorithm are:

Precision – the steps are precisely stated (defined).

Uniqueness – results of each step are uniquely defined and only depend on the input and the result of the pr
ue

Finiteness – the algorithm stops after a finite number of steps are executed.

Input – the algorithm receives input.

Output – the algorithm produces output.

Generality – the algorithm applies to a set of inputs.


vt

Add two integer numbers.

Step 1: Start
Step 2: identify the required variables num1, num2 and sum.
Step 3: Read values num1 and num2.
Step 4: Add num1 and num2 and assign the result to sum.
sum←num1+num2
Step 5: Display sum
Step 6: Stop
A flowchart is a pictorial (graphical) representation of the flow of control and logic in the solution of a problem.

m
co
e.
Pseudo code is an informal way of programming description that does not require any strict programming
dg
language syntax.
It is used for creating an outline or a rough draft of a program

i) Write pseudo code that reads two numbers, multiplies them and print their product
Read num1, num2
Set multi to num1*num2
ue

Write multi

Q2B What are variables how they are declared and initialized with an example
vt

Variable: Variable is a data item name used for storing data value and it changes its

value during execution of the program. The name of the variable is chosen by the

programmer in a meaningful way to reflect the purpose of variable.

Every variable has its associated type which defines the value a variable can hold.
1) Variable name must be made up of letters or
alphanumeric and only ‘_’ (underscore) can be used as
special symbol in variable names. Prefer alphabet as
Rules for Declaring first character.
Variables 2) Variable name cannot be Keyword
3) Variable name must not contain blank space
4) Variable names are case sensitive

m
Syntax to Declare variable:

data type v; data type v1, v2, v3,…;

co
OR

Where v or v1, v2, v3…. are names of the variable and data type can be any of basic data
types.

Examples: 1) int age;


e.
2) int snum, age, marks;
dg
2) Assigning value to variables OR Assignment statement: Variables are declared
for the purpose of storing values in them and this is done in program by using an
assignment statement.

Syntax to use assignment statement:


ue

data type v1=value, v2=value,…;

OR
vt

var_name = constant; var_name = expression;

Examples: 1) int age;

age = 21;

2) float tot_price, m1 = 56.5 , m2 = 60.3;

tot_price = m1 + m2;
Q2 C Write a C program to demonstrate the use of printf and scanf statements to read
and print values of variables of different data types.

Answer Refer Question 2 C from MODEL QUESTION PAPER SET 1

#include<stdio.h>

m
int main()
{
int num1, num2;
float fraction;
char character;

co
printf("\nEnter two numbers number");
scanf("%d %d", &num1, &num2);
printf("\nThe two numbers You have entered are %d and %d", num1, num2);
e.
printf("\nEnter a Decimal number");
scanf("%f", &fraction);
printf("\nThe float or fraction that you have entered is %f", fraction);

printf("\nEnter a Character");
dg
scanf("%c",&character);
printf("\nThe character that you have entered is %c", character);
return 0;
}

Q3A Explain the syntax and working of switch case statement. Write a C program to
ue

de termine whether an entered character is Vowel or not.

Answer Refer syntax of switch Question 4 A from MODEL QUESTION PAPER SET 1

/ * C program to check vowel or consonant using switch case*/


vt

#include <stdio.h>
int main()
{
char ch;
printf("Enter any alphabet: ");
scanf("%c", &ch);
switch(ch)
{
case 'a':
printf("Vowel");
break;
case 'e':
printf("Vowel");
break;
case 'i':
printf("Vowel");
break;
case 'o':
printf("Vowel");

m
break;
case 'u':
printf("Vowel");
break;
case 'A':

co
printf("Vowel");
break;
case 'E':
printf("Vowel");
break;
case 'I': e.
printf("Vowel");
break;
case 'O':
printf("Vowel");
dg
break;
case 'U':
printf("Vowel");
break;
default:
printf("Consonant");
ue

return 0;
}
vt

Q3 B Develop a C program to find the largest of three numbers using ternary


operator.

A Ternary Operator has the following form,


exp1? exp2 : exp3
The expression exp1 will be evaluated always. Execution of exp2 and exp3 depends on the
outcome of exp1. If the outcome of exp1 is TRUE then exp2 will be evaluated,
otherwise, exp3 will be evaluated
# include <stdio.h>
void main()
{
int a, b, c, big ;
printf("Enter three numbers : ") ;
scanf("%d %d %d", &a, &b, &c) ;
big = a > b ? (a > c ? a : c) : (b > c ? b : c) ;
printf("\nThe biggest number is : %d", big) ;
}

m
Q3 C Develop a program to convert an integer into the corresponding floating point
number using Type casting.

co
#include <stdio.h>
int main()
{
int sum = 17, count = 5;
double mean;
mean = (double) sum / count;

return 0;
}
e.
printf("Value of mean : %f\n", mean );
dg
Q4 A. Demonstrate the working of break and continue statement with suitable
example.

Answer: Sometimes, while executing a loop, it becomes necessary as soon as certain condition
becomes true either to leave the loop or to skip a part of the loop, this is achieved in C using
ue

break and continue statements respectively.

1) break statement: When break statement is encountered inside a loop, the loop is
immediately exited and the program continues with the statement immediately following the
loop.
vt

Example:
2) continue statement: It causes the program control to go directly to the test-condition of loop and
then continue the looping process i.e. on encountering continue statement inside the loop will leave
the current iteration of that loop , and starts with the next iteration in loop process.

While (test-Condition)
{
Statement-1;

m
Statement-2;
if(condition)
jumps to the {
next iteration continue;
directly }

co
Statement-3; /* not executed for the iteration of loop in
which continue executed*/

continue Example:

#include <stdio.h>
e. break Example:

int a = 10;
/* while loop execution */
int main ( )
dg
{ while( a < 20 )
int a,sum = 0; {
for (a = 0; a < 10; a++) printf("value of a: %d\n", a);
{ a++;
if( a > 15)
if ( a % 2 == 0 ) {
continue; /* terminate the loop using
ue

sum = sum + a; break statement */


} break;
printf("sum = %d",sum); }
return 0; }
}
OUTPUT
vt

Output value of a: 10
sum = 25 value of a: 11
value of a: 12
“IT WILL ADD ONLY ODD NUM value of a: 13
1, 3, 5, 7, 9 AND SKIP EVEN NUM” value of a: 14
value of a: 15
Q 4 B Explain relation operator and logical operator.
Relational Operators: A relational operator checks the relationship between two operands.
If the relation is true, it returns 1; if the relation is false, it returns value 0.

Operator Meaning of Operator Example


== Equal to 5 == 3 returns 0
> Greater than 5 > 3 returns 1

m
< Less than 5 < 3 returns 0
!= Not Equal to 5 != 3 returns 1
>= Greater than or equal to 5 >= 3 returns 1
<= Less than or Equal to 5 <= 3 returns 0

co
Logical Operators: An expression containing logical operator returns either 0 or 1
depending upon whether expression results true or false.

Operator
e.
Meaning of Operator

Logical AND. True only if


Example

If c = 5 and d = 2 then, expression ((c == 5)


&&
all operands are true && (d > 5)) equals to 0.
dg
Logical OR. True only if If c = 5 and d = 2 then, expression ((c == 5) ||
||
either one operand is true (d > 5)) equals to 1.

Logical NOT. True only if If c = 5 then, expression! ( c == 5) equals to


ue

!
the operand is 0 0.
vt
Q4 C Compare the working of for while and do while along with their Syntax.

while do while
while ( condition) do
{ {
body of loop statement(s); body of loop statement(s);
} } while( Condition );

m
It is also Pre-test or Entry controlled loop It is post test or exit controlled loop
statement statement

co
Initialization, condition checking, and updating Initialization, condition checking, and
loop control variable are done at different updating loop control variable are done at
places different places

e.
If loop condition false at the first iteration then
body of the loop will not execute at all
even though initially condition inside the
while is evaluated to false body of the loop
executes at least once
dg
If the condition is not put up in 'while' loop, it
Same as while
provides compilation error.

Semicolon (;) not used to terminate statement Semicolon (;) used to terminate statement
ue

Q5 A What is recursion? Develop a C program to print Fibonacci series using


recursion.

A function that calls itself is known as a recursive function. And, this technique is
known as recursion.
vt

While using recursion, make sure that it has a base (exit) condition; otherwise, the program
will go into the infinite loop.
The stack is maintained in memory to store the occurrence of each recursive call.
Direct Recursion call
Indirect Recursion call

#include<stdio.h>
int Fibona1cci(int);
int main( )
{
int n, i = 0, c;
scanf("%d",&n);
printf("Fibonacci series\n");
for ( c = 1 ; c <= n ; c++ )
{
printf("%d\n", Fibonacci(i));
i++;
}
return 0;
}

m
int Fibonacci(int n)
{
if ( n == 0 )
return 0;

co
else if ( n == 1 )
return 1;
else
return ( Fibonacci(n-1) + Fibonacci(n-2) );
}
e.
Q 5 B How 1D integer array is represented in memory. With the help of suitable
example demonstrate the initializing the element.
dg
Answer Refer Question 5 A from MODEL QUESTION PAPER SET 1

Q5 C Develop a C program to print binary search.


#include <stdio.h>
ue

int main()
{
int i, low, high, mid, n, key, array[100];
printf("Enter number of elementsn");
scanf("%d",&n);
printf("Enter %d integersn", n);
vt

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


scanf("%d",&array[i]);
printf("Enter value to findn");
scanf("%d", &key);
low = 0;
high = n - 1;
mid = (low+high)/2;
while (low <= high)
{
if(array[mid] < key)
low = mid + 1;
else if (array[mid] == key)
{
printf("%d found at location %d.n", key, mid+1);
break;
}
else
high = mid - 1;
mid = (low + high)/2;

m
}
if(low > high)
printf("Not found! %d isn't present in the list.n", key);
return 0;
}

co
Q6 A Distinguish between Call by Value and Call by Reference using suitable
example.
e.
Answer Refer Question 5 B from MODEL QUESTION PAPER SET 1

Q6 B Define function? Develop a C program to add two integers using functions


dg
Function definition contains the block of code to perform a specific task

C allows you to define functions according to your need. These functions are known as
User-defined functions

#include <stdio.h>
ue

int add(int x, int y)


{
return x + y;
}
vt

int main( )
{
int A, B, sum;

printf("Enter the First Number: \n");


scanf("%d", &A);

printf("Enter the Second Number: \n");


scanf("%d", &B);

sum = add(A, B);


printf("Sum of Numbers %d + %d = %d", A ,B ,sum);

return 0;
}

Q6 C Define storage class explain the different storage classes supported by c


Answer Refer Question 6 A from MODEL QUESTION PAPER SET 1

m
Q7 A How 2D array is represented in memory. Explain with suitable example.
Answer Refer Question 7 B from MODEL QUESTION PAPER SET 1

Q7 B Develop a C program to sort the given set of N numbers using bubble sort

co
Answer Refer Question 5 C from MODEL QUESTION PAPER SET 1

Q 7 C What are strings? Mention the reading strings and writing strings along with
their Syntax
e.
In C programming, a string is a sequence of characters terminated with a null character \0.

For example:
dg
char c[] = "c string";
When the compiler encounters a sequence of characters enclosed in the double quotation
marks, it appends a null character \0 at the end by default.

How to declare a string?


Here's how you can declare strings:
ue

char s[5];

String Declaration in C
vt

Here, we have declared a string of 5 characters.

How to initialize strings?


You can initialize strings in a number of ways.
char c[] = "abcd";

char c[50] = "abcd";

char c[] = {'a', 'b', 'c', 'd', '\0'};

char c[5] = {'a', 'b', 'c', 'd', '\0'};


Program to read and display string

#include <stdio.h>
int main()

m
{
char name[30];
printf("Enter name: ");
gets(name); // read string
printf("Name: ");

co
puts(name); // display string
return 0;
}

Q 8 A Develop a C program to implement matrix multiplication and validate the


rules of multiplication e.
Answer Refer Question 8 C from MODEL QUESTION PAPER SET 1

Q8 B With a neat diagram, Explain three dimensional array write a C program to


dg
read and display 2x2x2 array

Answer Refer Question 7 C from MODEL QUESTION PAPER SET 1

Q8 C Develop a C program to print the following pattern.


ue

H
HE
HEL
HELL
HELLO
vt

HELLO
HELL
HEL
HE
H
#include<stdio.h>
void main()
{
int x,y;
static char str[]="HELLO";
for(x=0; x<5; x++)
{
y=x+1;
printf("%-5.*s\n",y,str);
}
for(x=4; x>=0; x--)
{
y=x+1;
printf("%-5.*s\n",y,str);
}

m
}

Output
H

co
HE
HEL
HELL
HELLO
HELLO
HELL
HEL
HE
H
e.
dg
Q9 A What is a pointer? Discuss pointer arithmetic with suitable code

Pointers (pointer variables) are special variables that are used to store addresses of other
variable rather than values.
The pointer to a variable should have the same type as the variable it is points to.
Pointer Syntax
ue

Here is how we can declare pointers.


int *p;

Assigning addresses to Pointers


Let's take an example.
vt

int *pc, c;
c = 5;
pc = &c;

#include <stdio.h>
int main ()
{
int a = 10, b=20;
int *ptr1, *ptr2;
ptr1 = &a;
ptr2 = &b;

printf ("Pointer ptr1 before Increment: ");


printf ("%p \n", ptr1);
ptr1++;
printf ("Pointer ptr1 after Increment: ");
printf ("%p \n", ptr1);
printf ("Pointer ptr2 before Decrement: ");
printf ("%p \n", ptr2);

m
ptr2--;
printf ("Pointer ptr2 after Decrement: ");
printf ("%p \n", ptr2);
return 0;
}

co
Q9 B Using suitable code, Discuss the working of the following string functions
i Strcat ii. Strlen iii. Strstr iv. Strcmp
e.
The strlen() function is used to find the length of a string
The strcat() function is used to concatenate two strings
The strcmp() function is used to compare two strings.
dg
#include <stdio.h>
#include <string.h>

int main()
{
char name[50] = "santosh";
char last_name[30]="Patil";
ue

int length = strlen(name);


char string1[] = "apple";
char string2[] = "banana";
int result = strcmp(string1, string2);
vt

printf("The length of the string '%s' is %d\n", name, length);

strcat(name, last_name);
printf("The concatenated string is '%s\n", name);

if (result == 0)
{
printf("\nThe two strings are equal");
}
else
{
printf("\nString are not equal");
}
return 0;
}

The strstr() function is used to search for a substring in a string.

m
#include <stdio.h>
#include <string.h>
int main()
{

co
char string1[] = "The quick brown fox jumps over the lazy dog";
char string2[] = "brown";
char *result = strstr(string1, string2);

if (result == NULL)
{

}
else
e.
printf("Substring not found");

{
dg
printf("Substring %S found ", string2);
}
return 0;
}
ue

Q9 C Develop a C program to concatenate two strings without using built-in function.


#include<stdio.h>
void main(void)
{
vt

char str1[25],str2[25];
int i=0,j=0;
printf("\nEnter First String:");
gets(str1);
printf("\nEnter Second String:");
gets(str2);
while(str1[i]!='\0')
i++;
while(str2[j]!='\0')
{
str1[i]=str2[j];
j++;
i++;
}
str1[i]='\0';
printf("\nConcatenated String is %s",str1);
}

OUTPUT

m
Q10 A Develop a program using pointers to compute the Sum, Mean and Standard
deviation of elements stored in an array of N real numbers.

co
Refer Lab program number 10

Q10 B Define structure? How structure is declared and initialize.


e.
Structure in C is a user-defined data types, a structure is a collection of variables of different
data types under a single name.

Structures (also called structs) are a way to group several related variables into one place.
dg
Each variable in the structure is known as a member of the structure.

Defining a structure
struct keyword is used to define a structure.
Syntax
struct [structure_tag]
ue

{
//member variable 1
//member variable 2
//member variable 3
...
}[structure_variables];
vt

Example
struct Student //structure tag name-Student
{
char Name[30];
char USN[11];
int Marks;
}s1,s2; //s1,s2 variables of structure
/*initilalize
struct Student s1={“ajay”,”3RB22CS001”,65} ;

struct Student s2;


s2.name=”amit”;
s2.USN=”3RB22CS002”;
s2.Marks=75;

s2 variable for structure to access the member of structure we use DOT operator.

m
Q10 C Develop a C program to implement a structure read, write and compute average
marks and the students scoring above and below the average marks for a class

co
of N students

Answer Refer Question 9 B from MODEL QUESTION PAPER SET 1

e.
dg
ue
vt

You might also like