ProblemWhy sorting makes searching easier in C language? How can you judge the sorting efficiency in C?SolutionSorting is the process of arranging elements either in ascending (or) descending order.The term sorting came into existence when humans realized the importance of searching quickly.There are different things in life that we need to search for, particular record in database, roll numbers in a list, a number in a telephone directory, a specific page in a book etc.If the data was kept in an unordered and unsorted form, it becomes difficult to search a particular thing. But fortunately, the concept of sorting came ... Read More
We can write a program in C for printing some content in to the file and print the following −Number of characters entered into the file.Reverse the characters entered into the file.First, try to store number of characters into the file by opening the file in write mode.For entering data into file, we use the logic as mentioned below −while ((ch = getchar( ))!=EOF) {//after enter data press cntrl+Z to terminate fputc(ch, fp); }With the help of ftell, rewind, fseek functions, we can reverse the content that we already entered into the file.ExampleGiven below is a C program for ... Read More
Random accessing of files in C language can be done with the help of the following functions −ftell ( )rewind ( )fseek ( )ftell ( )It returns the current position of the file ptr.The syntax is as follows −int n = ftell (file pointer)For example, FILE *fp; int n; _____ _____ _____ n = ftell (fp);Note − ftell ( ) is used for counting the number of characters which are entered into a file.rewind ( )It makes file ptr move to beginning of the file.The syntax is as follows −rewind (file pointer);For example, FILE *fp; ----- ----- ... Read More
In C programming language, pointer to pointer or double pointer is a variable that holds the address of another pointer.DeclarationGiven below is the declaration for pointer to pointer −datatype ** pointer_name;For example, int **p;Here, p is a pointer to pointer.Initialization‘&’ is used for initialization.For example, int a = 10; int *p; int **q; p = &a;AccessingIndirection operator (*) is used for accessingSample programFollowing is the C program for double pointer − Live Demo#include main ( ){ int a = 10; int *p; int **q; p = &a; q = &p; printf("a =%d ", a); ... Read More
File is a collection of records (or) is a place on hard disk, where data is stored permanently. By using C commands, we can access the files in different ways.Operations on filesThe operations that can be carried out on files in C language are as follows −Naming the file.Opening the file.Reading from the file.Writing into the file.Closing the file.SyntaxThe syntax for opening and naming file is as follows −FILE *File pointer;For example, FILE * fptr;File pointer = fopen ("File name”, "mode”);For example, fptr = fopen ("sample.txt”, "r”);FILE *fp; fp = fopen ("sample.txt”, "w”);The syntax for reading from file is as ... Read More
I/O refers to the input - output functions in C language.High level I/OThese are easily understood by human beingsThe advantage is portability.Low level I/OThese are easily understood by computer.The advantage is that execution time is less.The disadvantage is that Non portability.High level I/O FunctionsThe high level input - output (I/O) functions are explained below −FunctionDescriptionfprintf ( )write data into a filefscanf ( )read data from a fileputc ( )/ fputc()write a character into a filegetc ( ) /fgetc()read a character from a fileputw ( )write a number into a filegetw ( )read number from a filefputs ( )write a string ... Read More
Lord Hanuman is the great central characters of the Indian epic Ramayana. Hanuman is well-known for his strength and he is immune to all sorts of weapons. He has got extreme speed (manojavam, marutha tulya vegam) effulgence, wisdom, no fear of death (Chiranjeevi), has won over the senses that lure. He has the knowledge of Eight Siddhis and Nine devotions. Even the world’s dangerous weapon Brahmastra can never harm him. He is the most powerful yet very obedient devotee of Shri Rama.The accurate prediction of distance from Earth to Sun:It was written in Hanuman Chalisa, “Yug Sahasra Yojana Par Bhanu, ... Read More
The cumulative sum till ith element refers to the total sum from 0th to ith element.The program statement is to form a new list from a given list. The ith element in the new list will be the cumulative sum from 0 to ith element in the given list.For example, Input[10, 20, 30, 40, 50]Output[10, 30, 60, 100, 150]Input[1, 2, 3, 4, 5]Output[1, 3, 6, 10, 15]Following is a program to form a cumulative sum list using the input list −The input list is passed to the function cumSum() which returns the cumulative sum list.We declare an empty list cum_list ... Read More
Python has an inbuilt round() function to round off a number.The round() method in Python takes two parameters −The first one is the number to be rounded off.The second one specifies the number of digits to which the number must be rounded off.Here, the second parameter is optional.If second parameter is not specified, then the round() method returns the integer using floor() and ceil().It will look for the digits after the decimal.If those are less than 5, it returns the floor() of the number passed.Whereas if the digits after decimal are greater than 5, it returns the ceil() of the ... Read More
Patterns in Python can be printed using nested for loops. The outer loop is used to iterate through the number of rows whereas the inner loop is used to handle the number of columns. The print statement is modified to form various patterns according to the requirement.The patterns can be star patterns, number patterns, alphabet patterns. The patterns can be of different shapes, triangle, pyramids, etc.ExampleAll these patterns can be printed with the help of for loops with modified print statements which forms these different patterns.The basic idea between the printing of these patterns is the same with slight differences.We ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP