0% found this document useful (0 votes)
14 views3 pages

C Programming Flowchart Examples

Uploaded by

rafid1216ahammad
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)
14 views3 pages

C Programming Flowchart Examples

Uploaded by

rafid1216ahammad
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

ICS

Drafted by Sadia Ahmmed

Draw a flowchart for the given problems:

1. Write a C program to accept two integers and check whether they are equal or not.
Input : 18 18
Expected Output :
Number 1 and Number 2 are equal

2. Write a C program to check whether a given number is even or odd.


Input: 13
Expected Output :
13 is an odd integer

3. Write a C program to check whether a given number is positive or negative.


Input : 5
Expected Output :
5 is a positive number

4. Write a C program to find the perimeter of a rectangle. Length and Width of the rectangle will be
provided by the user from the keyboard.

Sample Input Sample Output

5 10 30

12 36 96

5. Write a C program to find the largest of three numbers.


Input : 1 2 5
Expected Output :
The 3rd Number is the greatest

6. Write a C program where the user first inputs ‘q’ or ‘r’ If the input is q then find the quotient
from the division of two numbers and if the input is r then find reminder.
Sample Input Sample Output

q 5
32 6

r 1
63 2

7. Write a program that asks the user for an integer and then prints whether the number is even or
odd.

Sample Input Sample Output

7 odd

12 even

8. Write a program that asks the user for their age and then prints whether they are eligible to vote
(age 18 or older).

Sample Input Sample Output

Enter your age: 12 You are not eligible to vote.

Enter your age: 20 You are eligible to vote.

9. Write a C program to accept a coordinate point in an XY coordinate system and determine in


which quadrant the coordinate point lies.

Input : 7 9

Expected Output :

The coordinate point (7,8) lies in the First quadrant.

10. Create a calculator with 4 options. The user will input 2 numbers and a character like +, - , *
and / symbol. Based on the character input the program will complete the action of addition
subtraction multiplication or division and show result

Sample Input Sample Output


/ 5
32 6

+ 65
63 2

11. Write a C program to read temperature in centigrade and display a suitable message according
to the temperature state below:

Temp < 0 then Freezing

Temp 0-10 then Very Cold

Temp 10-20 then Cold

Temp 20-30 then Normal

Temp 30-40 then Hot

Temp >=40 then Very Hot

Input :

42

Expected Output :

Its very hot.

12. Write a program that asks the user for three integers and then prints the smallest of the three.

Sample Input Sample Output

Enter first number: 3 The smallest number is: 3


Enter second number: 9
Enter third number: 5

13. Swap two numbers

[Hint: use another variable?]

Sample Input Sample Output

a=2, b=3 a=3 b=2

Common questions

Powered by AI

A number is classified as even or odd based on its divisibility by 2. If a number divided by 2 results in a remainder of 0, it is classified as even. Conversely, if there is a remainder of 1, it is classified as odd. The programs use the modulus operator (%) to determine this divisibility by checking the remainder when the number is divided by 2 .

The program that checks voting eligibility accepts a single integer input representing the user's age and uses an if-else statement to determine if the age is 18 or older to print the eligibility status . In contrast, the program designed to find the largest of three numbers requires three separate integer inputs and employs chained conditional statements to compare the three values and determine the largest. This shows a difference in complexity as one deals with a single straightforward condition while the other one requires multiple evaluations to ascertain the greatest number .

By incorporating an area calculation to the existing perimeter calculation program, it demonstrates principles of program extensibility which include integrating additional functionality without disrupting existing ones. The program will accept the same inputs for length and width, and utilize them to compute and output both the perimeter and area. This showcases modularity, where existing inputs can be repurposed for multiple outputs, and thus exhibits the capability of the program to grow in functionality with minimal adjustment .

The temperature messaging program uses conditional statements to handle multiple scenarios based on temperature ranges. The program defines specific text messages based on precise temperature ranges: 1. Freezing for temperatures below 0. 2. Very Cold for temperatures from 0 to less than 10. 3. Cold for temperatures from 10 to less than 20. 4. Normal for temperatures from 20 to less than 30. 5. Hot for temperatures from 30 to less than 40. 6. Very Hot for temperatures 40 and above. These categories help classify the temperature into everyday language for user-friendly output . It demonstrates how conditions in programming can be tailored to output descriptive classifications based on the input values.

Control flow in the calculator program is crucial for handling different operations based on user input. By using conditional statements, the program selects the operation (+, -, *, /) that the user chooses and applies it to the two numbers provided. This ensures that only the appropriate arithmetic action is executed according to the operator input, allowing the program to deliver results dynamically and accurately for every possible valid user choice . Without proper control flow, the program might execute incorrect or multiple operations simultaneously, leading to erroneous outputs.

The program evaluates the quadrant by analyzing the signs of the x and y coordinates. It determines the quadrant according to the following conditions: - First quadrant if both x and y are positive. - Second quadrant if x is negative and y is positive. - Third quadrant if both x and y are negative. - Fourth quadrant if x is positive and y is negative . This approach accurately determines the quadrant for any non-zero coordinate point position, as quadrants are classically defined based on these sign characteristics.

Not handling division by zero in a calculator program can lead to runtime errors or crashes, as dividing by zero is undefined in mathematics and not supported in most programming environments. This can be mitigated by implementing a conditional check before performing a division operation, ensuring that the divisor is not zero, and displaying an error message or alternative action if zero is detected as the divisor. This proactive check prevents the program from attempting an invalid operation, thus enhancing its robustness and reliability .

Incorrect logical operators can lead to the program erroneously classifying a number's sign. Using the wrong operator (e.g., '<' instead of '>') could classify positive numbers as negative and vice versa. This would produce incorrect output and undermine the program's reliability. Using precise logical operators (e.g., '>', '>=', '<', '<=') ensures that conditions are evaluated correctly according to mathematical rules, maintaining the integrity of the output .

To optimize the process of finding the smallest number in larger datasets, the program could apply more efficient search algorithms like the divide-and-conquer strategy, which divides the dataset into smaller segments and finds the minimum recursively. This approach can be significantly faster than a linear search, especially with larger datasets, by reducing the total number of comparisons required. Additionally, utilizing data structures like heaps can minimize the computational complexity associated with finding the minimal elements .

The logic to check if two numbers are equal uses a simple comparison operation, where the program checks if the two numbers have the same value and then outputs the result based on this condition . Swapping two numbers involves modifying the state by assigning the numbers' values to each other using an auxiliary variable. An auxiliary variable temporarily holds one number's value while making the substitute assignments, which is more complex than a simple comparison .

You might also like