Bhanu Priya

Bhanu Priya

1,060 Articles Published

Articles by Bhanu Priya

Page 92 of 106

C program for a number to be expressed as a sum of two prime numbers.

Bhanu Priya
Bhanu Priya
Updated on 26-Mar-2021 5K+ Views

ProblemFind out if a given number can be expressed as sum of two prime numbers or not.Given a positive integer N, we need to check if the number N can be represented as a sum of two prime numbers.SolutionConsider an example given below −20 can be expressed as sum of two prime numbers 3 and 17, 13 and 7.20= 3+720= 13+7AlgorithmRefer an algorithm given below for expressing a given number as a sum of two prime numbers.Step 1 − Input the number to be checked at run time.Step 2 − Repeat from i = 2 to (num/2).Step 3 − Check ...

Read More

C program to replace all zeros with one in a given integer.

Bhanu Priya
Bhanu Priya
Updated on 26-Mar-2021 4K+ Views

ProblemWrite a program to replace all zeros (0's) with 1 in a given integer.Given an integer as an input, all the 0's in the number has to be replaced with 1.SolutionConsider an example given below −Here, the input is 102410 and the output is 112411.AlgorithmRefer an algorithm given below to replace all the 0’s to 1 in an integer.Step 1 − Input the integer from the user.Step 2 − Traverse the integer digit by digit.Step 3 − If a '0' is encountered, replace it by '1'.Step 4 − Print the integer.ExampleGiven below is the C program to replace all 0's ...

Read More

Explain queue by using linked list in C language

Bhanu Priya
Bhanu Priya
Updated on 26-Mar-2021 1K+ Views

Queue overflow and Queue under flow can be avoided by using linked list.Operations carried out under queue with the help of linked lists in C programming language are as follows −InsertDeleteInsertionThe syntax is as follows −Syntax&item : Newnode = (node*) mallac (sizeof (node)); newnode ->data = item; newnode ->link = NULL; if ((front = = NULL) || (rear = = NULL)){    front= newnode;    rear = newnode; }else{    Rear->link = newnode;    rear = newnode; }DeletionThe syntax is as follows −Syntaxif ((front= = NULL)) printf("Deletion is not possible, Queue is empty"); else{    temp = front;    front ...

Read More

C program to compare the structure variables

Bhanu Priya
Bhanu Priya
Updated on 26-Mar-2021 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 the stack by using linked list in C language

Bhanu Priya
Bhanu Priya
Updated on 26-Mar-2021 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

Explain the deletion of element in linked list

Bhanu Priya
Bhanu Priya
Updated on 26-Mar-2021 848 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

C program to calculate the standard deviation

Bhanu Priya
Bhanu Priya
Updated on 25-Mar-2021 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

Read More

C Program to represent a multiplication table.

Bhanu Priya
Bhanu Priya
Updated on 25-Mar-2021 941 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

Read More

C program to calculate range of values and an average cost of a personal system.

Bhanu Priya
Bhanu Priya
Updated on 25-Mar-2021 797 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

C Program to calculate the salesmen salary with macro functions.

Bhanu Priya
Bhanu Priya
Updated on 25-Mar-2021 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
Showing 911–920 of 1,060 articles
« Prev 1 90 91 92 93 94 106 Next »
Advertisements