Found 7346 Articles for C++

C++ Program to Remove all Characters in a String Except Alphabets

Arjun Thakur
Updated on 24-Jun-2020 09:44:44

582 Views

A string is a one-dimensional character array that is terminated by a null character. It may contain characters, digits, special symbols etc.A program to remove all characters in a string except alphabets is given as follows.Example#include using namespace std; int main() {    char str[100] = "String@123!!";    int i, j;    cout

C++ Program to Copy Strings

Chandu yadav
Updated on 24-Jun-2020 09:45:13

3K+ Views

A string is a one dimensional character array that is terminated by a null character. The value of a string can be copied into another string. This can either be done using strcpy() function which is a standard library function or without it.The program to copy a string without using strcpy() function is given as follows −Example Live Demo#include using namespace std; int main() {    char str1[100] = "Magic";    char str2[100];    int i;    for(i = 0; str1[i] != '\0'; i++)    str2[i] = str1[i];    str2[i] = '\0';    cout

C++ Program to Concatenate Two Strings

Samual Sam
Updated on 24-Jun-2020 08:14:20

824 Views

A string is a one dimensional character array that is terminated by a null character. Concatenation of two strings is the joining of them to form a new string. For example.String 1: Mangoes are String 2: tasty Concatenation of 2 strings: Mangoes are tastyA program to concatenate two strings is given as follows.Example Live Demo#include using namespace std; int main() {    char str1[100] = "Hi...";    char str2[100] = "How are you";    int i,j;    cout

C++ program to Reverse a Sentence Using Recursion

karthikeya Boyini
Updated on 24-Jun-2020 08:14:54

1K+ Views

A string is a one dimensional character array that is terminated by a null character. The reverse of a string is the same string in opposite order. For example.Original String: Apple is red Reversed String: der si elppAA program that reverses a sentence in the form of a string using recursion is given as follows.Example Live Demo#include using namespace std; void reverse(char *str) {    if(*str == '\0')    return;    else {       reverse(str+1);       cout

C++ Program to convert Octal Number to Decimal and vice-versa

Samual Sam
Updated on 24-Jun-2020 08:17:03

497 Views

In a computer system, the octal number is expressed in the octal numeral system while the decimal number is in the decimal numeral system. The octal number is in base 8 while the decimal number is in base 10.Examples of decimal numbers and their corresponding octal numbers are as follows.Decimal NumberOctal Number10127010625311620A program that converts the octal numbers into decimal and the decimal numbers into octal is as follows −Example Live Demo#include #include using namespace std; void DecimalToOctal(int decimalNum) {    int octalNum = 0, placeValue = 1;    int dNo = decimalNum;    while (decimalNum != 0) {       octalNum += (decimalNum % 8) * placeValue;       decimalNum /= 8;       placeValue *= 10;    } cout

C++ Program to Access Elements of an Array Using Pointer

karthikeya Boyini
Updated on 24-Jun-2020 08:17:53

12K+ Views

Pointers store the memory location or address of variables. In other words, pointers reference a memory location and obtaining the value stored at that memory location is known as dereferencing the pointer.A program that uses pointers to access a single element of an array is given as follows −Example Live Demo#include using namespace std; int main() {    int arr[5] = {5, 2, 9, 4, 1};    int *ptr = &arr[2];    cout

C++ Program to Store Information of a Student in a Structure

Samual Sam
Updated on 24-Jun-2020 08:18:52

5K+ Views

A structure is a collection of items of different data types. It is very useful in creating complex data structures with different data type records. A structure is defined with the struct keyword.An example of a structure is as follows.struct employee {    int empID;    char name[50];    float salary; };A program that stores student information in a structure is given as follows.Example Live Demo#include using namespace std; struct student {    int rollNo;    char name[50];    float marks;    char grade; }; int main() {    struct student s = { 12 , "Harry" , 90 , 'A' };    cout

C++ Program to Find the Number of Vowels, Consonants, Digits and White Spaces in a String

karthikeya Boyini
Updated on 24-Jun-2020 08:20:17

1K+ Views

A string is a one dimensional character array that is terminated by a null character. There can be many vowels, consonants, digits and white spaces in a string.For example.String: There are 7 colours in the rainbow Vowels: 12 Consonants: 15 Digits: 1 White spaces: 6A program to find the number of vowels, consonants, digits and white spaces in a string is given as follows.Example Live Demo#include using namespace std; int main() {    char str[] = {"Abracadabra 123"};    int vowels, consonants, digits, spaces;    vowels = consonants = digits = spaces = 0;    for(int i = 0; str[i]!='\0'; ... Read More

C++ Program to Find the Length of a String

Samual Sam
Updated on 24-Jun-2020 08:20:42

2K+ Views

A string is a one dimensional character array that is terminated by a null character. The length of a string is the number of characters in the string before the null character.For example.char str[] = “The sky is blue”; Number of characters in the above string = 15A program to find the length of a string is given as follows.Example Live Demo#include using namespace std; int main() {    char str[] = "Apple";    int count = 0;    while (str[count] != '\0')    count++;    cout

C++ Program to Find Transpose of a Matrix

karthikeya Boyini
Updated on 24-Jun-2020 08:21:39

12K+ Views

A matrix is a rectangular array of numbers that is arranged in the form of rows and columns. A transpose of a matrix is a new matrix in which the rows of the original are the columns now and vice versa. For example.A matrix is given below −1 2 3 4 5 6 7 8 9The transpose of the above matrix is as follows.1 4 7 2 5 8 3 6 9A program to find the transpose of a matrix is as follows −Example Live Demo#include

Advertisements