Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
4 views7 pages

Unit I

Uploaded by

saviourofdeers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views7 pages

Unit I

Uploaded by

saviourofdeers
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

PIC Unit 1 Answers

1. Use of Flowchart Symbols

 Oval (Terminator): Used to represent the start or end of a


flowchart.
 Rectangle (Process): Represents a process or instruction
to be executed.
 Diamond (Decision): Represents a decision point with
multiple outcomes.
 Parallelogram (Input/Output): Represents input to or
output from the system.

2. C Program for Addition & Multiplication of Two Integer


Numbers
#include <stdio.h>
#include <conio.h>

void main() {
int num1, num2, sum, product;
clrscr();

printf("Enter two integers: ");


scanf("%d %d", &num1, &num2);

sum = num1 + num2;


product = num1 * num2;

printf("Sum: %d\n", sum);


printf("Product: %d\n", product);

getch();
}

3. Flowchart for Checking Whether a Number is Prime

(Text-Based)
+------------------+
| Enter a number |
+--------+---------+
|
v
+------------------+
| Initialize flag |
+--------+---------+
|
v
+------------------------+
| Loop from 2 to n/2 |
| Check divisibility |
| if divisible set flag |
+--------+---------------+
|
v
+---------------------+
| Prime if flag unset |
| Not Prime otherwise |
+---------------------+

5. Definition of Algorithm

An algorithm is a finite sequence of well-defined instructions to


solve a problem or perform a task.

6. Flowchart Symbols with Labels

 Oval: Start/End
 Rectangle: Process
 Diamond: Decision
 Parallelogram: Input/Output

7. Algorithm and Flowchart to Print Even Numbers from 1


to 100

Algorithm:

1. Start
2. Initialize counter to 2
3. Print counter
4. Increment counter by 2
5. Repeat until counter > 100
6. Stop

Flowchart (Text-Based)
+----------------+
| Start |
+--------+-------+
|
v
+----------------+
| Counter = 2 |
+--------+-------+
|
v
+------------------+
| Print Counter |
+--------+---------+
|
v
+------------------+
| Counter += 2 |
+--------+---------+
|
v
+------------------+
| Counter > 100? |
+--------+---------+
| No
v
Yes
+------------------+
| End |
+------------------+

8. Algorithm to Check Divisibility by 5

1. Start
2. Read an integer number
3. If the number % 5 == 0, display "Divisible by 5"
4. Otherwise, display "Not Divisible by 5"
5. Stop
9. Flowchart for Checking Odd or Even Number
+----------------+
| Enter a number |
+--------+-------+
|
v
+------------------+
| num % 2 == 0? |
+--------+---------+
| Yes | No
v v
+-------------+ +--------------+
| Print Even | | Print Odd |
+-------------+ +--------------+

11. Flowchart for Finding the Largest of Three Numbers


+------------------------+
| Enter three numbers |
+--------+---------------+
|
v
+------------------------+
| Compare num1, num2, |
| and num3 |
+--------+---------------+
|
v
+------------------------+
| Print largest number |
+------------------------+

12. Flowchart for Addition of Two Numbers


+---------------------+
| Enter two numbers |
+--------+------------+
|
v
+---------------------+
| sum = num1 + num2 |
+--------+------------+
|
v
+---------------------+
| Print the sum |
+---------------------+

13. Importance of Flowchart

1. Helps visualize the steps in a process.


2. Simplifies debugging by clearly showing program flow.
3. Enhances communication among developers.
4. Provides documentation for future reference.

14. Algorithm to Determine Odd or Even

1. Start
2. Read an integer number
3. If number % 2 == 0, print "Even"
4. Else, print "Odd"
5. Stop

15. C Program to Check if a Number is Positive Integer


#include <stdio.h>
#include <conio.h>

void main() {
int num;
clrscr();

printf("Enter a number: ");


scanf("%d", &num);

if (num > 0) {
printf("The number is positive.\n");
} else {
printf("The number is not positive.\n");
}

getch();
}
16. Four Advantages of Flowchart

1. Easy to understand and explain complex processes


2. Simplifies program logic for developers
3. Reduces errors in program design
4. Useful for program documentation

17. C Program to Find Simple Interest


#include <stdio.h>
#include <conio.h>

void main() {
float principal, rate, time, interest;
clrscr();

printf("Enter Principal, Rate, and Time: ");


scanf("%f %f %f", &principal, &rate, &time);

interest = (principal * rate * time) / 100;

printf("Simple Interest: %.2f\n", interest);

getch();
}

18. C Program to Convert Fahrenheit to Centigrade


#include <stdio.h>
#include <conio.h>

void main() {
float fahrenheit, centigrade;
clrscr();

printf("Enter temperature in Fahrenheit: ");


scanf("%f", &fahrenheit);

centigrade = (fahrenheit - 32) * 5 / 9;

printf("Temperature in Centigrade: %.2f\n", centigrade);

getch();
}

You might also like