## C program to sort all columns and rows of matrix

Updated on 01-Sep-2021 13:10:15
ProblemWrite a code to sort all the rows of matrix in an ascending order and all columns in the descending order. The size of matrix and elements of matrix are given by user at runtime.SolutionThe solution to sort all the rows of matrix in an ascending order and all columns in the descending order in the C programming language is explained below −The logic used to sort the rows in an ascending order is as follows −for (i=0;i

## C program to interchange the diagonal elements in given matrix

Updated on 01-Sep-2021 13:07:55
ProblemWe need to write a code to interchange the main diagonal elements with the secondary diagonal elements. The size of the matrix is given at runtime.If the size of matrix m and n values are not equal, then it prints that the given matrix is not a square.Only a square matrix can interchange the main diagonal elements and can interchange with the secondary diagonal elements.SolutionThe solution to write a C program to interchange the diagonal elements in given matrix is as follows −The logic to interchange the diagonal elements is explained below −for (i=0;i

## C program to perform operations on two halves’ in a single array

Updated on 01-Sep-2021 13:05:11
ProblemWrite a program to accept a one-dimensional array of N elements and split into two halves. Later on, sort the first half in an ascending order and the second half into descending order.SolutionThe solution to perform the two operations on two halves’ in a single array in C programming language is explained below −The logic used to sort the first half in an ascending order is as follows −for (i=0; i

## C program to find the areas of geometrical figures using switch case

Updated on 01-Sep-2021 13:02:24
ProblemFind the areas of rectangle, square, triangle, circle by using the switch case statement, User need to enter base, height, side, radius, breadth and length at runtime to calculate the areas of all geometrical figures.SolutionThe solution to find the areas of rectangle, square, triangle, circle by using the switch case statement is explained below −FormulaeThe formulae for finding the areas of the respective geometrical figures are as follows −Area of rectangle = breadth *length;Area of square = side * side;Area of circle = 3.142*radius*radius;Area of triangle = 0.5 *base*height;ExampleFollowing is the C program to find the areas of rectangle, square, ... Read More

## C program to find the second largest and smallest numbers in an array

Updated on 01-Sep-2021 13:00:26
Enter the array elements and then, arrange the numbers in descending order by using the swapping technique. Later on, with the help of an index location, try to print the second largest and the second smallest element in an array.An array is used to hold the group of common elements under one name.The array operations in C programming language are as follows −InsertDeleteSearchAlgorithmGiven below is an algorithm to find the second largest and the second smallest numbers in an array −Step 1 − Declare and read the number of elements.Step 2 − Declare and read the array size at runtime.Step ... Read More

## C program to generate the value of x power n using recursive function

Updated on 01-Sep-2021 12:56:48
ProblemCompute the value of xn , where x and n both are the inputs given by the user at runtimeSolutionThe solution to generate the value of x power n by using the recursive function in C programming language is as follows −The logic to find xn is mentioned below −//Calling function: Xpow=power(x, n); //Called function: if (n==1)    return(x); else if ( n%2 == 0)    return (pow(power(x, n/2), 2)); /*if n is even*/ else    return (x*power(x, n-1));AlgorithmRefer an algorithm given below to generate the value of x power n by using the recursive function.Step 1 − Read long ... Read More

## What are different variations of for loop iterations?

Updated on 01-Sep-2021 12:55:42
The general form of the for statement is as follows −for (initialization; condition; operation) statement;Initialization is an assignment statement which is used to set the loop control variable.Condition is a relational expression that determines when the loop exits.The operation defines that how the loop variable changes each time when the loop is repeated.In for loops, the conditional test is performed at the top of the loop. This means that the code inside the loop may not be executed when the condition is false.To begin with as in the following example −x = 10; for (y=10; y != x; ++y) printf ... Read More

## What is exit() function in C language?

Updated on 01-Sep-2021 12:54:14
The exit () function is used to break out of a loop. This function causes an immediate termination of the entire program done by the operation system.The general form of the exit() function is as follows −void exit (int code);The value of the code is returned to the calling process, which is done by an operation system. Generally, zero is used as return code to indicate normal program termination.ExampleFollowing is the C program for use of exit() function −#include void main(){    char ch;    printf("B: Breakfast");    printf("L: Lunch");    printf("D: Dinner");    printf("E: Exit");    printf("Enter your choice:"); ... Read More

## C program to print four powers of numbers 1 to 9 using nested for loop

Updated on 01-Sep-2021 12:52:49
Nested loops consist of one loop placed inside another loop.An example of a nested for loop is as follows −for (initialization; condition; operation){    for (initialization; condition; operation){       statement;    }    statement; }In this example, the inner loop runs through its full range of iterations for each single iteration of the outer loop.ExampleFollowing is the C program to print the table of first four powers of numbers 1 to 9 by using nested for loop − Live Demo#include void main(){    int i, j, k, temp, I=1;    printf("I\tI^2\tI^3\tI^4 ");    printf("--------------------------------");    for ( i ... Read More

## What are reading and writing characters in C language?

Updated on 01-Sep-2021 12:50:41
In C programming language the reading and writing characters are as follows −The simplest of the console I/O functions are getche (), which reads a character from the keyboard, and putchar (), which prints a character to the screen.The getche () function works on until a key is pressed and then, returns its value. The key pressed is also echoed to the screen automatically.The putchar () function will write its character argument to the screen at the current cursor position.The declarations for getche () and putchar () are −int getche (void); int putchar (int c);The header file for getche () ... Read More
Previous 1 ... 3 4 5 6 7 8 9 ... 144 Next