0% found this document useful (0 votes)
8 views39 pages

2 Marks, Computer Programming - C

The document discusses problem solving in programming, emphasizing its importance for breaking down complex tasks and ensuring program efficiency. It covers key concepts such as algorithms, flowcharts, pseudocode, and error types in programming, along with their definitions and examples. Additionally, it highlights the features and significance of the C programming language, including its general-purpose nature and close interaction with computer hardware.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
0% found this document useful (0 votes)
8 views39 pages

2 Marks, Computer Programming - C

The document discusses problem solving in programming, emphasizing its importance for breaking down complex tasks and ensuring program efficiency. It covers key concepts such as algorithms, flowcharts, pseudocode, and error types in programming, along with their definitions and examples. Additionally, it highlights the features and significance of the C programming language, including its general-purpose nature and close interaction with computer hardware.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF or read online on Scribd
1 TWO MARKS QUESTION AND ANSWER What is problem solving in programming? Problem solving is the process of identifying a problem, designing a Solution, and implementing it in code. It involves logical thinking and step-by-step analysis This ensures efficiency and correctness of the program. Why is problem solving important for programmers? It helps in breaking down complex tasks into smaller steps. This makes it easie, to implement and debug code. Good problem solving saves time and avoids errors, What are the three main components of a problem analysis chart? A PAC consists of Input, Process, and Output. Input is the data provided, Process is the logic applied, and Output is the result. It helps break problems into simple sections. Give advantages of a problem analysis chart. It simplifies complex problems into smaller parts. This makes the logic easier to understand and implement. It also reduces chances of missing key details. What is an algorithm? An algorithm is defined as a collection of unambiguous instructions which are executed in a specific sequence to produce an output in a finite amount of time for a given set of input data. Write properties of a good algorithm. e Precision — the steps are precisely stated or defined. e Uniqueness — results of each step are uniquely defined and only depend on the input and the result of the preceding steps. e — Finiteness — the algorithm always stops after a finite number of steps. e Input — the algorithm receives some input. e Output — the algorithm produces some output. Give one real-life example of an algorithm. Making tea is an algorithm: Boil water > Add tea -> Add sugar/milk > Serve. It follows a clear sequence of steps. This ensures the same result each time. 8. Differentiate between flowchart and pseudocode. Flowchart Pseudocode A graphical representation of an algorithm using symbols. Uses standard'symbols such as rectangles, ovals, and diamonds. A textual representation of an algorithm in plain English-like statements. |} Uses structured keywords like IF, WHILE, FOR, etc. | Easy to understand visually, even by non- programmers. Easier to write and edit quickly without drawing. Difficult to modify if changes are frequent. Easy to modify as it is text-based. Best for visualizing the overall flow of a program. Best for focusing on program logic before coding. 9. Why is pseudocode used? Pseudocode helps in focusing on logic without syntax issues. It can be easily read by programmers and non-programmers. Later, it is converted into an actual program. 10. Mention any two advantages of a flowchart. A flowchart provides a visual understanding of program flow. It uses standard symbols like rectangles and diamonds. This makes it easier to follow the logic. i. Which function is mandatory in,every C program? The main() function is mandatory in every C program. It is the entry point where execution begins. Without it, the program cannot run. 12, Where are global variables declared in a program? Global variables are declared outside all functions. They can be accessed from any function in the program. This allows data sharing across multiple functions. 13, What are the stages of program execution in C The stages are Editing + Compiling > Linking —> Loading — Execution. Editing writes the code, compiling converts it to object code. Linking combines libraries, then program executes. a 14, What is the role of a compiler? A compiler converts source code into machine [Link] checks syntax errors durin, the process. This ensures the code can be executed by the computer. 15. Differentiate between interactive and script mode. L Interactive Mode Script Mode Code is executed line by line Code is written in a file and executed later, immediately. Useful for testing small code snippets. | Useful for large programs and reusability, Does not save code permanently. Code is saved and can be reused multiple times. 16. 17. Which mode is best for-small code testing? Interactive mode is best for testing small snippets. It allows immediate execution and quick feedback. This is useful for beginners and debugging. Differentiate between Compilation and Execution. Compilation Execution The process of converting source code into object/machine code. The process of. running the compiled executable program. Performed by a compiler before Performed by the operating system after execution, “ts linking and loading. Detects syntax errors, May produce logical or runtime errors. 18. Why are comments used in programming? Comments improve the teadability of code. They explain the purpose of different Parts of a program. Compilers ignore comments during execution. 19. How do you write a single-line and a multi-line comment in C? Single-line comments are written using //Everything after // on that line is ignored. They are useful for short explanations, Multi-line comments are written using /* ., /.They can span across many lines of explanation. They are helpful for documentation within code. 20. What is indentation in Programming? Indentation means proper spacing and ali gnment of code. It makes programs readable and structured. Though not requit red in C, it is good practice. 21. What is a syntax error? A syntax error occurs when code violates language rules. For example, missing a semicolon in C, It is detected at compile time. #include int main() { printf(“Hello, World!”) // Missing semicolon return 0; } 22, What is a logical error? A logical error is when the program runs but gives wrong results, It is caused by incorrect logic in the code. Such errors are harder to detect. #include int main( { int length = 10, breadth = 5; int area; // Logical Error: Using + instead of * area = length + breadth; printf(“Area of rectangle = %d\n”, area); return 0; 3 23. Give one example of a runtime error. Di sion by zero is a runtime error. It occurs while the program is executing. Such errors may cause program crashes. #include int main( { int a= 10, b=0; int result; // Runtime Error: Division by zero result = a/b; printf(“Result = %d\n”, result); return 0; } 24. What is the use of error messages? Error messages help programmers identify mistakes in code. They show what type of error occurred and where. This makes debugging faster and easier. 25. Compare all three error types Syntax, Runtime, and Logical Errors, Aspect Syntax Error Runtime Error Logical Error Meaning "| Mistakes in the Errors that occur while}Errors in logic that Biv tules/grammar of a_|the program [Link] output evey programming though program runs, language. Detection | Detected during Detected during/Detected only by Time compilation. program execution. —_| checking Program outpyt Cause Wrong use of Invalid operations like|Incorrect algorithm on keywords, symbols, |division by zero, file wrong formula used, or structure. not found. | Example _| Missing semicolon Dividing a number by Using + instead of * in} in C: zero. area calculation. printf(“Hello”) 26. Who invented C Language? 27, 28. Dennis Ritchie in 1972 developed a new language by inheriting the features of both BCPL and B and adding additional features, He named the language as just C. Why C Language? C is one of the high level languages. It is a general means it can be used to write programs of any sort. List the features of C Languages? In C one can write programs like that of hi BASIC, FORTRAN etc. as well as it inner workings of the computer. purpose language, which igh level languages as in COBOL, Permits very close interaction with the It is a. general purpose Programming language. It is usually called syste Programming language but equally suited to writing a variety of applications: Functions may be predefi: It supports various data types basic types, structures, unions or pointers. It follows the programming style based on fundamental control flow constructions for structured programming ined or user defined and they may return values of

You might also like