0% found this document useful (0 votes)
33 views8 pages

program To Copy Content of A File To Another

This C program contains code for multiple functions: 1) A file copy program that takes in source and destination file names from the user and copies the contents of the source file to the destination file. 2) A matrix multiplication program that takes in two 3x3 matrices from the user, multiplies them together, and displays the result. 3) A program that uses a structure to store student data like name, ID, and age and displays the stored values. 4) A program that takes in an array of numbers from the user, sorts it in ascending and descending order, and displays the results. 5) A program that takes in two numbers, calculates their greatest common divisor (GCD)

Uploaded by

Sujay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views8 pages

program To Copy Content of A File To Another

This C program contains code for multiple functions: 1) A file copy program that takes in source and destination file names from the user and copies the contents of the source file to the destination file. 2) A matrix multiplication program that takes in two 3x3 matrices from the user, multiplies them together, and displays the result. 3) A program that uses a structure to store student data like name, ID, and age and displays the stored values. 4) A program that takes in an array of numbers from the user, sorts it in ascending and descending order, and displays the results. 5) A program that takes in two numbers, calculates their greatest common divisor (GCD)

Uploaded by

Sujay
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

//Program to copy content of a file to another

#include <stdio.h>

main()

FILE *fs,*fd;

char ch,src[13],des[13];

printf("***File copy program***");

printf("\nEnter the source file name:");

scanf("%s",src);

fs=fopen(src,"r");

if(fs==NULL)

printf("\nFIle doesn't exist or cannot open");

getch();

exit(0);

printf("\nEnter the destination file name:");

scanf("%s",des);

fd=fopen(des,"w");

if(fd==NULL)

printf("\nFile doesn't exist or cannot open");


fclose(fs);

getch();

exit(0);

while(1)

ch=fgetc(fs);

if(ch==EOF)

break;

fputc(ch,fd);

printf("\nFile copied successfully");

printf("\nFRom %s to %s ",src,des);

fclose(fs);

fclose(fd);

getch();

}
//Program for NxM matrix
#include<stdio.h>
#define SIZE 3
int main()
{
int A[SIZE][SIZE];
int B[SIZE][SIZE];
int C[SIZE][SIZE];
int row,col,i,sum;
printf("\tEnter the elements in matrix A of size %dx%d;\n",SIZE,SIZE);
for(row=0;row<SIZE;row++)
{
for(col=0;col<SIZE;col++)
{
scanf("%d",&A[row][col]);
}
}

printf("\t\n Enter elements in matrix B of size %dx%d;\n",SIZE,SIZE);


for(row=0;row<SIZE;row++)
{
for(col=0;col<SIZE;col++)
{
scanf("%d",&B[row][col]);
}
}

for(row=0;row<SIZE;row++)
{
for(col=0; col<SIZE;col++)
{
sum=0;
for(i=0;i<SIZE;i++)
{
sum+=A[row][i]*B[i][col];
}
C[row][col]=sum;
}
}
printf("\nProduct of Matrix A*B=\n");
for(row=0;row<SIZE;row++)
{
for(col=0;col<SIZE;col++)
{
printf("\t%d",C[row][col]);
}
printf("\t\n");
}
return 0;
}
//program to using structures-studentinfo
#include <stdio.h>
struct StudentData
{
char *stu_name[10];
int stu_id;
int stu_age;
};
int main()
{ /*student is the variable of structure*/
struct StudentData student;
/*Assigning the values of each struct members*/
printf("Enter the Student's name\n");
scanf("%s",&student.stu_name);
printf("Enter the Student's Id\n");
scanf("%d",&student.stu_id);
printf("Enter the Student's Age\n");
scanf("%d",&student.stu_age);
/*Displaying the values of each struct members*/
printf("Student Name is : %s\n",student.stu_name);
printf("\nStudent Id is : %d\n",student.stu_id);
printf("\nStudent age is : %d\n",student.stu_age);
return 0;
}
//program for ascending and descending
#include<stdio.h>
main()
{
int n,data[100],i,j,temp;
printf("Enter the number of elements:");
scanf("%d",&n);
for(i=0;i<n;i++)
{
printf("\nEnter the element %d:",i+1);
scanf("%d",&data[i]);
}
for(i=0;i<n-1;i++)
{
for(j=i+1;j<n;j++)
{
if(data[i]>data[j])
{
temp=data[i];
data[i]=data[j];
data[j]=temp;
}
}
}
printf("\n Ascending order:");
for(i=0;i<n;i++)
printf("\t%d",data[i]);
printf("\n Descending order;");
for(i=n-1;i>=0;i--)
printf("\t %d",data[i]);
return 0;
}
//program for lcm and gcd
#include <stdio.h>

int main()

int num1,num2,gcd,lcm,remainder,numerator,denominator;

printf("Enter the numbers:\n");

scanf("%d%d",&num1,&num2);

if(num1>num2)

numerator=num1;

denominator=num2;

else

numerator=num2;

denominator=num1;

remainder=numerator%denominator;

while(remainder!=0)

numerator=denominator;
denominator=remainder;

remainder=numerator%denominator;

gcd=denominator;

lcm=num1*num2/gcd;

printf("GCD of %d and %d =%d\n",num1,num2,gcd);

printf("LCM of %d and %d =%d\n",num1,num2,lcm);

return 0;

getch();

You might also like