0% found this document useful (0 votes)
6 views5 pages

Google Docs Me

The document discusses programming languages, focusing on C as a middle-level language that combines low-level and high-level features. It covers various programming concepts such as procedural-oriented programming (POP) vs. object-oriented programming (OOP), C operators, user-defined functions, loops, and conditional statements. Additionally, it provides examples and explanations of algorithms, flowcharts, and the characteristics of good programming practices.

Uploaded by

thebeamis8
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)
6 views5 pages

Google Docs Me

The document discusses programming languages, focusing on C as a middle-level language that combines low-level and high-level features. It covers various programming concepts such as procedural-oriented programming (POP) vs. object-oriented programming (OOP), C operators, user-defined functions, loops, and conditional statements. Additionally, it provides examples and explanations of algorithms, flowcharts, and the characteristics of good programming practices.

Uploaded by

thebeamis8
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/ 5

C

Contd..1​ Q2. Why C is called middle-level language?


Q1. Define programming languages. Compare ​ Explain. (4)?
OOP and POP. Why C is called middle-level POP (Procedural-Oriented Programming): 1. ​
language? Explain.​ Based on functions and procedures, following a ANS: C as a Middle-Level Language:
​ step-by-step approach. 2. Does not provide data C is called a middle-level language because it
ANS: Programming Language: A programming hiding, making data vulnerable. ​ combines the features of both low-level and
language is a set of instructions used to 3. Lacks built-in support for code reusability; high-level languages.
communicate with a computer to perform specific functions must be rewritten. ​
tasks. It defines syntax and semantics for writing 4. Has a top-down approach, making 1. **Low-Level Features:** C provides direct
programs. Examples include C, Java, Python, modifications more difficult. ​ access to memory using pointers, supports
and JavaScript.​ 5. Functions depend on each other, reducing bitwise operations, and allows manipulation of
OOP (Object-Oriented Programming): ​ modularity. ​ hardware, similar to assembly language.
1. Based on objects and classes, focusing on 6. Uses global data that can be accessed by any 2. **High-Level Features:** C has structured
real-world entities. ​ function, increasing the risk of errors. 7. programming, functions, and libraries, making it
2. Uses encapsulation to protect data from Examples include C, Pascal, and Fortran. ​ easy to write complex programs like in high-level
unauthorized access. ​ languages.
3. Supports inheritance, allowing code reuse and 3. **Portability:** C programs can run on different
reducing redundancy. ​ hardware with minimal modification, bridging the
4. Follows a modular approach, making the gap between machine-dependent low-level
program easy to modify and extend. ​ languages and machine-independent high-level
5. Uses polymorphism, allowing the same languages.
function to operate differently based on the 4. **Balance of Control and Simplicity:** C gives
object. ​ programmers control over system resources
6. Implements abstraction, hiding complex while maintaining readability and efficiency,
implementation details from the user. ​ making it suitable for both system programming
7. Examples include Java, C++, and Python (like operating systems) and application
development.

Q3. Define C operators and their need in Contd..3​ Q6. Explain characteristics of good
programming. Also, explain types of C 2. **Relational Operators:** Compare values and algorithms and develop an algorithm and
operators with syntax and examples. (1+3+6)​ return true (1) or false (0). flowchart to calculate the sum of N natural
​ Syntax: `if(a > b) { ... }` numbers. ​
ANS: C Operators: Operators in C are symbols Example: `==`, `!=`, `>`, `<`, `>=`, `<=` ​ ​
that perform operations on variables and values. ANS: ​
They are essential for arithmetic calculations, 3. **Logical Operators:** Used for logical Characteristics of a Good Algorithm:
logical decisions, comparisons, and memory expressions. 1. **Well-Defined Input and Output:** It should
manipulation in programming. Syntax: `if(a > 0 && b > 0) { ... }` take valid input and produce the correct output.
Need for Operators: Example: `&&` (AND), `||` (OR), `!` (NOT) 2. **Finite Steps:** It must complete execution in
1. **Performing Arithmetic Operations** – Used a limited number of steps.
for calculations like addition, subtraction, 4. **Bitwise Operators:** Perform bit-level 3. **Unambiguous:** Each step should be clear
multiplication, etc. operations. and precise.
2. **Decision Making** – Comparison and logical Syntax: `int result = a & b;` 4. **Efficient:** Should use minimal time and
operators help in conditions and loops. Example: `&`, `|`, `^`, `<<`, `>>` resources.
3. **Memory and Bit Manipulation** – Operators 5. **Independent:** It should be
like bitwise and pointer operators help in 5. **Assignment Operators:** Assign values to language-independent and follow a logical
system-level programming. ​ variables. sequence.
Types of C Operators: Syntax: `a += 5;` Algorithm to Calculate the Sum of N Natural
1. **Arithmetic Operators:** Used for Example: `=`, `+=`, `-=`, `*=`, `/=`, `%=` Numbers:
mathematical operations. 1. Start
Syntax: `int sum = a + b;` 6. **Increment & Decrement Operators:** 2. Input N
Example: `+`, `-`, `*`, `/`, `%` Increase or decrease a value by 1. 3. Initialize sum = 0
Syntax: `a++;` 4. For i = 1 to N, add i to sum
Example: `++` (increment), `--` (decrement) 5. Print sum
6. Stop

Q.5 Explain Entry control and Exit control Contd..5​ Contd..6 ​


loops. Write a program to calculate the sum of ​ Flowchart:
digits of an integer entered by the user. (4+6) int i = 1; +----------------+
​ do { | Start |
ANS: Entry Control and Exit Control Loops: printf("%d ", i); +----------------+
|
Loops in C are used to execute a block of code i++; v
multiple times based on a condition. } while(i <= 5); +----------------+
| Input N |
+----------------+
1. **Entry Control Loop:** The condition is Program to Calculate Sum of Digits of an Integer:​ |
checked before executing the loop body. If the #include <stdio.h>​ v
condition is false initially, the loop will not execute int main() {​ +----------------+
| sum = 0, i = 1 |
even once. Examples: `for` loop, `while` loop. int num, sum = 0, digit;​ +----------------+
Example: printf("Enter an integer: ");​ |
```c scanf("%d", &num);​ v
+----------------+
int i = 1; while(num != 0) { ​ | i <= N ? |
while(i <= 5) { digit = num % 10; // Extract last digit​ +----------------+
printf("%d ", i); sum += digit; // Add digit to sum​ / \
i++; / \
num /= 10; // Remove last digit​ v v
} }​ +----------------+ +----------------+
printf("Sum of digits: %d", sum​ | sum = sum + i | | Print sum |
2. Exit Control Loop: The condition is checked |i=i+1 | +----------------+
return 0;​ +----------------+ |
after executing the loop body at least once. Even }​ v
if the condition is false, the loop will execute Example Output:​ +----------------+
once. Example: do-while loop. Enter an integer: 456 ​ | Stop |
+----------------+
Example: Sum of digits: 15
Q.4 Explain types of user-defined functions Contd..4​ Q.7 What are conditional and branching
and write a program to display the factorial of int getNumber() { statements? Explain types of conditional and
a number provided by the user using a return 10; branching statements with syntax, flow, and
examples.
function. (4+6) }​
ANS: Conditional and Branching Statements:
​ Function with Arguments and Returns a
Conditional and branching statements are used
ANS: Types of User-Defined Functions: Value: Takes input and returns a result.​
to execute different blocks of code based on
In C, user-defined functions allow modular Example:​
certain conditions, allowing decision-making in a
programming by dividing a program into smaller int add(int a, int b) { ​
program. Types of Conditional and Branching
functions for better readability and reusability. return a + b; ​
Statements: 1. **if Statement:**
}​
Used to execute a block of code if the condition
1. **Function with No Arguments and No Return Program to Display Factorial of a Number:​
is true. Syntax:
Value:** Performs a task but does not take input #include <stdio.h>​
if(condition) {
or return output. int factorial(int n) {​
// code to be executed if condition is true
Example: if(n == 0 || n == 1) ​
} Flow: If the condition is true, execute the
void greet() { return 1; ​
block; if false, skip.
printf("Hello, User!"); return n * factorial(n - 1); ​
Example:
} }​
if(a > b) {
​ int main() {​
printf("a is greater than b"); } ​
Function with Arguments but No Return int num;​
2. **if-else Statement:**
Value: Takes input but does not return a value.​ printf("Enter a number: ");​
Executes one block if the condition is true and
Example: scanf("%d", &num​
another block if false.
void square(int num) { printf("Factorial of %d is %d", num,
Syntax:
printf("Square: %d", num * num); factorial(num));​
if(condition) {
}​ return 0;​
// code if true
Function with No Arguments but Returns a } OUTPUT: Enter a number: 5
} else {
Value: No input, but returns a result. Factorial of 5 is 120
// code if false
Example:
}

Contd… 7 Flow: If the condition is true, execute


the first block, else execute the second.
Example:
if(a > b) {
printf("a is greater");
} else {
printf("b is greater");
} 3. **else-if Statement:**
Used when there are multiple conditions to
check.
Syntax:
if(condition1) {
// code if condition1 is true
} else if(condition2) {
// code if condition2 is true
} else {
// code if all conditions are false
} Flow: Checks the conditions sequentially and
executes the corresponding block.
Example:
if(a > b) {
printf("a is greater");
} else if(a == b) {
printf("a and b are equal");
} else {
printf("b is greater");
}

You might also like