Programming Articles - Page 1356 of 3366

How to add approximately equal sign in a plot using ggplot2 in R?

Nizamuddin Siddiqui
Updated on 06-Mar-2021 11:22:11

590 Views

To add approximately equal sign in a plot using ggplot2, we can use tilde sign twice as ~~ in geom_text function of ggplot2 package. For example, we can do this by using the following syntax geom_text(aes(label="NULL%~~%")). Check out the below example to understand how it works.ExampleConsider the below data frame − Live Demox

Write a C program to demonstrate post increment and pre increment operators

Bhanu Priya
Updated on 06-Mar-2021 08:02:49

3K+ Views

Increment operator (++)It is used to increment the value of a variable by 1. There are two types of increment operators, pre-increment and post-increment.The increment operator is placed before the operand in pre-increment and the value is first incremented and then the operation is performed on it.For example, z = ++a; a= a+1 z=aThe increment operator is placed after the operand in post-increment and the value is incremented after the operation is performed.For example, z = a++; z=a a= a+1Example 1Following is an example for pre-increment operator − Live Demomain ( ){    int A= 10, Z;    Z= ++A;   ... Read More

Write C program using isupper() function

Bhanu Priya
Updated on 06-Mar-2021 07:59:15

213 Views

ProblemHow to identify a total number of upper-case alphabets in a string using C Programming?SolutionThe logic we used to count number of upper-case letters in a sentence is as follows −for(a=string[0];a!='\0';i++){    a=string[i];    if (isupper(a)){       counter=counter+1;       //counter++;    } }Example 1 Live Demo#include #include void main(){    //Declaring integer for number determination, string//    int i=0;    char a;    char string[50];    int counter=0;    //Reading User I/p//    printf("Enter the string :");    gets(string);    //Using For loop and predefined function to count upper case alpha's//    for(a=string[0];a!='\0';i++){       a=string[i]; ... Read More

Explain malloc function in C programming

Bhanu Priya
Updated on 06-Mar-2021 07:56:53

695 Views

ProblemWrite a C program to display and add the elements using dynamic memory allocation functions.SolutionIn C, the library function malloc allocates a block of memory in bytes at runtime. It returns a void pointer, which points to the base address of allocated memory and it leaves the memory uninitialized.Syntaxvoid *malloc (size in bytes)For example, int *ptr;ptr = (int * ) malloc (1000);int *ptr;ptr = (int * ) malloc (n * sizeof (int));Note − It returns NULL, if the memory is not free.Example Live Demo#include #include void main(){    //Declaring variables and pointers, sum//    int numofe, i, sum=0;    int *p; ... Read More

Write a C program using time.h library function

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

353 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

Write a C program to check the atexit() function

Bhanu Priya
Updated on 06-Mar-2021 07:52:09

556 Views

The atexit() is a function that allows the user to register a function that has to be called based on program termination.It is a predefined function that is included in stdlib header files.Example 1 Live Demo#include #include void welcome(void){    printf("Welcome to New, "); } void world(void){    printf("World"); } int main(){    //test atexit ,call user defined function    atexit(world);    atexit(welcome);    return 0; }OutputWelcome to New, WorldExample 2 Live Demo#include #include void first(void){    printf("This is a beautiful, "); } void second(void){    printf("Wonderful life"); } int main(){    //test atexit ,call user defined function    atexit(second);    atexit(first); ... Read More

Calculate interest amount by using formula in C language

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

905 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

Explain the functions fread() and fwrite() used in files in C

Bhanu Priya
Updated on 06-Mar-2021 07:46:28

23K+ Views

ProblemWrite a C program for storing the details of 5 students into a file and print the same using fread() and fwrite()SolutionThe fread() function reads the entire record at a time.Syntaxfread( & structure variable, size of (structure variable), no of records, file pointer);Examplestruct emp{    int eno;    char ename [30];    float sal; } e; FILE *fp; fread (&e, sizeof (e), 1, fp);The fwrite() function writes an entire record at a time.Syntaxfwrite( & structure variable , size of structure variable, no of records, file pointer);Examplestruct emp{    int eno:    char ename [30];    float sal; } e; FILE ... Read More

Concatenating n characters from source string to destination string in C

Bhanu Priya
Updated on 06-Mar-2021 07:44:01

853 Views

ProblemWrite a C program to concatenate n characters from source string to destination string using strncat library functionSolutionThe strcat functionThis function is used for combining or concatenating two strings.The length of the destination string must be greater than the source string.The resultant concatenated string will be in the source string.Syntaxstrcat (Destination String, Source string);Example 1#include main(){    char a[50] = "Hello";    char b[20] = "Good Morning";    clrscr ( );    strcat (a, b);    printf("concatenated string = %s", a);    getch ( ); }OutputConcatenated string = Hello Good MorningThe strncat functionThis function is used for combining or ... Read More

Write a C program to compare two strings using strncmp library function

Bhanu Priya
Updated on 06-Mar-2021 07:39:52

3K+ Views

Strncmp is a predefined library function present in string.h file, it used to compare two strings and display which string is greater.The strcmp fucntion (String comparison)This function compares 2 strings. It returns the ASCII difference of the first two non– matching characters in both the strings.Syntaxint strcmp (string1, string2);If the difference is equal to zero, then string1 = string2.If the difference is positive, then string1> string2.If the difference is negative, then string1 0) {       printf("%s is greater than %s", string1, string2);    } else {       printf("%s is less than %s", string1, string2);    } ... Read More

Advertisements