Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Programming Articles - Page 1357 of 3366
17K+ Views
ProblemHow to read a series of items that are present in a file and display the data in columns or tabular form using C ProgrammingSolutionCreate a file in write mode and write some series of information in the file and close it again open and display the series of data in columns on the console.Write mode of opening the fileFILE *fp; fp =fopen ("sample.txt", "w");If the file does not exist, then a new file will be created.If the file exists, then old content gets erased & current content will be stored.Read mode of opening the file FILE *fp fp =fopen ... Read More
317 Views
Open a file in reading mode. If the file exists, then write a code to count the number of lines in a file. If the file does not exist, it displays an error that the file is not there.The file is a collection of records (or) It is a place on the hard disk where data is stored permanently.Following are the operations performed on files −Naming the fileOpening the fileReading from the fileWriting into the fileClosing the fileSyntaxFollowing is the syntax for opening and naming a file −1) FILE *File pointer; Eg : FILE * fptr; 2) File pointer ... Read More
1K+ Views
A pointer is a variable that stores the address of another variable.Features of PointersPointer saves the memory space.The execution time of a pointer is faster because of direct access to memory location.With the help of pointers, the memory is accessed efficiently, i.e., memory is allocated and deallocated dynamically.Pointers are used with data structures.Declaring a pointerint *p;It means ‘p’ is a pointer variable that holds the address of another integer variable.Initialization of a pointerAddress operator (&) is used to initialize a pointer variable.For example, int qty = 175; int *p; p= &qty;Accessing a variable through its pointerTo access the value of ... Read More
983 Views
ProblemWrite a C program to define the structure and display the size and offsets of member variablesStructure − It is a collection of different datatype variables, grouped together under a single name.General form of structure declarationdatatype member1; struct tagname{ datatype member2; datatype member n; };Here, struct - keywordtagname - specifies name of structuremember1, member2 - specifies the data items that make up structure.Examplestruct book{ int pages; char author [30]; float price; };Structure variablesThere are three ways of declaring structure variables −Method 1struct book{ int pages; char author[30]; float price; }b;Method 2struct{ ... Read More
2K+ Views
ProblemMention some of the legal and illegal declarations and initializations while doing C programming?Before discussing the legal and illegal statements let’s see how to declare and initialize the variables in C.Variable declarationFollowing is the syntax of variable declaration −SyntaxDatatype v1, v2, … vn;Where v1, v2, ...vn are names of the variables.For example, int sum;float a, b;Variable can be declared in two ways −local declarationglobal declarationThe ‘local declaration’ is declaring a variable inside the main block and its value is available within that block.The ‘global declaration’ is declaring a variable outside the main block and its value is available throughout the ... Read More
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
421 Views
To display the data frame summary in vertical order, we can use lapply and cbind function along with the summary function. For example, if we have a data frame called df then the summary of df in vertical order can be found by using the below command −lapply(df, function(x) cbind(summary(x)))Example1Consider the below data frame −Live Demo> x1 x2 x3 x4 x5 df1 df1Output x1 x2 x3 x4 x5 1 4 0 2 2 6 2 7 2 4 1 7 3 7 2 3 3 6 4 4 0 4 5 2 5 5 2 ... Read More
10K+ Views
To select rows of an R data frame that are non-Na, we can use complete.cases function with single square brackets. For example, if we have a data frame called that contains some missing values (NA) then the selection of rows that are non-NA can be done by using the command df[complete.cases(df), ].Example1Consider the below data frame −Live Demo> x1 x2 x3 df1 df1Output x1 x2 x3 1 1 NA NA 2 NA 5 3 3 1 5 NA 4 1 NA NA 5 NA 5 NA 6 NA 5 3 7 NA 5 NA 8 1 ... Read More
453 Views
To create stacked plot with density using ggplot2, we can use geom_density function of ggplot2 package and position="stack". For example, if we have a data frame called df that contains two columns say x and y, where x is categorical and y is numerical then the stacked plot with density can be created by using the command −ggplot(df, aes(y, y=..density..))+geom_density(aes(fill=x), position="stack")ExampleConsider the below data frame −Live Demo> x y df dfOutput x y 1 C 3 2 C 5 3 B 4 4 A 7 5 B 1 6 A 6 7 D 4 8 C 3 9 C 7 ... Read More
3K+ Views
To create a plot using ggplot2 by excluding values greater than a certain value, we can use subsetting with single square brackets and which function. For example, if we have a data frame called df that contains two columns say x and y, then the point chart by including values of x that are greater than 0 can be created by using the command −ggplot(df[which(df$x>0), ], aes(x, y))+geom_point()ExampleConsider the below data frame −Live Demo> x y df dfOutput x y 1 -0.62160328 0.38477515 2 0.68287365 -1.56169067 3 0.75259774 ... Read More