pic practical slip Answers
pic practical slip Answers
#include <stdio.h>
Int main() {
Return 0;
}
Task 2.1: Algorithm & Flowchart
Algorithm:
1. Start
6. Stop
Flowchart Symbols:
Input/Output: Parallelogram
Process: Rectangle
Decision: Diamond (Draw basic flow using these for the above algorithm)
Five symbols:
Start/End – Oval
Input/Output – Parallelogram
Process – Rectangle
Decision – Diamond
Connector – Circle
Slip 2
#include <stdio.h>
#define PI 3.1416
Int main() {
Scanf(“%f”, &radius);
Area = PI * radius * radius;
Circumference = 2 * PI * radius;
Return 0;
Algorithm:
1. Start
2. Read radius
3. Calculate area = π × r²
4. Calculate circumference = 2 × π × r
6. Stop
Keywords: Reserved words in C (e.g., int, return, if, else) which have fixed meanings.
Slip 3
Task 1: Program to check leap year
#include <stdio.h>
Int main() {
Int year;
Scanf(“%d”, &year);
Else
Return 0;
Algorithm:
1. Start
2. Read year
3. If year divisible by 4 and not 100 or divisible by 400, it’s a leap year
4. Print result
5. Stop
Relational operators: Compare values (e.g., ==, !=, <, >, <=, >=)
Logical operators:
&& (AND)
|| (OR)
! (NOT)
Slip 4
#include <stdio.h>
#include <string.h>
int main() {
scanf("%s", str);
len = strlen(str);
flag = 0;
break;
if(flag)
else
return 0;
Algorithm:
1. Start
2. Read a string
6. Stop
Flowchart: Use process blocks for reverse and compare, and a decision block for checking
equality.
for
while
do-while
int i = 1;
while (i <= 5) {
printf("%d\n", i);
i++;
---
Slip 5
Task 1: Program to find greatest of 3 numbers using conditional operator
#include <stdio.h>
int main() {
int a, b, c, max;
return 0;
Algorithm:
1. Start
2. Read 3 numbers
4. Display result
5. Stop
while:
while (condition) {
// body
do...while:
do {
// body
} while (condition);
---
Slip 6
#include <stdio.h>
int main() {
char ch;
if(ch=='a'||ch=='e'||ch=='i'||ch=='o'||ch=='u'||
ch=='A'||ch=='E'||ch=='I'||ch=='O'||ch=='U')
else
return 0;
Algorithm:
1. Start
2. Read character
5. Stop
Task 2.2: Difference between while and do...while | Feature | while | do...while
| |-----------------|--------------------------|------------------------------| | Condition Check | Before loop
body | After loop body | | Execution | May never execute | Executes at least
once | | Syntax | while (cond) {} | do { } while (cond); |
---
Slip 7
#include <stdio.h>
Int main() {
Float percentage;
Scanf(“%f”, &percentage);
Printf(“Grade: Distinction\n”);
Else
Printf(“Grade: Fail\n”);
Return 0;
1. Start
2. Input percentage
4. Display grade
5. Stop
// loop body
Example:
Printf(“%d\n”, i);
Slip 8
#include <stdio.h>
Int main() {
Scanf(“%d”, &num);
While(num != 0) {
Sum += digit;
Num /= 10;
Return 0;
Algorithm:
1. Start
2. Input number
3. Initialize sum = 0
4. While number is not 0:
Digit = number % 10
Number = number / 10
5. Print sum
6. Stop
Flowchart: Use loop and process blocks to extract and add digits
Multidimensional array: Array with more than 2 dimensions (e.g., int a[2][3][4];)
Slip 9
#include <stdio.h>
Int main() {
Int n, t1 = 0, t2 = 1, next;
Scanf(“%d”, &n);
Printf(“%d “, t1);
Next = t1 + t2;
T1 = t2;
T2 = next;
Return 0;
Algorithm:
1. Start
3. Initialize t1 = 0, t2 = 1
4. Loop from 1 to n:
Print t1
Next = t1 + t2
T1 = t2
T2 = next
5. Stop
Switch(expression) {
Case value1:
// code
Break;
Case value2:
// code
Break;
Default:
// code
Slip 10
#include <stdio.h>
int main() {
scanf("%d", &num);
return 0;
Algorithm:
1. Start
2. Input number
3. Initialize fact = 1
5. Print factorial
6. Stop
In call by value, the actual value is passed and changes do not reflect back.
Example:
void display(int x) {
x = x + 10;
printf("Inside function: %d\n", x);
int main() {
int a = 5;
display(a);
return 0;
---
Slip 11
#include <stdio.h>
int main() {
scanf("%d", &a[i]);
temp = a[i];
a[i] = a[j];
a[j] = temp;
return 0;