Professional Documents
Culture Documents
PSP Set-1
PSP Set-1
*They used vacuum tubes for circuitry and magnetic drums for memory
*They were big in size and each computer used to occupy the entire room space
*various operations.
SecondGeneration:
*The transistors were the most important component which replaced vacuum tubes.
*The stored program concept was introduced which stores both data and program.
Third Generation:
*The Integrated circuits(IC) were the most important component.
*The transistors, diodes, resistors, and capacitors were integrated on a single chip.
*The high-level language was used like BASIC, C, C++, and JAVA.
*Memory capacity increased and a magnetic hard disk was used for the second generation.
*The third generation computers also had OS and computers could rum programs invoked by
multi-users.
Fourth Generation:
*With the help of LSI (Large Scale Integration) and VLSI (Very Large Scale Integration),
*OS has moved from MSDOS to GUI (Graphical User Interface) like windows.
Fifth Generation:
*Artificial Intelligence and the use of natural languages are the main features of this
generation.
Answer:-
Bit:-
The data are represented by the state of electronic switches. A switch with
ON state represents 1 and OFF state represents 0 (zero). These values which represent
Example:-In other words, the binary digits 1 and 0 are called bits. Thus,
2. Nibble:-
Example:
1001= nibble
3. Byte:-
Example:-
4. Word:-
Example:-
5. Kilobyte:-
Answer:-
Primary Memory:-
*The memory that is accessible directly by the CPU of a computer is called primary memory.
*This memory is part of the main computer system which is plugged into the motherboard
along with the CPU.
*This primary memory allows the CPU to store and retrieve data quickly.
CPU registers
Secondary Memory:-
*The memory that is not part of the computer’s main memory and which is not directly
connected to the CPU but connected to the motherboard through ports and connectors is
*In secondary memory, we can store all the data and programs permanently and can be moved
from one place to another place and can be connected to another computer.
*The data and instructions are loaded from secondary memory to main memory so that the CPU
Ex: floppy diskette, hard disk, CD-ROMs, magnetic tapes, Blu-ray disk, flash
Flash memory
2.B) Explain the various rules for forming identifier names. Give examples of valid and
Answer:-
*Identifier should contain only alphabets (A-Z), (a-z), numerals(0-9) and underscore (_)
*The identifier should start with alphabet or underscore, but not a numeric character
*The first 31 characters in an identifier are significant, the rest of characters are
neglected
int //keyword
Answer:-
#include<stdio.h>
int main() {
float radius, area;
scanf("%d", &radius);
return (0);
3.A) How similar and different while & for loops are? Give example
Answer:-
One similarity between while and for loop is that they both are entry controlled loops i.e.
they both will check the condition for true or false. If the condition is true then only the
#include<stdio.h>
#include<conio.h>
void main()
int i,n,m; /* i for loop counter, m is lower limit, n for lower limit */ clrscr();
printf("%5d",i);
getch();
Output:
10 20
10 11 12 13 14 15 16 17 18 19 20
3.C) Demonstrate the working of break and continue statement with a suitable example
Answer:-
Break and continue: break and continue are unconditional control constructs.
i. Break:-
This statement is useful to terminate a loop and transfer control out of
*break statement works with while, do….while, for, and switch statements.
*Note: If a break statement is used in the nested loops, the control will come out
When condition2 is true the loop gets terminated and control is transferred to
statement5 (which is outside the loop). Here we can observe that even though
void main( )
{
int i; for(i=1;i<=5;i++)
if(i==3)
*Output: 1 2
ii. Continue
loop body and to continue execution from the beginning of the loop.
void main()
int i; for(i=1;i<=5;i++)
Output: 1 2 4 5
Answer:-
Answer:-
IF-ELSE SWITCH
Which statement will be executed depending
Which statement will be executed is decided
upon the output of the expression inside if
by user.
statement.
the if-else statement uses multiple statements switch statement uses a single expression for
for multiple choices. multiple choices.
if-else statement test for equality as well as
switch statement test only for equality.
for logical expression.
if statement evaluates integer, character, the switch statement evaluates only character
pointer or floating-point type, or boolean type. or integer value.
the switch statement executes one case after
Either if statement will be executed or else
another till a break statement appears or the
the statement is executed.
end of the switch statement is reached.
If the condition inside switch statements does
If the condition inside if statements is false,
not match with any of the cases, for that
then by default the else statement is
instance the default statement is executed if
executed if created.
created.
It is difficult to edit the if-else statement if the It is easy to edit switch cases as they are
nested if-else statement is used. recognized easily.
4.C) List various commonly used format specifiers. Explain any two of them.
Answer:-
Answer:-
Two-Dimensional Arrays:
A list of items can be given one variable name using two subscripts and such a variable
is called a Two-dimensional array.
It consists of both rows and columns. Ex: Matrix.
Here is the general syntax for array declaration along with examples.
After array is declared, the next is storing values into an array is called initialization.
1. Compile-time initialization
2. Run-time initialization
3. Compile-time initialization:
Run time initialization is storing values in an array when the program is running or
executing.
The following example illustrates run time storing of values using scanf and for loop:
Example:
Answer:-
Definition of String :-
#include<stdio.h>
#include<string.h>
main(){
char s1[10],s2[10],s3[10];
printf("Enter String 1\n");
gets(s1);
printf("Enter String 2\n");
gets(s2);
printf("Before Swapping\n");
printf("String 1 : %s\n",s1);
printf("String 2 : %s\n",s2);
strcpy(s3,s1);
strcpy(s1,s2);
strcpy(s2,s3);
printf("After Swapping:\n");
printf("String 1 : %s\n",s1);
printf("String 2 : %s\n",s2);
}
output:-
Enter String 1
Bgmi
Enter String 2
Leaks
Before Swapping
String 1: Bgmi
String 2: Leaks
After Swapping:
String 1: Leaks
String 2: Bgmi
6.A) Write a C program to implement the Bubble sort technique (ascending order)
and trace
the program for the following input: 58 42 10 25 60.
Answer:-
#include<stdio.h>
void main()
{
int a[10], n, i, j, temp;
printf("Enter the number of elements\n");
scanf("%d", &n);
printf("Enter the array elements\n");
for(i=0; i<n; i++)
scanf("%d", &a[i]);
for(j=1; j<n;j++)
{
for(i=0;i<n;i++)
{
if(a[i]>a[i+1])
{
temp=a[i];
a[i]=a[i+1];
a[i+1]=temp;
}
}
}
printf("The sorted array is\t");
for(i=0; i<n;i++)
printf(“%d\t”,a[i]);
}
Output
Enter the number of elements 7
Enter the array elements 12 23 10 13 15 1 8
The sorted array is 1 8 10 12 13 15 23
Answer:-
The first is the dest, a string variable whose value is going to be changed.
The second is the source of the string literal or variable which is going to be copied to
the destination.
Case 1:
Answer:-
Following block diagram explains how functions are useful:Instead of writing entire program (to
add and subtract) within main( ) function we can write independent modules add( ) and
subtract( ) as shown:
7. B) What is recursion? Write a C program to computer factorial using recursion.
Answer:-
• All recursive functions have two elements each call either solves one part of the
problem or it reduces the size of the problem.
• The statement that solves the problem is known as the base case.
• The rest of the function is known as a general case.
#include<stdio.h>
int fact(int);
void main()
{
int n,res;
printf(“enter the number to find its
factorial\n”);
scanf(“%d”,&n);
res=fact(n);
printf(“factorial of %d=%d”,n,res);
getch();
}
int fact(int n)
{
if(n==0) return 1;
else
return (n*fact(n-1));
}
Answers:-
“Functions are independent program modules that are designed to carry out a
particular
task.”
3. Functions are once written can be reused in any other applications – Reusability is
enhanced
4. We can protect our data from illegal users—Data protection becomes easier
Answer:
Answer:-
Answer :
9. B) Define a structure by the name DoB consisting of three variable members dd,
mm, and yy
of type integer. Develop a C program that would read values to the individual
member and display the date in mm/dd/yy form.
Answer:-
#include <stdio.h>
struct student{
char name[30];
int rollNo;
struct dateOfBirth{
int dd;
int mm;
int yy;
}DOB; /*created structure varoable DOB*/};
int main()
{
struct student std;
return 0;
}
Out put:-
Answer:-
Example of Structure
struct student
{
int rollno;
char name[50];
string phone;
};
Example of Union
union Student {
char name[32];
int age;
string email;
};
Answer:-