Compare Structure Variables in C

Bhanu Priya
Updated on 26-Mar-2021 06:47:28

9K+ Views

In C programming language, a structure is a collection of different datatype variables, which are grouped together under a single name.Declaration and initialization of structuresThe general form of a structure declaration is as follows −datatype member1; struct tagname{    datatype member2;    datatype member n; };Here, struct is a keyword.tagname specifies the name of structure.member1, member2 specifies the data items that make up structure.For example, struct book{    int pages;    char author [30];    float price; };Structure variablesThere are three methods of declaring structure variables, which are as follows −First methodstruct book{    int pages;    char author[30];   ... Read More

Explain Stack Using Linked List in C

Bhanu Priya
Updated on 26-Mar-2021 06:47:11

3K+ Views

Stack over flow and stack under flow can be avoided by allocating memory dynamically.Operations carried out under stack in C programming language are as follows −PushPopPushFollowing is the basic implementation of a linked list −&item = 10 newnode = (node*) malloc (sizeof (node)); newnode ->data = item; newnode ->link = NULL; newnode ->link = start; start = newnode;popThe syntax is as follows −Syntaxif (start = = NULL) printf("Deletion is not possible.List is empty") else{    temp = start;    start = start link;    free (temp); }ProgramFollowing is the C program for stack by using linked lists −#include #include ... Read More

Sort Names in Alphabetical Order using C String Functions

Bhanu Priya
Updated on 26-Mar-2021 06:43:54

1K+ Views

ProblemSort the names given by the user at runtime in an alphabetical order by using the bubble sort technique.SolutionThe logic used to print the names in alphabetical order is as follows −for (i=1; i < ITEMS; i++){    for (j=1; j 0){ /* Exchange of contents */          strcpy (dummy, string[j-1]);          strcpy (string[j-1], string[j]);          strcpy (string[j], dummy );       }    } }ExampleFollowing is the C program to sort the names in an alphabetical order by using the string functions − Live Demo#define ITEMS 5 #define MAXCHAR ... Read More

Deletion of Element in Linked List

Bhanu Priya
Updated on 26-Mar-2021 06:40:12

801 Views

Linked lists use dynamic memory allocation i.e. they grow and shrink accordingly. They are defined as a collection of nodes. Here, nodes have two parts, which are data and link. The representation of data, link and linked lists is given below −Operations on linked listsThere are three types of operations on linked lists in C language, which are as follows −InsertionDeletionTraversingDeletionConsider an example given below −Delete node 2Delete node 1Delete node 3ProgramFollowing is the C program for deletion of the elements in linked lists − Live Demo#include #include struct Node{    int data;    struct Node *next; }; void ... Read More

Calculate Standard Deviation in C

Bhanu Priya
Updated on 25-Mar-2021 11:48:20

6K+ Views

Standard deviation is used to measure deviation of data from its mean. The mathematical formula to calculate the standard deviation is as follows −$$s=\sqrt{Variance}$$whereVariance$$=\frac{1}{n}\:\:\displaystyle\sum\limits_{i=1}^n (x_{i}-m)^{2}$$and$$m=mean=\frac{1}{n}\:\displaystyle\sum\limits_{i=1}^n x_{i}$$AlgorithmRefer an algorithm given below to calculate the standard deviation for the given numbers.Step 1 − Read n items.Step 2 − Calculate sum and mean of the items.Step 3 − Calculate variance.Step 4 − Calculate standard deviation.The logic used in the program for calculating standard deviation is as follows −for (i = 1 ; i

Find the Median of a Given List in C

Bhanu Priya
Updated on 25-Mar-2021 11:39:46

19K+ Views

If the elements of the list are arranged in order, then, the middle value which divides the items into two parts with equal number of items on either side is called the median.Odd numbers of items have just one middle value whereas; even numbers of items have two middle values.The median for even number of items is therefore, designated as the average of the two middle values.AlgorithmRefer an algorithm given below to calculate the median.Step 1 − Read the items into an array while keeping a count of the items.Step 2 − Sort the items in increasing order.Step 3 − ... Read More

C Program to Represent a Multiplication Table

Bhanu Priya
Updated on 25-Mar-2021 11:35:48

921 Views

ProblemWrite a program to print the multiplication table from 1 x 1 to 12 x 10 as given below −1 2 3 4 5 6 7 8 9 10 2 4 6 8 ……………….20 3 6 9…………………….30 4 8 12 16……………..40 - - - 12 24……………………..120SolutionUse two do while loops in nested form to display the multiplication table.The logic used to display the multiplication table is as follows −Inner loop is controlled by the variable column and is executed 10 times, whenever each time the outer loop is executed.Outer loop is executed 12 times and controlled by variable row.do /*......OUTER LOOP BEGINS........*/{    column = 1;    do /*.......INNER LOOP BEGINS.......*/{       y = row * column;       printf("%4d", y);       column = column + 1;    }    while (column

Calculate Range of Values and Average Cost of a Personal System in C

Bhanu Priya
Updated on 25-Mar-2021 11:31:49

782 Views

ProblemA personal system is sold at different costs by the vendors.Let’s take the list of costs (in hundreds) quoted by some vendors −25.00, 30.50, 15.00, 28.25, 58.15, 37.00, 16.65, 42.00 68.45, 53.50SolutionCalculate the average cost and range of values.The difference between the highest and the lowest values in the series is called range Hence, Range = highest value - lowest value.Now, find the highest and the lowest values in the series.ExampleFollowing is the C program to calculate the range of values and average cost of a personal system − Live Demo#include main(){    int count;    float value, high, low, sum, ... Read More

Print Characters and Strings in Different Formats Using C

Bhanu Priya
Updated on 25-Mar-2021 11:22:17

16K+ Views

An algorithm is given below to explain the process which is included in the C programming language to print the characters and strings in different formats.Step 1: Read a character to print.Step 2: Read a name at compile time.Step 3: Output of characters in different formats by using format specifiers.printf("%c%3c%5c", x, x, x);printf("%3c%c", x, x);printf("");Step 4: Output of strings in different formats by using format specifiers.printf("%s", name);printf("%20s", name);printf("%20.10s", name);printf("%.5s", name);printf("%-20.10s", name);printf("%5s", name);ExampleFollowing is the C program to print the characters and strings in different formats − Live Demo#include main(){    char x = 'T';    static char name[20] = "Tutorials Point"; ... Read More

Calculate Salesmen Salary with Macro Functions in C

Bhanu Priya
Updated on 25-Mar-2021 11:18:21

2K+ Views

ProblemA laptop manufacturing company has the monthly compensation policy for their salespersons as mentioned below −Minimum base salary: 3000.00Bonus for every computer sold: 200.00Commission on the total monthly sales: 5 per centSince the prices of laptops are changing, the sales price of each laptop is fixed at the beginning of every month.SolutionThe logic for finding the bonus and commission is as follows −bonus = BONUS_RATE * quantity ; commission = COMMISSION * quantity * price ;The gross salary is calculated by using the formula given below −Gross salary = basic salary + (quantity * bonus rate) + (quantity * Price) ... Read More

Advertisements