Programming Articles

Page 129 of 2544

Diagonal of a Regular Heptagon in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 182 Views

In this tutorial, we are going to learn how to find the diagonal of a regular heptagon.We have to find the length of the diagonal of the regular heptagon using the given side. The length of the diagonal of a regular heptagon is 1.802 * s where s is the side of the heptagon.ExampleLet's see the code.#include using namespace std; float heptagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.802 * s; } int main() {    float s = 7;    cout

Read More

Write a program in C++ to replace all the 0&rsquo;s with 5 in a given number

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 1K+ Views

Given an integer N, the task is to replace all the 0’s that appear in the number with ‘5’. However, the number with leading ‘0’ cannot be replaced with ‘5’ as it remains unchanged. For example, Input-1 −N= 1007Output −1557Explanation − The given number has 2 zeros which when replaced by ‘5’ results in the output as 1557.Input-2 −N = 00105Output −155Explanation − Since the given number starts with the leading ‘0’ which can be ignored and the output after replacing the 0 in the middle with ‘5’ results the output as 155.Approach to Solve this ProblemTo replace all the ...

Read More

How to save a csv and read using fread in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 829 Views

To save a csv file, we can use write.csv function in R and if we want to read it using fread then fread function will be used with the name of the csv file. The benefit of reading the csv file with fread function is that there will be a variable added to the original csv file which contains the id as integers starting from 1 to the length of column values.Consider the below data frame −Examplex

Read More

Diagonal of a Regular Pentagon in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 250 Views

In this tutorial, we are going to learn how to find the diagonal of a regular pentagon.We have to find the length of the diagonal of the regular pentagon using the given side. The length of the diagonal of a regular pentagon is 1.22 * s where s is the side of the pentagon.ExampleLet's see the code.#include using namespace std; float pentagonDiagonal(float s) {    if (s < 0) {       return -1;    }    return 1.22 * s; } int main() {    float s = 7;    cout

Read More

Reverse Vowels of a string in C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 2K+ Views

Given a string, the task is to reverse all the vowels present in the given string. For example, Input-1 −a = “tutor”Output −toturExplanation − Reversing the string “tutor” will generate the output as “totur.Input-2 −a = “mathematics”Output −mithametacsExplanation − Reversing the string “mathematics” will generate the output as “mithametacs”.Approach to solve this problemGiven a string, we have to reverse all the vowels present in it. There are several approaches to solve this particular problem but we have to solve this in linear time O(n).Thus, the better method to solve this problem is to use the Two-Pointer approach in which we ...

Read More

How to hide NA values in an R matrix?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 329 Views

The hiding of NA values does not mean removal of NA values. If we have some NA values in an R matrix then we can hide them using blanks with double quotes. For example, suppose we have a matrix called M that contains some NA values then M can be printed by hiding NA value using print.table(M,na.print="")ExampleM1

Read More

How to fill NA values with previous values in an R data frame column?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 2K+ Views

To fill NA values with next and previous values, we can use na.locf function of zoo package with fromLast = TRUE. This is the situation of a column as shown below −x 0 NA NA 1 1 NA 0 1The output after filling NA values with next and previous values will be −x 0 0 0 1 1 1 0 1Consider the below data frame −Examplex1

Read More

Different possible marks for n questions and negative marking in C++ Program

Hafeezul Kareem
Hafeezul Kareem
Updated on 11-Mar-2026 392 Views

In this tutorial, we are going to write a program that finds different possible marks for the given n questions with positive and negative marking.Let's say we have 10 questions and each carries 2 marks for correct answers and -1 marks for a negative answer. Our aim is to find all the possible ways in which a student can score in the exam.Let's see the steps to solve the problem.Initialize the number of questions, positive marks for the correct answer and negative marks for the wrong answer.Initialize a set to store the possible marks.Write two inner loops from 0 to ...

Read More

Search an element in the given singly Linked List using C++

Dev Prakash Sharma
Dev Prakash Sharma
Updated on 11-Mar-2026 684 Views

Given a singly linked list, the task is to search a particular element in the linked list. If the element is found, then print “present” otherwise “Not present”. For example, Input-1 −1→ 2→ 3→ 4→ 5→ 6Searching for ‘7’Output −Not PresentExplanation − In the given singly linked list the element ‘7’ is not present, hence we will return the output as “Not Present”.Input-2 −1→ 2→ 3→ 4→ 5Searching for ‘2’Output −PresentExplanation − Since in the given Singly linked list the element ‘2’ is present thus we will return the output as “Present”.Approach to solve this problemThere are two approaches to ...

Read More

How to define the breaks for a histogram using ggplot2 in R?

Nizamuddin Siddiqui
Nizamuddin Siddiqui
Updated on 11-Mar-2026 8K+ Views

To manually define the breaks for a histogram using ggplot2, we can use breaks argument in the geom_histogram function. While creating the number of breaks we must be careful about the starting point and the difference between values for breaks. This will define the number of bars for histogram so it should be taken seriously and should be according to the distribution of the data.Consider the below data frame −Examplex

Read More
Showing 1281–1290 of 25,433 articles
« Prev 1 127 128 129 130 131 2544 Next »
Advertisements