Professional Documents
Culture Documents
Set2 Solution
Set2 Solution
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.
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
co
{
Declaration part
Executable part
}
below
Example: #include<stdio.h>
OR
OR
m
void main( ) - main( ) function does not return any value
OR
co
- Subprogram Section: This section contains all the user defined functions that are
called in the main function.
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:
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.
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
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:
co
OR
Where v or v1, v2, v3…. are names of the variable and data type can be any of basic data
types.
OR
vt
age = 21;
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.
#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
Answer Refer syntax of switch Question 4 A from MODEL QUESTION PAPER SET 1
#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
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
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
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.
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
!
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
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
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
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
C allows you to define functions according to your need. These functions are known as
User-defined functions
#include <stdio.h>
ue
int main( )
{
int A, B, sum;
return 0;
}
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.
char s[5];
String Declaration in C
vt
#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;
}
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
int *pc, c;
c = 5;
pc = &c;
#include <stdio.h>
int main ()
{
int a = 10, b=20;
int *ptr1, *ptr2;
ptr1 = &a;
ptr2 = &b;
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
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;
}
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
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
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} ;
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
e.
dg
ue
vt