Calculate Sum of Random Numbers in C Programming

Bhanu Priya
Updated on 06-Mar-2021 16:35:57

2K+ Views

In this program, we are adding random numbers that are generated in between 0 and 100.After every runtime, the result of sum of random numbers is different, i.e., we get a different result for every execution.The logic we use to calculate the sum of random numbers in between 0 to 100 is −for(i = 0; i

Write a C Program Using time.h Library Function

Bhanu Priya
Updated on 06-Mar-2021 16:33:29

357 Views

ProblemHow to display the current date and time in ISO standard format using C Programming language?SolutionThe current date and time of the input will be taken and we are trying to print the system time and date in ISO format.For example, Monday, Dec 15, 2020 10.50p.The built-in functions that we used in this program are −Time() − returns current time.Strftime() − converts the time to string form, this function include in time.h.Example Live Demo#include #include int main(){    time_t current = time(NULL);    char datetime[20];    strftime(datetime, sizeof(datetime), "%a, %d%b%y %H:%M", localtime(¤t));    puts(datetime);    return 0; }OutputThu, 31 Dec 20 ... Read More

Calculate Interest Amount Using Formula in C Language

Bhanu Priya
Updated on 06-Mar-2021 16:17:24

909 Views

ProblemWrite a C program to calculate the deposited amount incremented after some years with interestSolutionThe formula for calculating interest is −M=((r/100) * t); A=P*exp(M);Where r= rate of interest            t=no. of years            P=amount to be deposited            M=temporary variable            A= Final amount after interestAlgorithmSTART Step 1: declare double variables Step 2: read amount to be deposited Step 3: read rate of interest Step 4: read years you want to deposit Step 5: Calculate final amount with interest          I. ... Read More

Extract First Sub-Element from a List in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 14:15:37

13K+ Views

To extract only first element from a list, we can use sapply function and access the first element with double square brackets. For example, if we have a list called LIST that contains 5 elements each containing 20 elements then the first sub-element can be extracted by using the command sapply(LIST,"[[",1).Example1Consider the below data frame − Live DemoList1

Find Monthly Average from Different Date Data in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 14:15:10

2K+ Views

To find the monthly average from different date data, we first need to extract the months and year from date column and then find the average using aggregate function. For example, if we have a data frame called df which has three columns say x, month, and year then the monthly average can be found by using the command −aggregate(x~Month+Year,df,mean)Example1Consider the below data frame − Live DemoDate1

Change Code 'Yes' to 1 in R Data Frame Column

Nizamuddin Siddiqui
Updated on 06-Mar-2021 14:07:30

15K+ Views

To change the code “Yes” to 1, we can use ifelse function and set the Yes to 1 and others to 0. For example, if we have a data frame called df that contains a character column x which has Yes and No values then we can convert those values to 1 and 0 using the command ifelse(df$x=="Yes",1,0).Example1Consider the below data frame − Live DemoAgree

Count Particular Character in String Vector in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 14:02:00

179 Views

To find the count of a particular character in a string vector we can use nchar function along with gsub. For example, if we have a vector called x that contains string such India, Russia, Indonesia then we can find the number of times character i occurred then we can use the command nchar(gsub("[^i]","",x)) and the output will be 1 1 1 because first I’s in India and Indonesia will not be considered as they are in uppercase.Example1 Live Demox1

Find Mean Squared Error for Linear Model in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 14:01:33

4K+ Views

To find the mean squared error for linear model, we can use predicted values of the model and find the error from dependent variable then take its square and the mean of the whole output. For example, if we have a linear model called M for a data frame df then we can find the mean squared error using the command mean((df$y-predict(M))^2).Example1Consider the below data frame − Live Demox1

Create Data Frame Column with Letters of Both Size in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:57:25

413 Views

To create a data frame column with letters of both sizes, we can simply use the letters function and LETTERS function, the first one corresponds to lowercase letters and the latter corresponds to uppercase letters with single square brackets as shown in the below examples.Example1 Live Demodf1

Convert Matrix to Binary Matrix in R

Nizamuddin Siddiqui
Updated on 06-Mar-2021 13:55:48

2K+ Views

To convert a matrix to binary matrix, we can use as.matrix function and converting the matrix to logical matrix then adding 0 to the values greater than 0. For example, if we have a matrix called M then it can be converted to a binary matrix using the command −as.matrix((M

Advertisements