




























































































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
Unit 5 18CSS101J Programming for Problem Solving Detailed lecture slides covering all topics as prescribed by the curriculum for the academic year. Important and Necessary Exam Material
Typology: Slides
1 / 108
This page cannot be seen from the preview
Don't miss anything!





























































































COURSE LEARNING RATIONALE (CLR) The purpose of learning this course is to: CLR - 1: Think and evolve a logically to construct an algorithm into a flowchart and a pseudocode that can be programmed CLR - 2: Utilize the logical operators and expressions to solve problems in engineering and real-time CLR - 3: Store^ and^ retrieve^ data^ in^ a^ single^ and^ multidimensional^ array CLR - 4: Utilize custom designed functions that can be used to perform tasks and can be repeatedly used in any application CLR - 5: Create storage constructs using structure and unions. Create and Utilize files to store and retrieve information CLR - 6: Create a logical mindset to solve various engineering applications using programming constructs in C
LEARNING RESOURCES S. No (^) TEXT BOOKS
Zed A Shaw, Learn C the HardWay: Practical Exercises on the Computational Subjects You Keep Avoiding (Like C), AddisonWesley, 2015
W. Kernighan, Dennis M. Ritchie,The C Programming Language, 2nd ed. Prentice Hall, 1996
Initializing Structure, Declaring Structure variable- Structure using typedef, Accessing members – Nested structure Accessing elements in a structure array – Array of structure Accessing elements in a structure array – Passing Array of Structure to function- Array of Pointers to structures- Bit Manipulation of structure and pointer to structure – Union Basic and declaration – Accessing Union Members Pointers to union
INTRODUCTION TO STRUCTURE
Solution: Structure
8
10
11
13
struct structure_name structure_variable={value1, value2, …, valueN};
struct student { char name[20]; int roll_no; float marks; char gender; long int phone_no; }; void main() { struct student st1={“ABC", 4, 79.5, 'M', 5010670}; clrscr(); printf("Name\t\t\tRoll No.\tMarks\t\tGender\tPhone No."); printf("\n.........................................................................\n"); printf("\n %s\t\t %d\t\t %f\t%c\t %ld", st1.name, st1.roll_no, st1.marks, st1.gender, st1.phone_no); getch(); } 14
16 struct student { char name[ 20 ]; int roll; char remarks; float marks; }; void main() { struct student s 1 ={“name", 4 }; clrscr(); printf("Name=%s", s 1 .name); printf("\n Roll=%d", s 1 .roll); printf("\n Remarks=%c", s 1 .remarks); printf("\n Marks=%f", s 1 .marks); getch(); }
17 Accessing member of structure/ Processing a structure
19 struct student { char name[20]; int roll; float mark; }; void main() { struct student s; clrscr(); printf("Enter name:\t"); gets(s.name); printf("\n Enter roll:\t"); scanf("%d", &s.roll); printf("\n Enter marks:\t"); scanf("%f", &s.mark); printf("\n Name \t Roll \t Mark\n"); printf("\n...................................\n"); printf("\n%s\t%d\t%f", s.name, s.roll, s.mark); getch(); }
20
Copying and Comparing Structure Variables