Skip to main content

Posts

Writing Data Into A File using C.

Writing Data Into A File We can write data into a file. The following is the algorithm for writing data: Create a file using fopen() function Write data into a file using fprintf() and fputs() functions Close a file using fclose() function For testing, we create data into a file, demo.txt. For implementation, create a file, called filewrite.c, and write this code. #include <stdio.h> int main( int argc , const char* argv[]) { int i; FILE *f; f = fopen("demo.txt", "w+");   for (i= 0 ;i< 5 ;i++){    fprintf(f, "fprintf message %d\n",i);    fputs("fputs message\n", f); // no format } fclose(f); printf("Data was written into a file\n"); return 0 ; } Save this code. Compile and run this program.  

C program to add two matrix

C program to add two matrix This c program add two matrices i.e. compute the sum of two matrices and then print it. Firstly user will be asked to enter the order of matrix (number of rows and columns) and then two matrices. For example if the user entered order as 2, 2 i.e. two rows and two columns and matrices as First Matrix :- 1 2 3 4 Second matrix :- 4 5 6 7 then output of the program (sum of First and Second matrix) will be 5  7 9 11 #include <stdio.h>   int main ( ) { int m , n , c , d , first [ 10 ] [ 10 ] , second [ 10 ] [ 10 ] , sum [ 10 ] [ 10 ] ;   printf ( "Enter the number of rows and columns of matrix \n " ) ; scanf ( "%d%d" , & m , & n ) ; printf ( "Enter the elements of first matrix \n " ) ;   for ( c = 0 ; c < m ; c ++ ) for ( d = 0 ; d < n ; d ++ ) scanf ( "%d" , & first [ c ] [ d ] ) ;   printf (...

Deen Dayal Upadhyay Gorakhpur University RESULTS

DDU Gorakhpur results chahiye to yaha click kare                                                                       RESULTS  

C Program to swap two numbers using pointers and function.

C Program to swap two numbers using pointers and function.   #include <stdio.h> void swap(int *a,int *b); int main() {   int num1=5,num2=10;   swap(&num1,&num2);        /* address of num1 and num2 is passed to swap function */      printf( "Number1 = %d\n" ,num1);   printf( "Number2 = %d" ,num2);      return 0; } void swap(int *a,int *b) {  /* pointer a and b points to address of num1 and num2 respectively */   int temp;   temp=*a;   *a=*b;   *b=temp; }

To check if given string is palindrome or not.

To check if given string is palindrome or not. #include <stdio.h> #include <string.h> #include <conio.h>   int main()   {   char a[100], b[100]; printf ( "Enter the string to check if it is a palindrome\n" );   gets (a);   strcpy (b,a);   strrev (b);   if ( strcmp(a,b) == 0 )   printf ( "Entered string is a palindrome.\n" );   else   printf ( "Entered string is not a palindrome.\n" );   return 0;   }

C Program to find transpose of a Matrix

Transpose : Transpose of a Matrix means changing Rows into Columns and vice-versa.                                                          Statement of C Program : This Program accepts the Matrix and prints its Transpose.         #include<stdio.h> #include<conio.h> void main() { int A[2][3] , B[3][2]; int i, j;                                    /* 'i ' used for rows and ' j ' used for columns */ clrscr(); printf(" Enter the elements of A\n"); for(i=0 ; i<2 ; i+...

C Program to Check Leap Year

C program to check whether a year is leap year or not using if else statement .      #include <stdio.h>      int main()      {       int year;       printf( "Enter a year: " );       scanf( "%d" ,&year);       if (year%4 == 0)       {           if ( year%100 == 0)   /* Checking for a century year */           {               if ( year%400 == 0)                  printf( "%d is a leap year." , year);               else            ...