program To Copy Content of A File To Another
program To Copy Content of A File To Another
#include <stdio.h>
main()
FILE *fs,*fd;
char ch,src[13],des[13];
scanf("%s",src);
fs=fopen(src,"r");
if(fs==NULL)
getch();
exit(0);
scanf("%s",des);
fd=fopen(des,"w");
if(fd==NULL)
getch();
exit(0);
while(1)
ch=fgetc(fs);
if(ch==EOF)
break;
fputc(ch,fd);
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]);
}
}
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;
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;
return 0;
getch();