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

C PROGRAM LAB 2

The document is a lab report on C-Programming from Trinity International SS & College, detailing the author's learning experience and objectives related to loops in C. It covers the types of loops, including for, while, and do...while loops, along with their syntax and functionality. The conclusion emphasizes the importance of loops in programming for efficiency and code management.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views

C PROGRAM LAB 2

The document is a lab report on C-Programming from Trinity International SS & College, detailing the author's learning experience and objectives related to loops in C. It covers the types of loops, including for, while, and do...while loops, along with their syntax and functionality. The conclusion emphasizes the importance of loops in programming for efficiency and code management.
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

TRINITY INTERNATIONAL SS &COLLEGE

KATHMANDU, NEPAL
2024

Lab Sheet#6
C-PROGRAMMING

Lab date: 2081/ 09/ 21


Submission Date: 2081/ 09/28

Internal signature External signature


ACKNOWLEDGEMENT

I would like to express my sincere gratitude to Sanjay Phuyal Sir for his invaluable
guidance and support throughout the completion of this lab report on C-
Programming. His encouragement and advice greatly enhanced my understanding
of the topic and practical aspects of C-Programming

I would also like to extend my thanks to Trinity International College & SS for
providing the necessary resources and a conductive learning environment. I would
like to express my gratitude to all for helping me to learn C-PROGRAMMING. I
would like Mr. Sanjay Phuyal for giving this lab project and helping me
understand this topic better.

I am also grateful to my classmates for their teamwork and collaboration whenever


needed , which made the learning process enjoyable and insightful. The teachers
clear explanations and valuable feedback not only helped me understand the
concepts but also inspired me to apply them effectively. This project has been a
wonderful learning experience, and it wouldn’t have been possible without their
support and dedication.

Lastly, I am grateful for the support, environment, encouragement provided by the


Trinity International SS/ College .

Genuine Rajbhandari

Grade 11

MF1
OBECTIVES

I learned many useful skills while working on C-Programing in college. I now


know how to write different programs on C language by the help of looping.

I practiced to solve the program by the help of looping. This skill helped me to
start and execute the loop in C-Programming.

I learned how to make various codes, print different patterns, print the series and
nepal flag. etc on it. This skill was exciting because it made my work look more
professional and easier to understand.

The main objective for me was to understand how to use proper condition for
looping, using increment and decrement of looping properly to execute the loop in
right way. I feel more confident now because I can use C-Programming to handle
these tasks efficiently.

I am learning looping in C-Programming as I feel it is a very useful tool. I know


the skills I will gain will help me in my studies and future projects. I am grateful I
got the chance to learn and practice using C-Programming.
Table of Contents
C-PROGRAMMING……………………………………………………..,1

C for Loop………………..…………………………...…………… .1

Types of loops in C Programming ……………...……………………1

1) for Loops..…………………………………………………………….2

2)While Loop……….. ………………………………….………………4

3)do…while Loop……..………………………………………………...5

CONCLUSION ……………………………………………………………..6

REFERENCE………………………………………………………………..7
THEORY

C-Programming
The C programming language is a procedural and general-purpose
language that provides low-level access to system memory. A program
written in C must be run through a C compiler to convert it into an
executable that a computer can run. Many versions of Unix-based
operating systems (OSes) are written in C and it has been standardized as
part of the Portable Operating System Interface (POSIX).

C for Loop

In programming, a loop is used to repeat a block of code until the specified


condition is met.

C programming has three types of loops:

1. for loop

2. while loop

3. do...while loop

We will learn about for loop in this tutorial. In the next tutorial, we will learn
about while and do...while loop.
1) for Loop

The syntax of the for loop is:

for (initialization Statement; test Expression; update Statement)

// statements inside the body of loop

How for loop works?

 The initialization statement is executed only once.

 Then, the test expression is evaluated. If the test expression is evaluated to


false, the for loop is terminated.

 However, if the test expression is evaluated to true, statements inside the


body of the for loop are executed, and the update expression is updated.

 Again the test expression is evaluated.

This process goes on until the test expression is false. When the test expression is
false, the loop terminates.
for loop Flowchart

2) C while and do...while Loop

In programming, loops are used to repeat a block of code until a specified


condition is met.

C programming has three types of loops.

1. for loop

2. while loop

3. do...while loop

In the previous tutorial, we learned about for loop. In this tutorial, we will learn
about while and do..while loop.
While loop

The syntax of the while loop is:

while (test Expression) {

// the body of the loop

How while loop works?

 The while loop evaluates the test Expression inside the parentheses ().

 If test Expression is true, statements inside the body of while loop are
executed. Then, test Expression is evaluated again.

 The process goes on until test Expression is evaluated to false.

 If test Expression is false, the loop terminates (ends).

Flowchart of while loop


3) do...while loop

The do..while loop is similar to the while loop with one important difference. The
body of do...while loop is executed at least once. Only then, the test expression is
evaluated.

The syntax of the do...while loop is:

do {

// the body of the loop

while (test Expression);

How do...while loop works?

 The body of do...while loop is executed once. Only then, the test
Expression is evaluated.

 If test Expression is true, the body of the loop is executed again and test
Expression is evaluated once more.

 This process goes on until test Expression becomes false.

 If test Expression is false, the loop ends.

Flowchart of do...while Loop


CONCLUSION

Loops are a fundamental concept that allow developers to create dynamic


programs capable of performing repetitive tasks efficiently. Instead of writing out
the same code repeatedly, programmers can use loops to minimize the number of
lines, save time, and reduce errors. By doing so, loops make code more
manageable and organized, which is especially helpful when dealing with complex
or repetitive actions.

Looping mechanisms are critical in programming due to their role in enhancing


code efficiency and manageability. Loops eliminate the necessity of duplicating
code, thereby reducing the length of the codebase and simplifying both readability
and maintenance. They are adaptable to varying data sizes and scenarios, and they
aid in error localization within iterative code blocks. Choosing the correct loop
type for a specific task is crucial to avoid inefficiencies and potential issues in
program execution.
REFERENCES

1) Computer Science-I (Buddha Publications) [Text book]

2) https://www.programiz.com/c-programming/c-do-while-loops

3) https://learn.microsoft.com/en-us/cpp/c-language/c-language-

reference?view=msvc-170

4) https://www.geeksforgeeks.org/c-for-loop/

You might also like