Found 35164 Articles for Programming

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

474 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

952 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

11K+ 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

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

Samual Sam
Updated on 24-Jun-2020 08:02:07

4K+ 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 Live Demo#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

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

karthikeya Boyini
Updated on 24-Jun-2020 08:03:12

1K+ 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 4*3 matrix has 4 rows and 3 columns as shown below −3 5 1 7 1 9 3 9 4 1 6 7A program that adds two matrices using multidimensional arrays is as follows.Example Live Demo#include using namespace std; int main() {    int r=2, c=4, sum[2][4], i, j;    int a[2][4] = {{1,5,9,4} , {3,2,8,3}};    int b[2][4] = {{6,3,8,2} , {1,5,2,9}};    cout

C++ Program to Calculate Average of Numbers Using Arrays

Samual Sam
Updated on 24-Jun-2020 08:04:50

7K+ Views

Average of numbers is calculated by adding all the numbers and then dividing the sum by count of numbers available.An example of this is as follows.The numbers whose average is to be calculated are: 10, 5, 32, 4, 9 Sum of numbers = 60 Average of numbers = 60/5 = 12A program that calculates average of numbers using arrays is as follows.Example Live Demo#include using namespace std; int main() {    int n, i;    float sum = 0.0, avg;    float num[] = {12, 76, 23, 9, 5};    n = sizeof(num) / sizeof(num[0]);    for(i = 0; i < n; i++)    sum += num[i];    avg = sum / n;    cout

Advertisements