C++ Articles

Page 295 of 597

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

Samual Sam
Samual Sam
Updated on 11-Mar-2026 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#include using namespace std; int main() {    int num = 25;    if(num % 2 == 0)    cout

Read More

C++ Program to Find Largest Number Among Three Numbers

Samual Sam
Samual Sam
Updated on 11-Mar-2026 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#include using namespace std; int main() {    int a = 5 ,b = 1 ,c = 9;    if(a>b) {       if(a>c)       cout

Read More

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

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 3K+ Views

A palindrome number remains the same if its digits are reversed i.e its value does not change. A palindrome number can also be called symmetric. For example: The numbers 12321, 1551, 11 etc are palindromes as they do not change even if their digits are reversed.A program that checks if a number is palindrome or not is as follows.Example#include using namespace std; void palindrome(int num) {    int rev=0,val;    val = num;    while(num > 0) {       rev = rev * 10 + num % 10;       num = num / 10;    }    if(val==rev)    cout

Read More

C++ Program to Multiply Two Matrix Using Multi-dimensional Arrays

Samual Sam
Samual Sam
Updated on 11-Mar-2026 5K+ Views

A matrix is a rectangular array of numbers that is arranged in the form of rows and columns.An example of a matrix is as follows.A 3*3 matrix has 3 rows and 3 columns as shown below −8 6 3 7 1 9 5 1 9A program that multiplies two matrices using multidimensional arrays is as follows.Example#include using namespace std; int main() {    int product[10][10], r1=2, c1=3, r2=3, c2=3, i, j, k;    int a[2][3] = { {2, 4, 1} , {2, 3, 9} };    int b[3][3] = { {1, 2, 3} , {3, 6, 1} , {2, 9, 7} };    if (c1 != r2) {       cout

Read More

strcat() vs strncat() in C++

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 853 Views

Both strcat() and strncat() are predefined string functions in C++. Details about these are given as follows.strcat()This function is used for concatenation. It appends a copy of the source string at the end of the destination string and returns a pointer to the destination string. The syntax of strcat() is given as follows.char *strcat(char *dest, const char *src)A program that demonstrates strcat() is given as follows.Example#include #include using namespace std; int main() {    char str1[20] = "Mangoes are ";    char str2[20] = "yellow";    strcat(str1, str2);    cout

Read More

CHAR_BIT in C++

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 1K+ Views

The CHAR_BIT is the number of bits in char. It is declared in “limits.h” header file in C++ language. It is of 8-bits per byte.Here is an example of CHAR_BIT in C++ language,Example#include using namespace std; int main() {    int x = 28;    int a = CHAR_BIT*sizeof(x);    stack s;    cout

Read More

Ceil and floor functions in C++

karthikeya Boyini
karthikeya Boyini
Updated on 11-Mar-2026 5K+ Views

The ceil FunctionThe ceil function returns the smallest possible integer value which is equal to the value or greater than that. This function is declared in “cmath” header file in C++ language. It takes single value whoes ceil value is to be calculated. The datatype of variable should be double/float/long double only.Here is the syntax of ceil function in C++ language,double ceil(double x); float ceil(float x);Here is an example of ceil function in C++ language,Example#include #include using namespace std; int main() {    float var = 1234.25;    float res;    res = ceil(var);    cout

Read More

Const member functions in C++

Samual Sam
Samual Sam
Updated on 11-Mar-2026 20K+ Views

The const member functions are the functions which are declared as constant in the program. The object called by these functions cannot be modified. It is recommended to use const keyword so that accidental changes to object are avoided.A const member function can be called by any type of object. Non-const functions can be called by non-const objects only.Here is the syntax of const member function in C++ language, datatype function_name const();Here is an example of const member function in C++, Example#include using namespace std; class Demo {    int val;    public:    Demo(int x = 0) {   ...

Read More

isspace() function in C++

Arjun Thakur
Arjun Thakur
Updated on 11-Mar-2026 4K+ Views

The isspace() function is a predefined function in ctype.h. It specifies whether the argument is a whitespace character or not. Some of the whitespace characters are space, horizontal tab, vertical tab etc.A program that implements isspace() function by counting the number of spaces in a string is given as follows −Example#include #include using namespace std; int main() {    char str[] = "Coding is fun";    int i, count = 0;    for(i=0; str[i]!='\0';i++) {       if(isspace(str[i]))       count++;    }    cout

Read More

getchar_unlocked() in C

George John
George John
Updated on 11-Mar-2026 497 Views

The function getchar_unlocked() is deprecated in Windows because it is a thread unsafe version of getchar(). It is suggested not to use getchar_unlocked(). There is no stream lock check that’s why getchar_unlocked is unsafe. The function getchar_unlocked() is faster than getchar().Here is the syntax of getchar_unlocked() in C language,int getchar_unlocked(void);A program of getchar_unlocked() in C is as follows −Example#include int main() {    char val;    val = getchar_unlocked();    printf("Enter the character : ");    printf("Entered character : %c", val);    return 0; }OutputHere is the outputEnter the character : a Entered character : a

Read More
Showing 2941–2950 of 5,962 articles
« Prev 1 293 294 295 296 297 597 Next »
Advertisements