C++ Articles - Page 696 of 719

C++ Program to Add Two Numbers

sudhir sharma
Updated on 09-May-2025 15:26:44

13K+ Views

In this article, we'll show how to add two numbers using C++ and display the result. Adding two numbers is a basic arithmetic operation, meaning we combine their values to get a total. We will see different methods to solve this. Different Ways to Add Two Numbers in C++ In C++, there are various approaches to add two numbers, each approach using its own cases and advantages. Below are the mentioned list: Using Addition Operator Using User Input Using Increment and Decrement Operators ... Read More

C++ Program To Convert Decimal Number to Binary

Nishu Kumari
Updated on 13-May-2025 16:58:31

5K+ Views

In a computer system, the binary number is expressed in the binary numeral system while the decimal number is in the decimal numeral system. The binary number is in base 2 while the decimal number is in base 10. Examples of decimal numbers and their corresponding binary numbers are as follows: Decimal Number ... Read More

C++ Program to Print Number Entered by User

karthikeya Boyini
Updated on 23-Jun-2020 16:36:19

5K+ Views

The objects “cin” and “cout” are used in C++ for input and output respectively. cin is an instance of the istream class and is attached to the standard input device such as the keyboard. cout is an instance of the ostream class and is connected to the standard output device such as the display screen.A program that prints the number entered by the user is as follows −Example Live Demo#include using namespace std; int main() {    int num;    coutnum;    cout

C++ Program to Check Whether a Number is Prime or Not

Nishu Kumari
Updated on 13-May-2025 16:59:42

4K+ Views

A prime number is a whole number greater than one and the only factors of a prime number should be one and itself. For example, 2, 3, 5, 7, and 11 are prime numbers. Our task is to write a C++ program that checks if a given number is prime or not. We will cover different approaches to solve this problem. We'll cover the following methods for checking whether a number is prime or not: Using a Simple Loop Using the Square Root Method Using ... Read More

C++ Program to Display Factors of a Number

Nishu Kumari
Updated on 13-May-2025 17:04:52

12K+ Views

A factor is a number that divides a given number completely without leaving a remainder. In this article, we'll show you how to display all the factors of a number using different methods in C++. For example, the factors of 12 are 1, 2, 3, 4, 6, and 12. In this article, we will look at two ways to find and display the factors of a number: Basic Iterative Approach Optimized Square Root Approach Factors of a Number Using Iterative (Basic) Approach In this approach, we use loop to go ... Read More

C++ Program to Display Fibonacci Series

Samual Sam
Updated on 23-Jun-2020 16:24:22

16K+ Views

The fibonacci series contains numbers in which each term is the sum of the previous two terms. This creates the following integer sequence −0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377…….The recurrence relation that defines the fibonacci numbers is as follows −F(n) = F(n-1) + F(n-2) F(0)=0 F(1)=1Programs to Display Fibonacci SeriesThere are two methods to display fibonacci series i.e. using dynamic programming and recursive programming. These are further explained as follows −Dynamic ProgrammingExample#include using namespace std; void fib(int n) {    int f[n];    int i;    f[0] = 0;    f[1] ... Read More

How to get last 2 characters from string in C# using Regex?

Sreemaha
Updated on 22-Jun-2020 12:16:45

1K+ Views

Set the string −string str = "Cookie and Session";Use the following Regex to get the last 2 characters from string −Regex.Match(str,@"(.{2})\s*$")The following is the code −Example Live Demousing System; using System.Text.RegularExpressions; public class Demo {    public static void Main() {       string str = "Cookie and Session";       Console.WriteLine(Regex.Match(str,@"(.{2})\s*$"));    } }Outputon

C/C++ Pointers vs Java references

Nishu Kumari
Updated on 09-May-2025 11:34:00

2K+ Views

In this article, we will show you the difference between C/C++ pointers and Java references. C/C++ use pointers to manually control how memory is used and accessed. Java, on the other hand, does not support pointers and uses references instead, which manage memory automatically. Pointer in C/C++ A pointer is a variable that holds the address of another variable in memory. It gives you direct access to that memory, which is powerful but can lead to errors if not used carefully. Syntax Here's the syntax where we declare a pointer with an asterisk(*) ... Read More

How can we read Python dictionary using C++?

Samual Sam
Updated on 28-Aug-2025 09:29:08

569 Views

A dictionary in Python is a collection of key-value pairs where each key must be unique. The lists, which are indexed by numbers, are accessed using keys that can be immutable types, strings, numbers, or tuples. Lists cannot be used as keys because they can be modified. Dictionaries are created using {}, and key-value pairs are added with commas. We can store, retrieve, and delete values using their keys. Using the list() returns all keys, while sorting them. To check if a key exists, we can use the in keyword. If a key is replaced, then its old value is replaced. ... Read More

Java is also not pure object-oriented like c++

Pythonista
Updated on 30-Jul-2019 22:30:22

426 Views

the main() method in Java code is itself inside a class. The static keyword lets the main() method which is the entry point of execution without making an object but you need to write a class. In C++, main() is outside the class and writing class it self is not mandatory. Hence, C++ is not a pure object oriented language bu Java is a completely object oriented language.

Advertisements