Unit 1 - POP Question Bank
Unit 1 - POP Question Bank
A computer is an electronic device which basically performs five major operations which
includes:
1) accepts data or instructions (input)
2) stores data
3) process data
4) displays results (output) and
5) controls and co-ordinates all operations inside a computer
• Input: This is the process of entering data and instructions into the computer. Different input
devices such as mouse, keyboard, scanner and trackball can be used to enter the instructions.
It is the responsibility of the input device to convert the input data into binary code.
• Storage: This is the process of saving data and instructions permanently in the computer such
that it can be used for processing. There are 2 types of storage areas
1. Primary storage (Main memory): This area stores data, intermediate results and
recently generated results that
are currently being worked on.
⮚ The storage area that is directly accessible by the CPU at very high speed.
⮚ It is very expensive, limited capacity and volatile.
⮚ Eg : Random Access memory
2. Secondary Storage (Auxiliary Memory): this area stores the data that is not
accessed frequently (as compared to the data in primary storage.
⮚ It is a non-volatile memory medium that preserves data until and unless it has
been deleted or overwritten.
⮚ It supplements the limited storage capacity of primary memory
⮚ Eg : CD , Hard disk drives, Magnetic disk
• Input: This is the process of entering data and instructions into the computer. Different
input devices such as mouse, keyboard, scanner and trackball can be used to enter the
instructions. It is the responsibility of the input device to convert the input data into
binary code.
• Storage: This is the process of saving data and instructions permanently in the computer
such that it can be used for processing. There are 2 types of storage areas
1. Primary storage (Main memory): This area stores data, intermediate results and
recently generated results that
are currently being worked on.
⮚ The storage area that is directly accessible by the CPU at very high speed.
⮚ It is very expensive, limited capacity and volatile.
⮚ Eg : Random Access memory
2. Secondary Storage (Auxiliary Memory): this area stores the data that is not
accessed frequently (as compared to the data in primary storage.
⮚ It is a non-volatile memory medium that preserves data until and unless it
has been deleted or overwritten.
⮚ It supplements the limited storage capacity of primary memory
⮚ Eg : CD , Hard disk drives, Magnetic disk
Known as main memory or internal memory Known as auxiliary memory or External memory
Eg : RAM, ROM , Cache, EPROM Eg: HDD , CD, DVD ,Flash drives
CPU directly accesses data CPU does not directly accesses data
Power cut causes loss of data Power cut does not cause loss of data
Flowcharts
d. Graphical or symbolic representation of a process.
e. Helps user to visualize the logic of the process which helps them to understand
the process better , find flaws , bottlenecks.
Pseudocodes
f. Compact and informal high level description of an algorithm
g. Helps user to focus on the logic of the algorithm without worrying about the
details of language syntax.
h. An ideal pseudocode must be complete , descriptive such that it can be translated
to a programming language straightaway.
5. Define flowchart and list out the different symbols used to represent a flowchart.
Flowchart are the graphical representation of a solution to a particular problem, which
comes under the category of programming practices and techniques.
7. Write a C program to read Grade, CGPA, age and phone number and print the same as
the output.
#include<stdio.h>
void main()
{
char gr;
float cg;
int age,num;
printf("enter grade & cgpa : \n");
printf("enter age and phone num : \n");
scanf("%c%f",&gr,&cg);
scanf("%d%d",&age,&num);
printf("\n grade is : %c",gr);
printf("\n cgpa is : %f",cg);
printf("\n age is : %d",age);
printf("\n phone num is : %d",num);
}
8. Write a C program to perform basic arithmetic operations such as sum, difference,
product and quotient i)fixed values of operands ii)on user entered value of operands. Print
result of each operation . [Note: in divide assume no 0 is entered by the user]
#include <stdio.h>
int main() {
// Part i: Using fixed values
int a = 20, b = 10;
printf("Using Fixed Values:\n");
printf("a = %d, b = %d\n", a, b);
printf("Sum = %d\n", a + b);
printf("Difference = %d\n", a - b);
printf("Product = %d\n", a * b);
printf("Quotient = %d\n\n", a / b); // assuming b != 0
● Keywords
● Identifiers
● Constants
● Strings
● Operators
● Special Symbols
● char: Character
#include <stdio.h>
int main() {
int num;
scanf("%d", &num);
if(num % 2 == 0)
printf("Even");
else
printf("Odd");
return 0;
14. Write a C program that takes hours and minutes as input, and calculates the total number
of minutes.
#include <stdio.h>
int main() {
int hours, minutes, totalMinutes;
printf("Enter hours: ");
scanf("%d", &hours);
printf("Enter minutes: ");
scanf("%d", &minutes);
totalMinutes = (hours * 60) + minutes;
printf("Total minutes = %d\n", totalMinutes);
return 0;
}
15. Write a program that checks if a number is odd and divisible by 3 but not by 5.
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if ((num % 2 != 0) && (num % 3 == 0) && (num % 5 != 0))
{
printf("Number meets the condition.\n");
}
else
{
printf("Number does not meet the condition.\n");
}
return 0;
}
16. Predict the output
int x = 10, y;
y = x++ + ++x;
printf("x = %d, y = %d\n", x, y);
Solution:
● So y = 10 + 12 = 22, and x = 12
Output: x = 12, y = 22
Solution:
● a & b = 2 & 1 = 0 (binary: 10 & 01 = 00)
● b ^ a = 1 ^ 2 = 3 (01 ^ 10 = 11)
● 0 || 3 = 1
Output: 1
int a = 5, b = 10, c = 3;
int result = a + b * c - ++a / c;
printf("%d\n", result);
Solution:
● Step-by-step evaluation:
○ ++a makes a = 6
○ b * c = 10 * 3 = 30
○ ++a / c = 6 / 3 = 2
Output: 34
#include<stdio.h>
void main(){
int a=10,b=15,c=20,d=25;
printf("++a= %d \n",++a);
printf("++b=%d \n",++b);
printf("c++=%d \n",c++);
printf("d++=%d \n",d++);
printf("++a=%d \n",++a);
printf("++b=%d \n",++b);
printf("c++=%d \n",c++);
printf("d++=%d \n",d++);
}
Output
++a= 11
++b=16
c++=20
d++=25
++a=12
++b=17
c++=21
d++=26
#include<stdio.h>
int main()
{
int a = 1, b = 1, c;
c = a++ + b;
printf("%d, %d", a, b);
}
a) a = 1, b = 1
b) a = 2, b = 1 ←ANS
c) a = 1, b = 2
d) a = 2, b = 2
22.Writea C Program , taking two integer values as 10
and 2, demonstrate the integer arithmetic operations
by
Printing the following on the monitor
10+2=12
10-2=8
10*2=20
10/2=5
10 % 2 =0
#include<stdio.h>
void main(){
int c,d,e,f,g;
int a=10,b=2;
c = a+b;
d=a-b;
e=a*b;
f=a/b;
g=a%b;
printf("%d + %d= %d \n",a,b,c);
printf("%d-%d=%d\n", a, b,d);
printf("%d*%d=%d\n", a, b,e);
printf("%d/%d=%d\n", a,b,f);
printf("%d %% %d=%d\n", a,b,g);
OUTPUT
10 + 2= 12
10-2=8
10*2=20
10/2=5
10 % 2=0
Output
Enter the number of days:265
Months = 8
Days = 25
24.Program to show working of Relational operators.
#include<stdio.h>
void main()
{
int a=10,b=20;
printf("%d<%d =%d \n",a,b,a<b);
printf("%d>%d =%d\n",a,b,a>b);
printf("%d<=%d =%d\n",a,b,a<=b);
printf("%d>=%d =%d\n",a,b,a>=b);
printf("%d==%d =%d\n",a,b,a==b);
printf("%d!=%d =%d\n",a,b,a!=b);
}
Output
10<20=1
10>20=0
10<=20=1
10>=20=0
10==20 = 0
10!=20 = 1
25.Program to show working of Relational operators.
#include<stdio.h>
void main()
{
int a=10,b=11,c=12,d;
d=(a<b)&&(c<b);
printf(" d = %d",d);
d= (a<b)||(c<b);
printf("\n d = %d",d);
}
Output
d=0
d=1
#include<stdio.h>
void main()
{
int a,b,c;
int result;
printf("enter the values of 3 numbers");
scanf("%d%d%d",&a,&b,&c);
result = (a>b && a>c)?a:(b>c)?b:c;
printf("%d is biggest ",result);
}
Output
enter the values of 3 numbers6
45
6
45 is biggest
27.Write a C program to find if a number is odd or
even using ternary operator
#include <stdio.h>
int main() {
int num;
printf("Enter an integer: ");
scanf("%d", &num);
(num % 2 == 0) ? printf("%d is even.\n",
num) : printf("%d is odd.\n", num);
return 0;
}
#include<stdio.h>
void main()
{
int a=60 ,b=13;
int c;
c=a&b;
printf("\n bitwise and : c= %d",c);
c=a|b;
printf("\n bitwise or : c=%d",c);
c=~a;
printf("\n bitwise complement : c=%d",c);
c=a ^ b;
printf("\n bitwise xor : c=%d",c);
c=a<<2;
printf("\n left shift : c=%d",c);
c=a>>2;
printf("\n right shift : c=%d",c);
}