×
Time can be your best friend and your worst enemy depending on whether you use it or waste it.

# Note for Programming in C - C By Lakshmi S

• Programming in C - C
• Note
• 1178 Views
Lakshmi S
0 User(s)

#### Text from page-2

2. Naturalness: • Provide the data types, operators and syntax required to write programs in the specified application area. 3. Abstraction: • Group essential details and ignore other details. 4. Efficiency: • Occupy less memory space. • Fast execution. 5. Structuredness: • Provide facility to divide a problem into sub-problems and write separate sub-programs for them. 6. Compactness: • Provide facility to write compact programs. 7. Extensibility: • Provide facility to extend a program. _______________________________________________________________________________________ 3. Write the algorithm and draw the flowchart to find the product of the first n natural numbers. * Product of the First n Natural Numbers: Natural Numbers – 1, 2, 3 . . . n Algorithm: Begin Input n product  1 for i  1 to n do Begin product  product * i; End Output product End

#### Text from page-3

Flow Chart: Start Input n product = 1 for i = 1 to n True False product = product * i Output product End _______________________________________________________________________________________________ 4. Write the algorithm and draw the flowchart to find the factorial of a given number. * Note: This algorithm and flowchart is same as that of product of first n natural numbers. Factorial of a Given Number: n! = 1 * 2 * 3 … * n Algorithm: Begin Input n fact  1 for i  1 to n do Begin fact  fact * i; End Output fact End

#### Text from page-4

Flow Chart: Start Input n fact = 1 for i = 1 to n True False fact = fact * i Output fact End _______________________________________________________________________________________________ 5. Write the algorithm and draw the flowchart to find the largest of three numbers. * Largest of Three Numbers: Algorithm: Begin Input a, b, c if (a > b) then if (a > c) then Output else Output else if (b > c) then Output else Output End a c b c

#### Text from page-5

Flow Chart: Start Input a,b,c False True if (a > b)? False Output c if (b > c)? True Output b False if (a > c)? Output c True Output a End _______________________________________________________________________________________ 6. Explain the structure of a C program with an example. * Structure of a C Program: • General Structure of a C Program: Include Section Global Declaration Section main() { Local Declaration Section Statement Section } User-defined Function Section • Include Section: • In this section, header files are included. • Global Declaration Section: • In this section, global variables are declared. • main() Section: • Execution of the program starts from the main() function. • Local Declaration Section: • In this section, local variables used in main() function are declared. • Statement Section: • In this section, the C statements required to solve the program are written. • User-defined Function Section: • In this section, user-defined functions are written.