Showing posts with label C Programming. Show all posts
Showing posts with label C Programming. Show all posts

Monday, 12 June 2017

C Program to check whether an year is a Leap Year or not.




This is a C program which checks the input year for Leap year.

A year is said to be a leap year, if it exactly divisible by 4 but not for century years(years ending with 00) and also an year is called Leap Year when it is exactly divisible by 400.




PROGRAM : 

#include <stdio.h>
#include <stdlib.h>

void checkLeapYear(int);
int main()
{
    int input_year;
    printf("\n Enter any year : ");
    scanf("%d",&input_year);
    checkLeapYear(input_year);
    getch();
    return 0;
}

void checkLeapYear(int year)
{
    int r1,r2;
    r1 = year%4 ;
    r2 = year%100;
    if((r1 == 0) && (r2!=0) || year%400 == 0)
    {
        printf("\n The given year %d is a LEAP Year",year);
    }
    else
    {
        printf("\n The given year %d is NOT a Leap Year",year);
    }
}

Output:

C Program to check whether an year is a Leap Year or not

C Program to check whether an year is a Leap Year or not

Friday, 26 August 2016

C Program on string copy without using strcpy()

A simple C program on string copy without using library function strcpy(). Here we read each character in the first string until the end and copy it to the second string.

Refer below for screenshot and program,



Download code

PROGRAM : 

#include<stdio.h>

int main()
{
    char str1[100],str2[100];
    int i=0;

    printf("Enter a string: ");
    gets(str1);

    while(str1[i]!='\0')
    {
        str2[i] = str1[i];
        i++;
    }
    str2[i]='\0';

    printf("\nCopied String: %s\n",str2);
    return 0;
}
Download code

OUTPUT :  

C Program on string copy without strcpy()

Thursday, 25 August 2016

C Program to concat two strings using strcat()


A simple C program which concats two strings. the second string appends to first string and forms a concatenated string.

Here string concatination is done using strcat() function.

Look below for program and the screenshot,


Download code

PROGRAM : 

#include<stdio.h>
#include<string.h>

int main()
{
    char string1[50], string2[50];
    printf("\nEnter First string :");
    gets(string1);
    printf("\nEnter Second string :");
    gets(string2);
    strcat(string1,string2);
    printf("\nConcatenated string is :%s\n", string1);
    return (0);
}
Download code

OUTPUT : 

C Program - String concatenation using strcat()

C Program to concat two strings without using strcat()


A simple C program which concats two strings. the second string appends to first string and forms a concatenated string.

Here string concatination is done without using strcat() function.

Look below for program and the screenshot,





Download code

PROGRAM : 

#include<stdio.h>
#include<string.h>

int main()
{
    char string1[50], string2[50];
    int i, j;
    printf("\nEnter First string :");
    gets(string1);
    printf("\nEnter Second string :");
    gets(string2);
    i = strlen(string1);
    for (j = 0; string2[j] != '\0'; i++, j++)
    {
        string1[i] = string2[j];
    }
    string1[i] = '\0';
    printf("\nConcatinated string is :%s\n", string1);
    return (0);
}
Download code

OUTPUT : 

C Program - String concatenation without strcat

Wednesday, 24 August 2016

C Program to reverse a string without using strrev()



This is a simple C program where a string is reversed by replacing its last character with first one until all the characters are replaced.

Look below for program and screenshot.




Download code

PROGRAM : 

#include <stdio.h>
#include <string.h>

void reverse_string(char *str)
{
    if (str == 0 || (*str == 0) )
    {
        return;
    }
    char *start = str;
    char *end = start + strlen(str) - 1;
    char temp;
    while (end > start)
    {
        temp = *start;
        *start = *end;
        *end = temp;
        ++start;
        --end;
    }
}

int main(void)
{
    char input[50];
    printf("\nEnter the string :");
    gets(input);
    reverse_string(input);
    printf("%s\n", input);
    return 0;
}

Download code

OUTPUT :  

C Program - Reverse a string

Monday, 22 February 2016

Data Structures - C Program to implement Linked List Operations - Insert , Delete , Update , Display

Linked List is another data structure consisting of group of nodes which together represent a sequence. Each node has two parts one for the value and other for link to the next node.
Linked lists allows dynamic memory allocation.

Singly-linked-list.svg
A singly linked list whose nodes contain two fields: an integer value and a link to the next node



Some of the operations in a linked list are :

  • Insertion into the list
  • Deletion from the list
  • Updation of the value
  • Display the list





Download code

PROGRAM :

#include <stdio.h>
 #include <stdlib.h>
 #include <malloc.h>

 struct node
 {
     int value;
     struct node *next;
 };
 typedef struct node snode;
 snode *newnode, *ptr, *prev, *temp;
 snode *first = NULL, *last = NULL;

 int main()
 {
     int ch;
     char ans = 'Y';
     while (ans == 'Y'||ans == 'y')
     {
  printf("\n1.Insert node at first");
  printf("\n2.Insert node at last");
  printf("\n3.Insert node at position");
  printf("\n4.Delete Node from any Position");
  printf("\n5.Update Node Value");
  printf("\n6.Display List");
  printf("\n7.Exit\n");
  printf("\nEnter your choice: \t");
  scanf("%d", &ch);

  switch (ch)
  {
  case 1:
      insertNodeFirst();
      break;
  case 2:
      insertNodeLast();
      break;
  case 3:
      insertNodePosition();
      break;
  case 4:
      deleteNode();
      break;
  case 5:
      updateNode();
      break;
  case 6:
      displayList();
      break;
  case 7:
      return 0;
      break;
  default:
      printf("\n...Invalid Choice...\n");
      break;
  }
  printf("\nDo you want to continue ? (Y/N) \t");
  scanf(" %c", &ans);
     }
     return 0;
 }
 snode* createNode(int val)
 {
     newnode = (snode *)malloc(sizeof(snode));
     if (newnode == NULL)
     {
  printf("\nMemory was not allocated");
  return 0;
     }
     else
     {
  newnode->value = val;
  newnode->next = NULL;
  return newnode;
     }
 }
 void insertNodeFirst()
 {
     int val;
     printf("\nEnter the value for the node: \t");
     scanf("%d", &val);
     newnode = createNode(val);
     if (first == last && first == NULL)
     {
  first = last = newnode;
  first->next = NULL;
  last->next = NULL;
     }
     else
     {
  temp = first;
  first = newnode;
  first->next = temp;
     }
     printf("\nInserted Successfully");
 }
 void insertNodeLast()
 {
     int val;

     printf("\nEnter the value for the Node: \t");
     scanf("%d", &val);
     newnode = createNode(val);
     if (first == last && last == NULL)
     {
  first = last = newnode;
  first->next = NULL;
  last->next = NULL;
     }
     else
     {
  last->next = newnode;
  last = newnode;
  last->next = NULL;
     }
     printf("\nInserted Successfully");
 }
 void insertNodePosition()
 {
     int pos, val, count = 0, i;
     printf("\nEnter the value for the Node: \t");
     scanf("%d", &val);
     newnode = createNode(val);
     printf("\nEnter the position: \t");
     scanf("%d", &pos);
     ptr = first;
     while (ptr != NULL)
     {
  ptr = ptr->next;
  count++;
     }
     if (pos == 1)
     {
  if (first == last && first == NULL)
  {
      first = last = newnode;
      first->next = NULL;
      last->next = NULL;
  }
  else
  {
      temp = first;
      first = newnode;
      first->next = temp;
  }
  printf("\nInserted Successfully");
     }
     else if (pos>1 && pos<=count)
     {
  ptr = first;
  for (i = 1; i < pos; i++)
  {
      prev = ptr;
      ptr = ptr->next;
  }
  prev->next = newnode;
  newnode->next = ptr;
  printf("\nInserted Successfully");
     }
     else
     {
  printf("Position is out of range");
     }
 }
 void deleteNode()
 {
     int pos, count = 0, i;

     if (first == NULL)
     {
  printf("No nodes in the list to delete\n");
     }
     else
     {
  printf("\nEnter the position of value to be deleted: \t");
  scanf(" %d", &pos);
  ptr = first;
  if (pos == 1)
  {
      first = ptr->next;
      printf("\nElement deleted successfully");
  }
  else
  {
      while (ptr != NULL)
      {
          ptr = ptr->next;
          count = count + 1;
      }
      if (pos > 0 && pos <= count)
      {
          ptr = first;
          for (i = 1; i < pos; i++)
          {
              prev = ptr;
              ptr = ptr->next;
          }
          prev->next = ptr->next;
      }
      else
      {
          printf("Position is out of range");
      }
      free(ptr);
      printf("\nElement deleted successfully");
  }
     }
 }
 void updateNode()
 {
     int oldval, newval, flag = 0;

     if (first == NULL)
     {
  printf("No nodes in the list to update\n");
     }
     else
     {
  printf("\nEnter the value to be updated: \t");
  scanf("%d", &oldval);
  printf("\nEnter the new value: \t");
  scanf("%d", &newval);
  for (ptr = first; ptr != NULL; ptr = ptr->next)
  {
      if (ptr->value == oldval)
      {
          ptr->value = newval;
          flag = 1;
          break;
      }
  }
  if (flag == 1)
  {
      printf("\nUpdated Successfully");
  }
  else
  {
      printf("\nValue not found in List");
  }
     }
 }
 void displayList()
 {
     if (first == NULL)
     {
  printf("No nodes in the list to display\n");
     }
     else
     {
  for (ptr = first; ptr != NULL; ptr = ptr->next)
  {
      printf("%d\t", ptr->value);
  }
     }
 }
 

Download code

OUTPUT :

C - Linked List Operations - Insertion at front

C - Linked List Operations - Insertion at last and  any position

C - Linked List Operations -  Deletion of node

C - Linked List Operations - Updation of value

C - Linked List Operations - Display List

Tuesday, 16 February 2016

Data Structures - C Program to implement queue operations using an array

Queue is a data structure  , similar to Stack , but here in queue we have openings at both the ends , one for insertion and other for deletion.


Some of the common operations of queue are :

  • Adding an item to queue(enqueue)
  • Removing an item from a queue(dequeue)
  • Overflow Condition(Queue full)
  • Underflow Condition(Queue empty)
  • Getting the front element(peek)



Overflow situation occur when the queue is full and then we are trying to  insert/add another item to the queue .

Underflow situation occur when the queue is empty and the we are trying to remove/delete an item from the queue.

The principle of  queue is First In First Out (FIFO).

Download code


PROGRAM :

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int rear = -1,front = -1,item,MAX ,choice ,i;
    printf("Enter Size of Queue : \t ");
    scanf("%d" , &MAX);
    int QueueArray[MAX];
    while (1)
    {
        printf("\nQueue Operations  :");
        printf("\n1. Insert/Add");
        printf("\n2. Remove/Delete");
        printf("\n3. Peek/Front item");
        printf("\n4. Display Queue");
        printf("\n5. Exit");
        printf("\nEnter your choice :\t");
        scanf("%d" , &choice);
        switch (choice)
        {
        case 1:
            if (rear == MAX - 1)
            {
                printf("Queue Overflow \n");
            }
            else
            {
                if (front == -1)
                {
                    front = 0;
                }
                printf("Inset the element in queue : \t");
                scanf("%d" , &item);
                rear = rear + 1;
                QueueArray[rear] = item;
            }

            break;
        case 2:

            if (front == -1 || front > rear)
            {
                printf("Queue Underflow \n");
                break;
            }
            else
            {
                printf("Element deleted from queue is %d \n" , QueueArray[front] );
                front = front + 1;
            }
            break;
        case 3:
            if (front == -1 || front > rear)
            {
                printf("Queue Underflow \n");
                break;
            }
            else
            {
                printf("The front element is : %d \t" , QueueArray[front]);
            }
            break;
        case 4:
            if (front == -1 || front > rear)
            {
                printf("Queue Underflow \n");
                break;
            }
            else
            {
                printf("The current elements in queuue are :");
                for (i = front; i <= rear; i++)
                {
                    printf("%d " ,QueueArray[i]);
                }
            }
            break;
        case 5:
            return 0;
            break;
        default:
            printf("Wrong Entry \n ");
            break;
        }

    }
    return 0;
}
Download code

OUTPUT :

C - Queue Operations
C- Queue Overflow
   
C - Queue Underflow


Download code

Friday, 5 February 2016

CPU Scheduling Algorithm - Round Robin(C)


This is a C program which implements one of the CPU Scheduling algorithm called Round Robin(RR).

Round robin algorithm is mainly used in time sharing systems , it is also similar to First Come First Served(FCFS) algorithm but FCFS does not have that time slicing switch.

All the jobs gets executed in this scheduling algorithm , so the advantage here is , its Starvation free.




Download Code

PROGRAM :

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int bt_c[10],bt[10],i,j,n,m[50],r,q,e=0;
    float f,avg=0;
    printf("\nEnter how many jobs ?\t");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        printf("Enter burst time for job %d :\t",i);
        scanf("%d",&bt[i]);
        bt_c[i]=bt[i]; //stores job has how much burst  time in array  i
    }
    printf("\nEnter Quantum (time slice value) :\t");
    scanf("%d",&q);
    int max=0;
    max=bt[1];
    for(j=1; j<=n; j++)
        if(max<=bt[j])
            max=bt[j];

    if((max%q)==0)
        r=(max/q);
    else
        r=(max/q)+1;
    for(i=1; i<=r; i++)
    {
        printf("\n\nRound %d",i);
        for(j=1; j<=n; j++)
        {
            if(bt[j]>0)
            {
                bt[j]=bt[j]-q;

                if(bt[j]<=0)
                {
                    bt[j]=0;
                    printf("\njob %d is completed",j);
                }
                else
                    printf("\njob %d remaining time is %d",j,bt[j]);
            }
        }

    }
    for(i=1; i<=n; i++)
    {
        e=0;
        for(j=1; j<=r; j++)
        {
            if(bt_c[i]!=0)
            {
                if(bt_c[i]>=q)
                {
                    m[i+e]=q;
                    bt_c[i]-=q;
                }
                else
                {
                    m[i+e]=bt_c[i];
                    bt_c[i]=0;
                }
            }
            else
                m[i+e]=0;
            e=e+n;
        }
    }
    for(i=2; i<=n; i++)
        for(j=1; j<=i-1; j++)
            avg=avg+m[j];
    for(i=n+1; i<=r*n; i++)
    {
        if(m[i]!=0)
        {
            for(j=i-(n-1); j<=i-1; j++)
                avg=m[j]+avg;
        }
    }
    f=avg/n;
    printf("\n\n\nTOTAL WATING TIME:%f\t",avg);
    printf("\n\nAVERAGE WAITING TIME:%f\t\n",f);
    return 0;
}
Download Code

OUTPUT : 

C Program - CPU Scheduling Algorithm : Round Robin

Sunday, 8 March 2015

C Program to Calculate Easter Sunday



This is a C Program which computes the date of Easter Sunday.

The date of the Easter changes from year to year. Generally its is the first sunday after the first full moon of Spring.New Testment says that the crucification of Jesus Christ took place during Passover(which is after first full moon of Spring).

So the date changes every year. An algorithm was invented by a mathematician Carl Friedrich Gauss in 1800 to compute the date of Easter Sunday.





Here is the algorithm by Carl Friedrich Gauss :

Step 1  :  Let Y be the year
Step 2  :  Divide Y by 19 to get a remainder as A
Step 3  :  Divide Y by 100 to get a quotient  B and a remainder C
Step 4  :  Divide B by 4 to get a quotient D and a remainder E
Step 5  :  Divide (8*B+13) by 25 to get a quotient G
Step 6  :  Divide (19*A+B-D-G+15) by 30 to get a remainder H
Step 7  :  Divide C by 4 to get a quotient J and a remainder K
Step 8  :  Divide (A+11*H) by 319 to get a quotient M
Step 9  :  Divide (2*E+2*J-K-H+M+32) by 7 to get a remainder R
Step 10:  Divide (H-M+R+90) by 25 to get a quotient N
Step 11: Divide (H-M+R+N+19) by 32 to get a remainder P


So for a given year Y Easter Sunday falls on day P and month N


PROGRAM : 
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int y;
    printf("Enter Year :\t");
    scanf("%d",&y);
    if(y <= 0)
        printf("\nPlease enter a valid Year\n");
    else
    {
        int a =y%19;
        int b = y/100;
        int c = y%100;
        int d = b/4;
        int e = b%4;
        int g = (8*b+13)/25;
        int h =(19*a+b-d-g+15)%30;
        int j = c/4;
        int k = c%4;
        int m = (a+11*h)/319;
        int r = (2*e+2*j-k-h+m+32)%7;
        int n = (h-m+r+90)/25;
        int p = (h-m+r+n+19)%32;



        printf("\n\nEaster Sunday for year %d is  ",y);
        switch(n)
        {
        case 1:
            printf("January %d\n" ,p);
            break;
        case 2:
            printf("February %d\n" ,p);
            break;
        case 3:
            printf("March %d\n" ,p);
            break;
        case 4:
            printf("April %d\n" ,p);
            break;
        case 5:
            printf("May %d\n" ,p);
            break;
        case 6:
            printf("June %d\n" ,p);
            break;
        case 7:
            printf("July %d\n" ,p);
            break;
        case 8:
            printf("August %d\n" ,p);
            break;
        case 9:
            printf("September %d\n" ,p);
            break;
        case 10:
            printf("October %d\n" ,p);
            break;
        case 11:
            printf("November %d\n" ,p);
            break;
        case 12:
            printf("December %d\n" ,p);
            break;
        default:
            printf("Invalid ,TRY AGAIN !!" );
        }
    }

    return 0;
}

OUTPUT : 

C Program for computing Easter Sunday



C Program for computing Easter Sunday

Wednesday, 21 January 2015

C Program to find length of a string without using strlen()


This is simple C Program which prints out the length of a string without using the string function strlen().

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char name[20];
    int i,length=0;
    printf("Enter any name(String) : \t");
    gets(name);
    for(i=0; name[i]!='\0'; i++)
        length++;
    printf("\nThe length of the string is \t %d \n",i);
    return 0;
}

OUTPUT : 
C Program to find length of a string without using strlen()

C Program to find the length of a string.


This is a C Program to find the length of a String.
Here we use string function strlen() to find the length of a string.
All the string functions are present in the header string.h

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    char name[40];
    printf("Enter any name(String) : \t");
    gets(name);
    printf("\nThe length of the string you entered is : \t %d" ,strlen(name));
    return 0;
}

OUTPUT :

C Program to find the leegth of a string

Getting Started with Strings in C - Using gets() and puts() functions.


This is a simple C Program which uses string functions gets() and puts() to read and display the content respectively.


PROGRAM :
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
    char name[20];
    printf("Enter any name(String) : \t");
    gets(name);
    printf("\n You Entered : " );
    puts(name);
    return 0;
}

OUTPUT : 
C Programming - Strings - gets() and puts()

Monday, 19 January 2015

C Program to print Palindrome Traingle


This is a C Program which prints thee palindrome triangle based on the input given.

Here , check each row elements , you can see a palindrome sequence.

Palindrome Traingle


PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,n;
    printf("Enter number of lines[height of triangle] : \t");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
            printf(" ");
        for(j=1; j<=i; j++)
            printf("%d",j);
        for(j=i-1; j>=1; j--)
            printf("%d",j);
        printf("\n");
    }

    return 0;
}


OUTPUT : 
C Program to print PalindromeTraingle


Saturday, 17 January 2015

C Program to print triangle filled with numbers


This is a simple C Program which prints out a triangle with respect to the input given , here the obtained triangle is filled with numbers.

Triangle with numbers pattern

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j, n,k;
    printf("Enter number of lines[height of triangle] : \t");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
        {
            printf(" ");
        }
        for(k=1; k<(i*2); k++)
        {
            printf("%d",k);
        }
        printf("\n");
    }
    return 0;
}

OUTPUT : 
C Program to print a triangle with numbers

C Program to print a triangle filled with stars


This is a simple C Program which prints out a triangle with respect to the input given , the obtained triangle is  filled with stars.

Triangle pattern

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j, n,k;
    printf("Enter number of lines[height of triangle] : \t");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
        {
            printf(" ");
        }
        for(k=1; k<i*2; k++)
        {
            printf("*");
        }
        printf("\n");
    }
    return 0;
}

OUTPUT : 
C Program to print a triangle

C Program to print a Right Angled Triangle


This is a simple C Program which prints out a Right angled triangle with respect to he input given.

Right angled triangle

PROGRAM :

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j, n,k;
    printf("Enter number of lines[height of triangle] : \t");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
        {
            printf(" ");
        }
        for(k=1; k<(i*2); k++)
        {

            printf("%d",k++);
        }
        printf("\n");
    }
    return 0;
}

OUTPUT : 
C Program to print  Right angled triangle

NOTE : The output should be less than 5 to see the best result as when the output exceeds 5 the numbers from 10,11 .. are 2 digits so then the output would become somewhat messy.

C Program to print Pascals Traingle


This is a C Program which prints pascals triangle based on the input given.


C Program to print Pascals Triangle



PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i,j,x,n,s;
    printf("Enter number of lines[height of triangle] : \t");
    scanf("%d",&n);
    for(i=0; i<=n; i++)
    {
        x=1;
        for(s=1; s<=n-i; s++)
            printf(" ");
        for(j=1; j<=i+1; j++)
        {
            printf("%d ",x);
            x=x*(i-j+1)/j;
        }
        printf("\n");
    }
    return 0;
}


OUTPUT : 
C Program to print Pascals Triangle


C Program to print floyds triangle


This is a C program which prints the Floyd's triangle with respect to the input given.

Floyd's triangle

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j, k = 1,n;
    printf("Enter the range: ");
    scanf("%d", &n);
    printf("\nFLOYD'S TRIANGLE : \n");
    for (i = 1; i <= n; i++)
    {
        for (j = 1; j <= i; j++, k++)
        {
            printf("%d\t", k);
        }
        printf("\n");
    }
    return 0;
}

OUTPUT :  
C Program to print Floyd's Triangle

C Program to print a diamond with stars pattern


This is a  C Program which prints out the diamond with stars pattern.

Diamond with stars (pattern)

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int i, j, k,n;
    printf("Enter number of lines[height of diamond] : \t");
    scanf("%d",&n);
    for(i=1; i<=n; i++)
    {
        for(j=i; j<n; j++)
        {
            printf(" ");
        }
        for(k=1; k<(i*2); k++)
        {
            printf("*");
        }
        printf("\n");
    }
    for(i=n-1; i>=1; i--)
    {
        for(j=n; j>i; j--)
        {
            printf(" ");
        }
        for(k=1; k<(i*2); k++)
        {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}

OUTPUT : 
C Program to print diamond.

File Structures - C Program to copy characters from one file to another file.


This is a C Program which copies the contents from one file to another file.

Here we use file pointer to read and write data. To read data we open a file in read mode and similarly to write data we open a file in write mode . Read and write modes are shown by 'r' and 'w' , these should be passed as an second argument for fopen function.

PROGRAM :
#include <stdio.h>
#include <stdlib.h>

int main()
{
    FILE *fp1,*fp2;

    fp1 = fopen("input.txt" ,"r");
    fp2 = fopen("output.txt","w");

    while(1)
    {
        char ch;
        ch = fgetc(fp1);
        if (ch == EOF)
            break;
        else
            putc(ch, fp2);
    }
    fclose(fp1);
    fclose(fp2);

    return 0;
}


OUTPUT :

First create a file named input.txt in the root directory of the project,

Create a new file input.txt

Now open that file and write some data in it,

Write some data in input.txt file

Now run the c file which we created above, then it will create a new file output.txt
The file output.txt is automatically created after executing our program

Now open that output.txt file , we will see the data from input.txt copied to output.txt file.

Contents copied from input.txt to output.txt