Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 32

Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Student Name : SALAPU ATCHUTA VENKATA DURGA SUDHIR


Department : C.S.E.
Course : Computer Programming Lab
Course code : 23ESX05
Roll no : 23NU1A05B8

1
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

What we learn from c?


• These are few topics:
• Operators: Operators,which used to perform mathematical and logical operations.
• Conditional statements: C provides three main types:
1)If Statement 2)If-Else Statement 3)Else-If Statement.
• Control Statements :c provides
1)for loop 2)while loop 3)do-while loop
• Arrays: Arrays, which allow you to store collections of elements of the same data
type.
• Pointers: pointers, which are variables that store memory addresses.
• Strings(character arrays): strings are represented as arrays of characters (char).
For example, "Hello" is represented as char my String[] = "Hello";.
• Functions: Functions are a core concept in C for structuring your code.
• Structures :collection of elements of different data types.
• Files :A file is a sequence of bytes on the disk a file is used to store the large
amount of data 2
List of experiments: Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

1.Write C programs to Familiarization with programming environment


2. Write C programs to Simple computational problems using arithmetic expressions
3. Write C programs to computational problems using the operator’ precedence and
associativity
4. Write C programs to involving if-then-else structures
5. Write C programs on while and for loops
6. Write C programs on 1D Array manipulation, linear search
7. Write C programs on Matrix ,String operations

8. Write C programs on Functions, call by value, scope and extent

3
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

9. Write C programs to implement Recursive functions

10. Write C programs on Simple functions using Call by reference, Dangling pointers
11. Write C programs on Pointers, structures and dynamic memory allocation
12. Write C programs on Bit fields, Self-Referential Structures
13. Write C programs to implement File operations

4
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

LAB COURSE OUTCOMES

At the end of the Computer Programming lab we are able to

Code Course Outcomes

23ESX05.1 Demonstrate the use of basic language features

23ESX05.2 Apply the right control structure for solving the problem
Implement simple programs to solve computing problems using user defined
23ESX05.3
functions
23ESX05.4 Develop programs using arrays and pointers

23ESX05.5 Experiment with user defined data types and file operations

5
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
PROGRAM OUTCOMES
SNO OUTCOMES DESCRIPTION

1 Engineering Knowledge Apply the knowledge of mathematics , science, engineering fundamentals and an
engineering specialization to the solution of complex engineering problems .

2 Problem Analysis Identify , formulate, research literature &analyze complex engineering problems reaching
substantiated conclusions using first principles of mathematics , natural science , engineering
science .

3 Design/Development of solution Design solutions for complex engineering problems and design system components of
processes that meet the specified needs with appropriate consideration for the public health
safety and the cultural, societal and environmental considerations

4 Conduct Investigations of Use research –based knowledge and research methods including design of experiments and
interpretation of data and synthesis of the information to provide valid conclusions
complex problems

5 Modern tool usage Create, select and apply appropriate techniques, resources and modern engineering and IT
tools including prediction and modeling to complex engineering activities with an
understanding of the limitations .

6 The Engineering and society Apply reasoning informed by the contextual knowledge to assess societal ,health ,safety ,
legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice
6
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)
PROGRAM OUTCOMES
SNO OUTCOMES DESCRIPTION

7 Environmental and sustainability Understand the impact of professional engineering solutions and environmental contexts
and demonstrate the knowledge of and need for sustainable development

8 Ethics Apply ethical principles and commit to professional ethics and responsibilities and norms of
engineering practice.

9 Individual and teamwork Function effectively as an individual , and as a member or leader in diverse terms and in
multidisciplinary settings

10 Communication Communicate effectively on complex engineering activities with the engineering community
and with society at large such as being able to comprehend and write effective reports and
documentation, make effective presentation, and give and receive clear instructions .

11 Project management and Demonstrate knowledge and understanding of the engineering and management principles
and apply theses to one’s own work ,as a member and leader in a team ,to manage projects
finance and in multidisciplinary environments.

12 Lifelong Learning Recognize the need for and have the preparation and ability to engage in independent and
life-long learning in the broadest context of technological change.
7
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Name of the Experiment:

PROGRAMS ON WHILE AND FOR LOOPS

8
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

What is While loop ?


Definition:
A “While loop” in the c program is used when programmer doesn’t know how many
times the code will be executing before starting the loop, as it depends upon the
user input
Syntax:
while (test expression is true)
{
statement1;
statement2;

} 9
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Flow chart for a while loop


10
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Declaration and Initialization:


Declaration: In c language, a variable can be declared within a
for loop as follows

Example:
int i=1; //Declaration for a loop body
while(i<=5) {
//loop body
//code to be executed repeatedly
} 11
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

In the above example for combined initialization and


declaration.
• ‘int i=1’:declares the loop variable ‘1’.
• ‘i<=5’ :condition to continue the loop.
• ‘i++’ :increment the loop variables after each
iteration.
iteration means the repetition of a process
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Program:
Input:
#include<stdio.h>
int main() {
int n,count=0;
printf(“Enter n value \n”);
scanf(“%d”,&n);
while(n!=0) {
count ++;
n=n/10;
}
printf(“count=%d”,count);
return 0;
} 13
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Output

14
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

What is for loop?


Definition:
A "for loop" in the C language is a control flow statement that allows
repeated execution of a block of code, with specified initialization,
condition, and increment/decrement expressions.
Syntax:
For(initialization expression;test expression;increment/decrement
expression)
{
//Block of statements to execute
}
15
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Flow chart of for loop 16


Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Declaration and Initialization:

Declaration:In c language,a variable can be declared within a for loop


as follows

example:
int n=5
for(i=0;i<n;i=++)
{
//Block of statements to execute

}
17
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

combined declaration and intialization :

int i; //Declarationof a for loop variable


for(i=0;i<5;i++)
{
// Loop body
//Code to be executed repeatedly
}

18
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

in the above example for combined intialization and declaration,

- 'int i': declares the loop variable 'i'.


-'i=0: intializes the loop variable to '0'
-'i<5:' is the condition to continue the loop.
-'i++' increment the loop variable after each iteration.
iteration means " the repetition of a process".

19
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Program:
Input:
#include<stdio.h>
int main()
{
int i,n first=0,second=1,next;
printf("Enter the number of terms :");
scanf("%d",&n);
printf("fibanocci series:");
for(int i=0;i<n;i++)
{ 20
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

printf("%d",first);
next=first+second;
first=second;
second=next;
}
return 0;
}

21
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

output 1:

22
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

output 2:

23
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

Real Time Applications of for loop:


Programming: for loop are used in programming languages for intalization and
conditions ,this is used for repetition process.

Array manipulation: iterating through elements of an array for operation like


sum,average,or finding specific values.
coping elements from one array to anthor.

Dataprocessing: Analalyzing data stored in arrays or other data structures.


processing elements of a matrix.

File Handling: Reading or writing data from/to files line by line or character by
character.

24
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

user input validation: Repeatedly prompting the user until valid input
is provided.

Simulation and Modeling: simulating behavior over time using a loop to


model discrete time steps.

Network programming: handling connections,sending/receiving data in


networking applications.

25
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

NAME OF THE EXPERIMENT:

BIT FIELDS
AND
SELF-REFERENTIAL STRUCTURES

26
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

BIT FIELDS
Bit fields are a way to declare a structure or union member with a
specific width in terms of the number of bits it occupies in memory. Bit
fields allow you to create more compact data structures by explicitly
specifying the number of bits each member should occupy

Here's the basic syntax for defining bit fields within a structure:

27
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

In the above example, ‘flag’ is a bit field that occupies 1 bit, and value is a bit field
that occupies 4 bits.
Here's a more detailed breakdown:
• ‘member_ name’: This is the name of the bit field member within the
structure.
• ‘width’: This is the number of bits that the member should occupy.
Bit fields are useful in scenarios where memory conservation is crucial, and you
want to optimize the storage of data. However, they come with some
considerations and limitations:
• The actual memory layout may depend on the architecture and compiler.
• The width of a bit field member cannot exceed the size of the underlying data
type (e.g., ‘int’, ‘char’).
• The order of bit fields within a structure is not guaranteed.
Here's an example of using bit fields in a complete program:

28
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

In this example, the Flags structure contains three bit fields: flag1 and flag2 with 1 bit each, and value with 4
29
bits. The program initializes these bit fields and prints their values.
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

SELF-REFERENTIAL STRUCTURE:
Self-referential structures, also known as recursive structures, are
structures in programming languages like C or C++ that have a member
that is a pointer to the same type of structure. This allows the structure to
contain elements that refer to other instances of the same structure type.
Self-referential structures are commonly used to build data structures
like linked lists, trees, and graphs.

Here's a simple example of a self-referential structure for representing a


singly linked list:

30
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

31
Nadimpalli Satyanarayana Raju Institute of Technology (NSRIT)

In this example:

• The ‘Node’ structure contains an integer data member (‘data’) and a pointer to the
next ‘Node’ in the list (‘next’).
• In the ‘main’ function, three instances of ‘Node’ (node1, node2, and node3) are
created, and data is assigned to each node.
• The nodes are linked to form a linked list by assigning the ‘next’ pointers
accordingly.
• The program then traverses the linked list, starting from the first node (‘node1’)
and printing the data of each node.

This example illustrates the concept of self-referential structures in the context of a


singly linked list. Similar principles can be applied to other self-referential data
structures like trees and graphs.
32

You might also like