C IMPORTANT PROGRAMS - 2

This is the second part of the post which contains all the C programs of 1st semester. This post covers the part which is a bit hard to understand but if you do them, you sure get good marks in final examination. This post mainly contains:
  1. arrays
  2. structure
  3. files
  4. pre-processor directives
You can checkout the first part of this post to learn some basic๐Ÿ‘‰๐Ÿ‘‰ Part - 1

->Arrays

Arrays is a collection of similar type of data types that holds contiguous memory location. Example: int arr[10];
There are different methods to initialize an array.
1. int a[5];
2. int a[]={1,2,3,4,5};
3. int a[5]={1,2,3,4,5};
they are of 2 types:- single-dimension array and multi-dimension array.
Multi-dimension array can be of 2D array or 3D array or more than that but now we only talk about 2D array.
2D arrays are generally use to form a matrix or to store data in an aligned format.

Sum of elements in the array : sum_of_elements
Sum of squares of the elements : sum_of_squares
Matrix using 2D array : matrix
Find the transpose of a matrix : transpose

->Strings

You can use several commands using<string.h> header file. The 4 main library functions are strcat(), strcpy(), strlen() and strcmp().

string functions : string
Searching menu option : search
Bubble sort : sort
Swapping, sorting and searching in a single program : long_code

->Structure

Structure is a user defined data type that can store related information(even of different datatypes) together.
Storing books data : book
Nested Structure : student details
Enumerated data type: enum

Comments