C Articles - Page 20 of 95

How to use Pre-defined mathematical function in C language?

Bhanu Priya
Updated on 08-Mar-2021 10:29:13

336 Views

ProblemHow to find the cube root of any given number by using the C programming language?SolutionAlgorithmStep 1: Enter any number at run time Step 2: Read from console Step 3: Compute result         Result:pow(number, 1.0/3.0) Step 4: Increment result Step 5: Print resultExampleFollowing is the C program to find the cube root of any given number −//finding cube root of given number// #include #include #include void main(){    int number, result;    printf("Enter any number: ");    scanf("%d", &number);    result=pow(number, 1.0/3.0);    result++;    printf("\Cube of %d is: %d", number, result);    getch(); }OutputWhen the above ... Read More

What are the input and output for strings in C language?

Bhanu Priya
Updated on 08-Mar-2021 10:27:24

5K+ Views

An array of characters (or) collection of characters is called a string.Input and output for stringsExampleFollowing is the C program for input and output for strings −#include main ( ){    char a[30];    printf("enter your name");    scanf ( "%s", a);    printf ("your name is %s", a);    getch ( ); }OutputWhen the above program is executed, it produces the following result −1. Enter your name : Lucky 2. Enter your name : Lucky Lol Your name is Lucky Your name is LuckyNote −‘&’ is not used for accepting strings because name of the string itself specifies the ... Read More

Explain the END OF FILE (EOF) with a C Program

Bhanu Priya
Updated on 14-Sep-2023 21:13:13

31K+ Views

The End of the File (EOF) indicates the end of input.After we enter the text, if we press CTRL+Z, the text terminates i.e. it indicates the file reached end nothing to read.AlgorithmRefer to the algorithm given below for EOF.Step 1: Open file in write mode. Step 2: Until character reaches end of the file, write each character in filepointer. Step 3: Close file. Step 4: Again open file in read mode. Step 5: Reading the character from file until fp equals to EOF. Step 5: Print character on console. Step 6: Close file.ExampleFollowing is the C program for End of ... Read More

How to access an array element in C language?

Bhanu Priya
Updated on 08-Mar-2021 10:02:11

7K+ Views

An array is a group of related data items that share a common name. A particular value in an array is identified by using its "index number" or "subscript".The advantage of an array is as follows −The ability to use a single name to represent a collection of items and to refer to an item by specifying the item number enables the user to develop concise and efficient programs.The syntax for declaring array is as follows −datatype array_name [size];For example, float height [50]This declares ‘height’ to be an array containing 50 float elements.int group[10]This declares the ‘group’ as an array ... Read More

What do you mean by buffer in C language?

Bhanu Priya
Updated on 08-Mar-2021 09:50:04

11K+ Views

A temporary storage area is called buffer. All input output (I/O) devices contain I/O buffer.When we try to pass more than the required number of values as input then, the remaining values will automatically hold in the input buffer. This buffer data automatically go to the next input functionality, if it is exists.We have to clear the buffer before the next input is taken in.ExampleFollowing is the C program for buffer −#include void main(){    int a, b;    printf(" Enter a value: ");    scanf("%d", &a);    printf(" Enter b value: ");    scanf("%d", &b);    printf(" a+b=%d ", ... Read More

What are Backslash character constants in C language?

Bhanu Priya
Updated on 08-Mar-2021 07:06:32

5K+ Views

A backslash ( \ ) that allows a visual representation of some nongraphic characters introduces an escape.One of the common escape constants is the newline character ( ).Backslash CharactersThe backslash characters are as follows −CharacterMeaning‘\a’alert‘\b’backspace‘\f’form feed‘’newline‘\t’horizontal tab‘\r’carriage return‘\v’vertical tab‘\’backslash‘\’ ’single quote‘\" ’double quote‘\?’Question markExample programFollowing is the C program for the backslash character constants −Example Live Demo#include #define PI 3.14 float area; void main(){    double r;    r=1.0;    area = PI * r * r;    printf("Area is %d ", area); // /n is used to enter the next statement in newline }OutputArea is 1492442840Read More

Explain the constant type qualifier in C language

Bhanu Priya
Updated on 08-Mar-2021 06:10:16

273 Views

Type qualifiers add special attributes to existing datatypes in C programming language.There are three type qualifiers in C language and constant type qualifier is explained below −ConstThere are three types of constants, which are as follows −Literal constantsDefined constantsMemory constantsLiteral constants − These are the unnamed constants that are used to specify data.For example, a=b+7 //Here ‘7’ is literal constant.Defined constants − These constants use the preprocessor command ‘define" with #For example, #define PI 3.1415Memory constants − These constants use ‘C’ qualifier ‘const’, which indicates that the data cannot be changed.The syntax is as follows −const type identifier = valueFor ... Read More

Decimal to Binary conversion using C Programming

Bhanu Priya
Updated on 08-Mar-2021 06:05:08

4K+ Views

ProblemHow to convert a decimal number to a binary number by using the function in the C programming language?SolutionIn this program, we are calling a function to binary in main(). The called function to binary will perform actual conversion.The logic we are using is called function to convert decimal number to binary number is as follows −while(dno != 0){    rem = dno % 2;    bno = bno + rem * f;    f = f * 10;    dno = dno / 2; }Finally, it returns the binary number to the main program.ExampleFollowing is the C program to ... Read More

C Program to print the sum of boundary elements of a matrix

Bhanu Priya
Updated on 24-Mar-2021 14:28:37

6K+ Views

Given a matrix, we need to print the boundary elements of the matrix and display their sum.ExampleRefer the matrix given below −Given matrix1 2 3 4 5 6 7 8 9Boundary Matrix1 2 3 4   6 7 8 9Sum of boundary elements: 1 + 2 + 3 + 4 + 6 + 7 + 8 + 9 = 40The logic to find the sum of boundary matrix is as follows −for(i = 0; i

C program to calculate power of a given number

Bhanu Priya
Updated on 24-Mar-2021 14:14:46

19K+ Views

Take two integers from the user for base and exponent and calculate the power as explained below.ExampleConsider the following for writing a C program.Suppose base =3Exponent = 4Power=3*3*3*3AlgorithmFollow the algorithm given below −Step 1: Declare int and long variables. Step 2: Enter base value through console. Step 3: Enter exponent value through console. Step 4: While loop. Exponent !=0    i. Value *=base    ii. –exponent Step 5: Print the result.ExampleThe following program explains how to calculate power of given number in C language.#include int main(){    int base, exponent;    long value = 1;    printf("Enter a base value: ... Read More

Advertisements