0% found this document useful (0 votes)
3 views

Unit 1

Uploaded by

tanishqrajpatel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views

Unit 1

Uploaded by

tanishqrajpatel
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 13

Unit 1: Answers

1. What do you mean by programming language?


A programming language is a formal system of communication used to instruct
computers to perform tasks. Examples include Python, C, Java, and more.

2. Define program.
A program is a sequence of instructions written in a programming language that
performs a specific task.

3. Define flowchart? How many symbols are used in flowchart?


A flowchart is a diagrammatic representation of an algorithm or process. Common
symbols include oval (start/end), rectangle (process), diamond (decision), and arrows
(flowlines).

4. Explain symbols used in flowchart.

o Oval: Start or End

o Rectangle: Process

o Diamond: Decision

o Arrow: Flow direction

5. What is algorithm? Describe its properties.


An algorithm is a step-by-step procedure to solve a specific problem. Properties
include:

o Finiteness

o Definiteness

o Input/Output

o Effectiveness

o Generality

6. What is the use of decision-making symbol in flowchart?


It is used to depict a decision point that can result in different outcomes, leading to
alternative paths in the flowchart.

7. Algorithm and flowchart to find the area of a triangle.

o Algorithm:

1. Start

2. Input base (bbb) and height (hhh).

3. Compute area: Area=12×b×h\text{Area} = \frac{1}{2} \times b \times


hArea=21×b×h.

4. Output area

5. Stop
o Flowchart: Graphical depiction using input/output, process, and decision
symbols.

8. Algorithm and flowchart to find area of rectangle, square, and circle.

o Rectangle: Area=length×breadth\text{Area} = \text{length} \times


\text{breadth}Area=length×breadth

o Square: Area=side2\text{Area} = \text{side}^2Area=side2

o Circle: Area=π×radius2\text{Area} = \pi \times \text{radius}^2Area=π×radius2

9. Algorithm and flowchart to find the maximum number out of 2 numbers.

o Algorithm:

1. Start

2. Input two numbers (a,ba, ba,b).

3. Compare: If a>ba > ba>b, output aaa, else output bbb.

4. Stop

10. Algorithm and flowchart to check if a number is even or odd.

o Algorithm:

1. Start

2. Input number (nnn).

3. If n%2==0n \% 2 == 0n%2==0, output "Even"; otherwise, output "Odd".

4. Stop

Would you like me to detail Unit 2 next, or prioritize specific units/questions?

4o

You said:

unit 2

ChatGPT said:

Unit 2: Answers

1. Define:

o C Language: C is a general-purpose, procedural programming language


designed for system and application software.

o Datatype: Defines the type of data a variable can hold (e.g., int, float, char).

o Variable: A storage location in memory with a name that holds data.

o Keyword: Reserved words in C with predefined meanings (e.g., int, return).


o Constant: A value that doesn’t change during program execution (e.g., #define
PI 3.14).

o Token: The smallest unit of a program, such as keywords, identifiers, literals,


and operators.

o I/O Function: Input and output functions in C (e.g., scanf and printf).

o Character Set: The set of characters recognized by the language (letters, digits,
symbols).

2. What is C? Why is C called a mid-level programming language?


C is a procedural programming language. It is called mid-level because it combines the
features of high-level languages (easy-to-read syntax) and low-level languages (direct
hardware manipulation).

3. Features of the C language:

o Simplicity and efficiency

o Portability

o Rich library functions

o Low-level hardware access

o Modular programming

4. What is a preprocessor?
The preprocessor processes code before compilation. It handles directives like
#include, #define, and conditional compilation.e

5. What is a token? Types of tokens in C:

o Tokens are the smallest units in a C program.

o Types: Keywords, Identifiers, Constants, Operators, Strings, Punctuation.

6. What do you mean by header file? Write the name of any three header files.
A header file contains declarations for library functions and macros. Examples:

o #include<stdio.h>

o #include<math.h>

o #include<string.h>

7. Explain programming development steps:

1. Define problem

2. Design algorithm

3. Write source code

4. Compile and debug

5. Test and maintain


8. Structure of a C program:

Copy code

#include<stdio.h> // Header files

int main() { // Main function

printf("Hello, World!"); // Program body

return 0; // Return statement

9. Define variable. Describe naming rules.


A variable is a named memory location.

o Naming Rules:

▪ Must begin with a letter or underscore.

▪ Cannot use reserved keywords.

▪ No special characters.

10. What is variable? Restrictions on variable names:


Same as above. Restrictions: No spaces, special characters, or reserved keywords.

11. C program to print a value given by the user:

Copy code

#include<stdio.h>

int main() {

int num;

printf("Enter a number: ");

scanf("%d", &num);

printf("You entered: %d", num);

return 0;

12. Basic data types in C:

o int: Integer

o float: Floating point

o char: Character

o double: Double-precision float


13. Primitive, user-defined, and derived data types:

o Primitive: Basic types like int, char.

o User-defined: Structures, enums.

o Derived: Arrays, pointers.

14. Define operator. Types of operators:


Operators perform operations on data.
Types: Arithmetic, Relational, Logical, Bitwise, Assignment, Conditional,
Increment/Decrement.

15. Type conversion in C:


Converting one data type to another.

o Implicit: Automatically by the compiler.

o Explicit: Forced using casting, e.g., (float)x.

16. Type conversion examples:

o Implicit: int x = 10; float y = x;

o Explicit: float y = (float)x;

17. Use of assignment operators:


Used to assign values (=, +=, -=).

18. Difference between pre-increment and post-increment operators:

o Pre-increment: ++x increases before use.

o Post-increment: x++ increases after use.

19. Arithmetic operator precedence:


Operators like *, /, % have higher precedence than +, -.

20. Ternary operator:


Syntax: condition ? expr1 : expr2;
Example: int max = (a > b) ? a : b;

21. All operators in C with examples:


Examples:

o Arithmetic: +, -

o Relational: ==, !=

o Logical: &&, ||

22. Five operators in C:

o Arithmetic: *

o Relational: >

o Logical: &&
o Conditional: ?:

o Bitwise: &

23. Explain types of operators:


Covered in previous questions.

24. Relational, Logical, Conditional operators:

o Relational: Compare values.

o Logical: Combine conditions.

o Conditional: Ternary operator.

25. Assignment statement general form:


variable = expression;

26. Basic data types in C and their significance:

o int: Integers

o float: Decimal numbers

o char: Single characters

o double: Precision floats

27. C program to compute size of int, float, double, char:

Copy code

#include<stdio.h>

int main() {

printf("Size of int: %lu\n", sizeof(int));

printf("Size of float: %lu\n", sizeof(float));

printf("Size of double: %lu\n", sizeof(double));

printf("Size of char: %lu\n", sizeof(char));

return 0;

Let me know if you'd like me to continue with Unit 3 or need further clarifications.

4o

You said:

unit 3 unit 4 and unit 5

ChatGPT said:
Unit 3: Answers

1. What is decision-making? Why is it needed in C?


Decision-making enables a program to choose a particular path based on conditions. It
is crucial for implementing logic and handling dynamic scenarios.

2. What do you mean by conditional statements? List them.


Conditional statements allow the program to make decisions based on conditions.
Examples:

o if

o if-else

o else if

o switch

3. Explain any two conditional control statements with syntax and example:

o if-else:

Copy code

if (condition) {

// Code for true condition

} else {

// Code for false condition

Example:

Copy code

if (x > 0) printf("Positive");

else printf("Non-positive");

o switch:

Copy code

switch (variable) {

case value1: // Code

break;

case value2: // Code


break;

default: // Code

4. C program: Perform arithmetic operation using switch statement:

Copy code

#include<stdio.h>

int main() {

char op;

int a, b, result;

printf("Enter operator (+, -, *, /): ");

scanf(" %c", &op);

printf("Enter two numbers: ");

scanf("%d %d", &a, &b);

switch (op) {

case '+': result = a + b; break;

case '-': result = a - b; break;

case '*': result = a * b; break;

case '/': result = a / b; break;

default: printf("Invalid operator");

printf("Result: %d", result);

return 0;

5. Program to reverse an integer and check if palindrome:

Copy code

#include<stdio.h>

int main() {

int n, reverse = 0, temp, remainder;

printf("Enter a number: ");


scanf("%d", &n);

temp = n;

while (temp != 0) {

remainder = temp % 10;

reverse = reverse * 10 + remainder;

temp /= 10;

printf("Reversed Number: %d\n", reverse);

if (n == reverse) printf("Palindrome");

else printf("Not a Palindrome");

return 0;

6. Program to find the biggest of three numbers:

Copy code

#include<stdio.h>

int main() {

int a, b, c;

printf("Enter three numbers: ");

scanf("%d %d %d", &a, &b, &c);

if (a > b && a > c) printf("Largest: %d", a);

else if (b > c) printf("Largest: %d", b);

else printf("Largest: %d", c);

return 0;

Unit 4: Answers

1. Define array. Advantages and disadvantages:


An array is a collection of elements of the same data type stored at contiguous memory
locations.

o Advantages: Efficient data handling, ease of access using indices.

o Disadvantages: Fixed size, inefficient insertion/deletion.


2. Declare and initialize a 1D array:

Copy code

int arr[5] = {1, 2, 3, 4, 5};

3. Declare and initialize a 2D array:

Copy code

int arr[2][3] = {{1, 2, 3}, {4, 5, 6}};

4. Define string and explain string I/O functions:


A string is a sequence of characters terminated by a null character (\0).

o Input: scanf("%s", str)

o Output: printf("%s", str)

5. Explain string handling functions:

o strlen: Find length of a string.

o strcpy: Copy one string to another.

o strcmp: Compare two strings.

o strcat: Concatenate two strings.

6. Difference between char array and string literal:


A char array is mutable, while a string literal is immutable.

7. What is an array? Write its syntax:


An array is a collection of elements.
Syntax: datatype arrayName[size];

8. Declare a float array of size 5 and assign values:

Copy code

float arr[5] = {1.1, 2.2, 3.3, 4.4, 5.5};

9. Advantages of arrays:

o Access elements using indices.

o Reduces code size for large data sets.

10. What happens when accessing array beyond its dimension?


It leads to undefined behavior.

11. Creating a 2D array:

c
Copy code

int arr[3][3];

12. Example of 2D array usage:

Copy code

int arr[2][2] = {{1, 2}, {3, 4}};

13. Equating an array:


You cannot directly equate arrays. Use loops to copy elements.

14. Ways of initializing arrays:

o During declaration: int arr[3] = {1, 2, 3};

o Later assignment: Assign values individually.

15. Difference between 1D and 2D arrays:

o 1D: Single row/column of data.

o 2D: Rows and columns forming a matrix.

Unit 5: Answers

1. Define function with its syntax:


A function is a block of code that performs a specific task.
Syntax:

Copy code

return_type function_name(parameters) {

// Function body

2. Parts of a function:

o Function declaration

o Function definition

o Function call

3. Difference between function declaration and definition:

o Declaration: Prototype of the function.

o Definition: Contains actual code.


4. What is a function call?
A function call executes the code within a function.

5. Applications of recursive functions:

o Factorial calculation

o Fibonacci sequence generation

6. Difference between call by value and call by reference:

o Call by Value: Sends a copy of the variable.

o Call by Reference: Sends the actual variable address.

7. Scope of variable:
Scope defines the lifetime and accessibility of a variable in a program.

8. C function to find the square root of a number:

Copy code

#include<stdio.h>

#include<math.h>

int main() {

double num, result;

printf("Enter a number: ");

scanf("%lf", &num);

result = sqrt(num);

printf("Square root: %.2lf", result);

return 0;

9. User-defined function:
Functions created by users to perform specific tasks.

10. What is meant by library function?


Predefined functions in C (e.g., printf, sqrt).

11. No argument and no return value in a function:

Copy code

void display() {

printf("Hello, World!");
}

12. Difference between formal and actual parameters:

o Formal Parameters: Defined in function declaration.

o Actual Parameters: Passed during function call.

13. Explain recursive functions with example:

Copy code

int factorial(int n) {

if (n == 0) return 1;

return n * factorial(n - 1);

You might also like