Found 26504 Articles for Server Side Programming

How to check if a matrix in R is in binary form?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 04:57:24

273 Views

A binary matrix contains values in form of twos such as 0/1, 1/2, Yes/No etc. If we have a matrix that has some values and we expect that there are only two values in the whole matrix then we can check whether only those two values exist in the matrix or not. For example, if we have a matrix called M then we can check whether it contains only 0/1 in the matrix by using the command all(M %in% 0:1).Example1Live Demo> M1 M1Output      [, 1] [, 2] [, 3] [, 4]  [1, ]    0    0   ... Read More

How to find the index of n number of maximums in each row of a matrix in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 04:56:32

149 Views

If a matrix has multiple columns and values in each row are different then there will be number of maximums equal to the number of columns. Suppose, we want to extract the index of two maximums in each row in a matrix called M then we can use the below command −t(apply(M, 1, order, decreasing=TRUE)[1:2, ]) Example1Live Demo> M1 M1Output      [, 1] [, 2] [, 3] [, 4]  [1, ]    7    4    4   10  [2, ]    7    1    4    3  [3, ]    9    6    6    4  [4, ... Read More

How to remove a character in an R data frame column?

Nizamuddin Siddiqui
Updated on 01-Nov-2023 14:50:11

50K+ Views

To remove a character in an R data frame column, we can use gsub() function which will replace the character with blank. For example, if we have a data frame called df that contains a character column say x which has a character ID in each value then it can be removed by using the command gsub("ID", "", as.character(df$x)).Example1Consider the below data frame −Live Demo> x1 x2 df1 df1Output        x1  x2 1    Male1  8 2  Female1  4 3    Male1  9 4    Male1  2 5    Male1  7 6  Female1  5 7    Male1  3 ... Read More

How to create a bar plot with bars for missing values in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 04:55:24

998 Views

To create a bar plot in R, we can use barplot function but if there exist some missing values in the data then we can use ggplot2 package. For example, if we have a data frame having two vectors say x and y, x containing categorical values with NA as one of the values and y having counts/frequency for each of the categories then the bar plot will be created by using the command ggplot(df, aes(x, y))+geom_bar(stat="identity").ExampleConsider the below data frame −Live Demo> x y df dfOutput     x  y 1    A 24 2    B 21 3 ... Read More

Write a C program to maintain cricketer’s information in tabular form using structures

Mandalika
Updated on 05-Mar-2021 12:14:40

7K+ Views

ProblemHow to store the cricketer’s data in tabular form in sorted order based on average runs using structures in C Programming language.SolutionLet’s try to enter the cricketer information such as name, age, no of matches and average runs he scored. It will be entered in the console at runtime using the structure concept.And try to display the information in tabular form in sorted order based on average runs scored by each person so that it is easy to identify each person's details clearly.The logic we used to sort the cricketers in ascending order based on average runs they scored is ... Read More

Write a C program to calculate the average word length of a sentence using while loop

Mandalika
Updated on 05-Mar-2021 12:11:51

939 Views

ProblemEnter a sentence at run time and write a code for calculating the average length of words that are present in a sentenceSolutionAlgorithmSTART Step 1: declare character, int and double variables Step 2: Enter any statement Step 3: while loop        Check condition stmt[i]=getchar()) != ''        True then enter into loop        Increment I and call the function at step 5 Step 4: Print the average length return by function        From step 5 Step 5: called function calculatewordlength          i. declare and initialize         ... Read More

Write a C program to print numbers in words using elseif statements

Mandalika
Updated on 05-Mar-2021 12:08:07

5K+ Views

ProblemWithout using a switch case, how can you print a given number in words using the C programming language?SolutionIn this program, we are checking three conditions to print a two-digit number in words −if(no99)entered number is not a two digitelse if(no==0)print first number as zeroelse if(no>=10 && no=20 && no=10 && no=20 && no

Write a C program to print the message in reverse order using for loop in strings

Mandalika
Updated on 05-Mar-2021 12:05:26

813 Views

Here we write a program to reverse the sentence without predefined functions. By using for loop, we can easily print statement in reverse order.Program 1#include int main(){    char stmt[100];    int i;    printf("enter the message:");    for(i=0;i=0;i--) //printing each char in reverse order    putchar(stmt[i]);    putchar('');    return 0; }Outputenter the message: Hi welcome to my world the reverse statement is: dlrow ym ot emoclew iHProgram 2Here, we will write a C program to reverse a string using strrev library function −#include #include void main(){    //Declaring two strings//    char result[50], string[25];    //Reading string 1 ... Read More

How to print a one-month calendar of user choice using for loop in C?

Mandalika
Updated on 06-Mar-2021 18:36:13

6K+ Views

The logic to print a one-month calendar is as follows −for(i=1;i

Generate an even squares between 1 to n using for loop in C Programming

Mandalika
Updated on 05-Mar-2021 11:56:52

1K+ Views

Even square numbers are - 22, 42, 62, 82,……… = 4, 16, 36, 64, 100, ………AlgorithmSTART Step 1: declare two variables a and n Step 2: read number n at runtime Step 3: use for loop to print square numbers         For a=2; a*a

Advertisements