Found 33676 Articles for Programming

C++ Program to Calculate Sum of Natural Numbers

Nishu Kumari
Updated on 09-May-2025 15:31:03

3K+ Views

In this article, we will write a C++ program to calculate the sum of the first n natural numbers. Natural numbers are positive numbers starting from 1(i.e., 1, 2, 3, ...). We will take a positive number n as input and find the sum of all natural numbers from 1 up to n. Let's understand with examples: Input: n = 5 The sum of the first 5 natural numbers is: 1 + 2 + 3 + 4 + 5 = 15 Output: 15 Input: n = 8 The sum of the first 8 natural numbers is: 1 + ... Read More

C++ Program to Find All Roots of a Quadratic Equation

karthikeya Boyini
Updated on 24-Jun-2020 07:47:19

8K+ Views

A quadratic equation is in the form ax2 + bx + c. The roots of the quadratic equation are given by the following formula −There are three cases −b2 < 4*a*c - The roots are not real i.e. they are complexb2 = 4*a*c - The roots are real and both roots are the same.b2 > 4*a*c - The roots are real and both roots are differentThe program to find the roots of a quadratic equation is given as follows.Example#include #include using namespace std; int main() {    int a = 1, b = 2, c = 1;    float discriminant, ... Read More

C++ Program to Find Largest Number Among Three Numbers

Samual Sam
Updated on 24-Jun-2020 07:22:40

5K+ Views

The largest number among three numbers can be found using if statement multiple times. This is given in a program as follows −Example Live Demo#include using namespace std; int main() {    int a = 5 ,b = 1 ,c = 9;    if(a>b) {       if(a>c)       cout

C++ Program to Check Whether a character is Vowel or Consonant

Nishu Kumari
Updated on 09-May-2025 15:16:30

12K+ Views

In this article, we'll show you how to write a C++ program to check if a given character is a vowel or a consonant. Vowels are the letters 'a', 'e', 'i', 'o', 'u'(both uppercase and lowercase), and all other alphabetic characters are consonants. For example, if we input the character 'a', the program will output 'vowel'. If we input 'b', it will output 'consonant'. In C++, there are different ways to check if a character is a vowel or consonant. Below are the common methods: Using an if-else statement ... Read More

C++ Program to Check Whether Number is Even or Odd

Samual Sam
Updated on 24-Jun-2020 07:24:38

13K+ Views

A number is even if it is divisible by two and odd if it is not divisible by two.Some of the even numbers are −2, 4, 6, 8, 10, 12, 14, 16Some of the odd numbers are −1, 3, 5, 7, 9, 11, 13, 15, 17Check Whether Number is Even or Odd using ModulusA program to check whether number is even or odd using modulus is as follows.Example Live Demo#include using namespace std; int main() {    int num = 25;    if(num % 2 == 0)    cout

C++ Program to Swap Two Numbers

Samual Sam
Updated on 24-Jun-2020 07:26:57

2K+ Views

There are two ways to create a program to swap two numbers. One involves using a temp variable and the second way does not use a third variable. These are explained in detail as follows −Program to Swap Two Numbers using temp VariableThe program to swap two numbers using a temp variable is as follows.Example Live Demo#include using namespace std; int main() {    int a = 10, b = 5, temp;    temp = a;    a = b;    b = temp;    cout

Python program to check for URL in a string

Sarika Singh
Updated on 04-Apr-2023 11:47:24

3K+ Views

This article will teach you how to determine whether a string contains a URL or not. In Python, strings are collections of bytes that represent Unicode characters. You can use single or double quotes and everything enclosed in them is considered as a string. When given a string, we will first determine whether it contains a URL. If one is found, we will then print the URL. Using findall() method We will employ Python's regular expression concept to resolve this issue. Regular expressions are supported by the Python re package. Using a particular syntax defined in a pattern, a regular ... Read More

C++ Program to find size of int, float, double and char in Your System

karthikeya Boyini
Updated on 23-Jun-2020 16:27:53

3K+ Views

Data Types in C++There are many data types in C++ but the most frequently used are int, float, double and char. Some details about these data types are as follows −int - This is used for integer data types which normally require 4 bytes of memory space.float - This is used for storing single precision floating point values or decimal values. float variables normally require 4 bytes of memory space.double - This is used for storing double precision floating point values or decimal values. Double variables normally require 8 bytes of memory space.char - This is used for storing characters. ... Read More

C++ Program to Find Quotient and Remainder

Samual Sam
Updated on 23-Jun-2020 16:30:27

11K+ Views

Quotient and Remainder are parts of division along with dividend and divisor.The number which we divide is known as the dividend. The number which divides the dividend is known as the divisor. The result obtained after the division is known as the quotient and the number left over is the remainder.dividend = divisor * quotient + remainderFor Example: If 15 is divided by 7, then 2 is the quotient and 1 is the remainder. Here, 15 is the dividend and 7 is the divisor.15 = 7 * 2 + 1A program to find quotient and remainder is as follows:Example Live Demo#include ... Read More

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

Advertisements