Found 27758 Articles for Server Side Programming

C++ Program to Store and Display Information Using Structure

Arjun Thakur
Updated on 24-Jun-2020 09:55:46

6K+ 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 and displays information using structure is given as follows.Example Live Demo#include using namespace std; struct employee {    int empID;    char name[50];    int salary;    char department[50]; }; int main() {    struct employee emp[3] = { { 1 , "Harry" , 20000 , "Finance" } , { 2 , "Sally" , 50000 , "HR" } ,    { 3 , "John" , 15000 , "Technical" } };    cout

C++ Program to Calculate Standard Deviation

Chandu yadav
Updated on 24-Jun-2020 09:56:27

7K+ Views

Standard deviation is the measure of how spread out the numbers in the data are. It is the square root of variance, where variance is the average of squared differences from the mean.A program to calculate the standard deviation is given as follows.Example Live Demo#include #include using namespace std; int main() {    float val[5] = {12.5, 7.0, 10.0, 7.8, 15.5};    float sum = 0.0, mean, variance = 0.0, stdDeviation;    int i;    for(i = 0; i < 5; ++i)    sum += val[i];    mean = sum/5;    for(i = 0; i < 5; ++i)    variance += pow(val[i] - mean, 2);    variance=variance/5;    stdDeviation = sqrt(variance);    cout

C++ Program to Check if it is a Sparse Matrix

George John
Updated on 24-Jun-2020 09:57:21

494 Views

A sparse matrix is a matrix in which majority of the elements are 0. In other words, if more than half of the elements in the matrix are 0, it is known as a sparse matrix. For example −The matrix given below contains 5 zeroes. Since the number of zeroes is more than half the elements of the matrix, it is a sparse matrix.1 0 2 5 0 0 0 0 9A program to check if it is a sparse matrix or not is as follows.Example Live Demo#include using namespace std; int main () {    int a[10][10] = { {2, ... Read More

C++ Program to Perform Matrix Multiplication

Ankith Reddy
Updated on 24-Jun-2020 09:41:13

7K+ 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*2 matrix has 3 rows and 2 columns as shown below −8 1 4 9 5 6A program that performs matrix multiplication is as follows.Example Live Demo#include using namespace std; int main() {    int product[10][10], r1=3, c1=3, r2=3, c2=3, i, j, k;    int a[3][3] = { {2, 4, 1} , {2, 3, 9} , {3, 1, 8} };    int b[3][3] = { {1, 2, 3} , {3, 6, 1} , {2, 4, 7} };    if (c1 != r2) {       cout

C++ Program to Find Factorial of a Number using Recursion

Arjun Thakur
Updated on 24-Jun-2020 09:42:22

12K+ Views

Factorial of a non-negative integer n is the product of all the positive integers that are less than or equal to n.For example: The factorial of 4 is 24.4! = 4 * 3 * 2 *1 4! = 24The factorial of an integer can be found using a recursive program or an iterative program.The following program demonstrates a recursive program to find the factorial of a number −Example Live Demo#include using namespace std; int fact(int n) {    if ((n==0)||(n==1))    return 1;    else    return n*fact(n-1); } int main() {    int n = 4;    cout

C++ Program to Find Factorial of a Number using Iteration

Chandu yadav
Updated on 24-Jun-2020 09:42:42

3K+ Views

Factorial of a non-negative integer n is the product of all the positive integers that are less than or equal to n.For example: The factorial of 6 is 720.6! = 6 * 5 * 4 * 3 * 2 *1 6! = 720The factorial of an integer can be found using a recursive program or an iterative program.A for loop can be used to find the factorial of a number using an iterative program. This is demonstrated as follows.Example Live Demo#include using namespace std; int main() {    int n = 6, fact = 1, i;    for(i=1; i

C++ Program to Find the Frequency of a Character in a String

George John
Updated on 24-Jun-2020 09:43:27

14K+ Views

A string is a one-dimensional character array that is terminated by a null character. Frequency of characters in a string is the number of times they occur in a string. For example −String: Football is a sport The frequency of alphabet o in the above string is 3A program to find the frequency of a particular alphabet is given as follows.Example Live Demo#include using namespace std; int main() {    char str[100] = "this string contains many alphabets";    char c = 'a';    int count = 0;    for(int i = 0; str[i] != '\0'; i++) {       if(str[i] == c)       count++;    }    cout

C++ Program to convert Decimal Numbers to Octal

Ankith Reddy
Updated on 24-Jun-2020 09:44:02

1K+ 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 Number81070106253177A program that converts the decimal numbers into octal is as follows.Example Live Demo#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 Remove all Characters in a String Except Alphabets

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

526 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

Advertisements