C++ Articles

Page 349 of 597

Sum of a Geometric Progression in C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 11-Dec-2024 7K+ Views

What is Geometric Progression? A geometric progression is a sequence of numbers where each term is obtained by multiplying the previous term by a fixed number. This fixed number is known as the common ratio and it should be a non-zero. In this article, we are going to learn how we can find the sum of given n terms in geometric progression in C++. We are given first-term, common ratio, and number of terms for which we have to find the sum of geometric progression. Formula for Calculating Sum of Geometric Progression Sn= a (1 - rn)/(1 - r)  ...

Read More

C++ program to convert the string into an integer

Arnab Chakraborty
Arnab Chakraborty
Updated on 09-Dec-2024 13K+ Views

C++ is a statically typed language. To write programs we need to define variables of specified types. Sometimes we need to read inputs from the console or files. In such a scenario the string data are read into the program. To convert them into other datatypes needs special operations. In this article, we shall discuss how to convert strings to integers in C++. There are a few different techniques to do so. Let us explore them one by one. String to Integer Using stringstream Class C++ uses streams for different applications. Such streams are filestreams, standard input/output streams, etc. There ...

Read More

Pythagorean Triplet in an Array Using C++

C++
AYUSH MISHRA
AYUSH MISHRA
Updated on 09-Dec-2024 34K+ Views

Pythagorean Triples Pythagorean triples are a set of three distinct numbers a, b, and c which satisfy the condition: a2 + b2 = c2 These numbers a, b, and c are known as Pythagorean triples. We can say that these three numbers represent the sides of a right-angled triangle. These three sides are known as triplets of the array. Problem Description We are given an array of integers, and we have to find if there exist three distinct numbers in the array which form the Pythagorean triplet in C++. Below are examples to demonstrate the problem statement clearly: ...

Read More

5 Different methods to find length of a string in C++?

Arnab Chakraborty
Arnab Chakraborty
Updated on 05-Dec-2024 12K+ Views

Here we will see five different ways to get the string lengths in C++. In C++ we can use the traditional character array string, and C++ also has String class. In different area there are different methods of calculating the string lengths. The C++ String class has length() and size() function. These can be used to get the length of a string type object. To get the length of the traditional C like strings, we can use the strlen() function. That is present under the cstring header file. Another two approaches are straight forward. One by using the while loop, ...

Read More

Type Inference in C++ (auto and decltype)

Ayush Gupta
Ayush Gupta
Updated on 03-Dec-2024 343 Views

In this tutorial, we will be discussing a program to understand Type interference in C++ (auto and decltype). In the case of auto keyword, the type of the variable is defined from the type of its initializer. Further, with decltype, it lets you extract the type of variable from the called element. auto type Example Here is the following example of auto-type in C++. #include using namespace std; int main() { auto x = 4; auto y = 3.37; auto ptr = & x; cout

Read More

Bitwise AND of N binary strings in C++

sudhir sharma
sudhir sharma
Updated on 03-Dec-2024 804 Views

In this problem, we are given an array bin[] of size n of binary strings. Our task is to create a program to find the Bitwise AND (&) of N binary strings. Here, we will take all numbers and find the bitwise AND of them i.e. bin[0] & bin[1] &... bin[n-2] & bin[n] Example Let’s take an example to understand the problem. Input − bin[] = {“1001”, “11001”, “010101”} Output − 000001 Explanation Bitwise AND of all binary strings − (1001) & (11001) & (010101) = 000001 To solve this problem, ...

Read More

Largest gap in an array in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 03-Dec-2024 382 Views

In this tutorial, we are going to write a program that finds the largest difference between the two elements in the given array. Approach Let's look at the approach we will follow to solve this problem. Firstly, we will initialize the array. Then we will find or search for the max and min elements in the array. And will return max - min. Example Here is the following code for finding the largest gap in an array in C++. #include using namespace std; ...

Read More

Structure vs class in C++

Nishtha Thakur
Nishtha Thakur
Updated on 03-Dec-2024 365 Views

In C++ the structure and class are basically the same. But there are some minor differences. These differences are like below. The class members are private by default, but members of structures are public. Let us see these two codes to see the differences. Example Code for Class Here is the following code for the class. #include using namespace std; class my_class {   public:  int x = 10; }; int main() {  my_class my_ob;  cout

Read More

C++ Program to Perform Complex Number Multiplication

Ankith Reddy
Ankith Reddy
Updated on 03-Dec-2024 7K+ Views

Complex numbers are numbers that are expressed as a+bi, where i is an imaginary number and a and b, are real numbers. Some examples of complex numbers are − 2+3i 5+9i 4+2i Example A program to perform complex number multiplication is as follows − #include using namespace std; int main(){  int x1, y1, x2, y2, x3, y3;  cout y1;  cout y2;  x3 = x1 * x2 - y1 * y2;  y3 = x1 * y2 + y1 * x2;  cout

Read More

Delete a node in a Doubly Linked List in C++

Hafeezul Kareem
Hafeezul Kareem
Updated on 03-Dec-2024 7K+ Views

In this tutorial, we are going to learn how to delete a node in the doubly linked list. Approach Let's see the steps to solve the problem. Write struct with data, prev, and next pointers. Write a function to insert the node into the doubly linked list. Initialize the doubly ...

Read More
Showing 3481–3490 of 5,962 articles
« Prev 1 347 348 349 350 351 597 Next »
Advertisements