 # C Programming Code Examples

## C > Beginners Lab Assignments Code Examples

### Program to Sort Structures on the basis of Structure Element

``` Program to Sort Structures on the basis of Structure Element Sorting Two Structures on the basis of any structure element and Display Information Program Statement - Define a structure called cricket that will describe the following information Player name Team name Batting average Using cricket, declare an array player with 10 elements and write a program to read the information about all the 10 players and print a team wise list containing names of players with their batting average. #include<stdio.h> struct cricket { char pname; char tname; int avg; } player, temp; void main() { int x, j, n; clrscr(); for (x = 0; x < 10; x++) { printf("\nEnter Player Name : "); scanf("%s", player[x].pname); printf("\nEnter Team Name : "); scanf("%s", player[x].tname); printf("\nEnter Average : "); scanf("%d", &player[x].avg); printf("\n"); } n = 10; for (x = 1; x < n; x++) for (j = 0; j < n - x; j++) { if (strcmp(player[j].tname, player[j + 1].tname) > 0) { temp = player[j]; player[j] = player[j + 1]; player[j + 1] = temp; } } for (x = 0; x < n; x++) { printf("\n%s\t%s\t%d",player[x].pname,player[x].tname,player[x].avg); } getch(); } ```

Program Find the Length of the Linked list - C Program to Find the length of the linked list using Recursion. This program uses Recursive Function and calculates the length of a string. The user enters a string to find it's length. List

C++ & Encapsulations Represents Binding - "Encapsulation" represents binding data and functions into one container. Container hides the details of the data and the way functions process data. In C++, Class is a container that

Find the First Occurrence of a Character in - C program to 'input any string' from user and find the 'first occurrence' of a given character in the string. Input string from user and store it in a variable say "str". Run a loop from start

Increment Operator Decrement Operator - Basic "arithmetic operators" are +, -, *, /, %. "Increment operator" is ++ and "decrement operator" is --. These operators can be used as before the variable (prefix) and after the

C Find Volume and Surface Area of Sphere - C Program calculates the volume and surface area of sphere. The formula used in this code Surface_area = 4 * Pi * r2, Volume = 4/3 * Pi * r3 where r is the radius of the sphere, Pi= 22/7

C check uppercase or lowercase characters - Code Step by Step descriptive logic to check Uppercase and Lowercase alphabets. Input a character from user. Store it in some variable say ch. Character is uppercase alphabet if(ch

Find the Odd Element given an Array with - Will hold XOR of two odd occurring elements. Xor will basically be xor of two odd occurring elements. Get one set rightmost bit in the xor2. Now divide elements in two sets. XOR

Function strncpy Copies First n Characters - If 'Length of str2' > n then it just copies first n characters of str2 into str1. If Length of str2 < n then it 'copies' all the characters of str2 into str1 & appends several 'terminator' chars('\0')