Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions File handling/dat file.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
struct bank
{
int bookid;
char name[25];
float rate;
};
main()
{
struct bank b1;
FILE *fp;
fp=fopen("f5.dat","wb");
printf("Enter bookid name and rate:\n");
scanf("%d",&b1.bookid);
fflush(stdin);
gets(b1.name);
scanf("%f",&b1.rate);
fwrite(&b1,sizeof(b1),1,fp);
fclose(fp);
}
Binary file added File handling/dat file.exe
Binary file not shown.
Binary file added File handling/dat file.o
Binary file not shown.
18 changes: 18 additions & 0 deletions File handling/f1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include<stdio.h>
main()
{
int i;
FILE *fp;
char str[]="Amee Computer class Batch 1 sneh";
fp=fopen("f1.txt","w");
if(fp==NULL)
{
printf("File cannot be opened.\n");
exit(1);
}
for(i=0;i<strlen(str);i++)
{
fputc(str[i],fp);
}
fclose(fp);
}
Binary file added File handling/f1.exe
Binary file not shown.
Binary file added File handling/f1.o
Binary file not shown.
1 change: 1 addition & 0 deletions File handling/f1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Amee Computer class Batch 1 sneh
Binary file added File handling/f5.dat
Binary file not shown.
16 changes: 16 additions & 0 deletions File handling/fputs.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<stdio.h>
main()
{
char ch[20];
FILE *fp;
fp=fopen("juju1.txt","w");
if(fp==NULL)
{
printf("File not found.\n");
exit(1);
}
printf("Enter string:\n");
gets(ch);
fputs(ch,fp);
fclose(fp);
}
Binary file added File handling/fputs.exe
Binary file not shown.
Binary file added File handling/fputs.o
Binary file not shown.
1 change: 1 addition & 0 deletions File handling/juju.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sneh chauhan
1 change: 1 addition & 0 deletions File handling/juju1.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
snehchauhan
18 changes: 18 additions & 0 deletions File handling/reading from a file using fgets.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*To read from a file using fgets() */
#include<stdio.h>
main()
{
char ch[20];
FILE *fp;
fp=fopen("juju.txt","r");
if(fp==NULL)
{
printf("File not found.\n");
exit(1);
}
while(fgets(ch,8,fp)!=NULL)
{
printf("%s",ch);
}
fclose(fp);
}
Binary file not shown.
Binary file added File handling/reading from a file using fgets.o
Binary file not shown.
19 changes: 19 additions & 0 deletions File handling/sns.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
main()
{
char ch;
FILE *fp;
fp=fopen("juju.txt","r");
if(fp==NULL)
{
printf("File not found.\n");
exit(0);
}
ch=fgetc(fp);
while(!feof(fp))
{
printf("%c",ch);
ch=fgetc(fp); //Recursion
}
fclose(fp);
}
Binary file added File handling/sns.exe
Binary file not shown.
Binary file added File handling/sns.o
Binary file not shown.
17 changes: 17 additions & 0 deletions Functions/areaofcircle.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
#define PI 3.14
float areac(float);
int main()
{
float r;
printf("Enter the radius of Circle:\n");
scanf("%f",&r);
printf("The Area of the circle with radius %f is: %f",r,areac(r));
return 0;
}
float areac(float r)
{
float z;
z=PI*r*r;
return z;
}
Binary file added Functions/areaofcircle.exe
Binary file not shown.
Binary file added Functions/areaofcircle.o
Binary file not shown.
23 changes: 23 additions & 0 deletions Functions/dectobin.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include<stdio.h>
int dec(int);
main()
{
int x,i;
printf("Enter the value of x:\n");
scanf("%d",&x);
dec(x);
}
int dec(x)
{
int i,bin[15];
for(i=0;i<15;i++)
{
bin[i]=x%2;
x=x/2;
}
printf("The Binary value is:\n");
for(i=14;i>=0;i--)
{
printf("%d",bin[i]);
}
}
Binary file added Functions/dectobin.exe
Binary file not shown.
Binary file added Functions/dectobin.o
Binary file not shown.
20 changes: 20 additions & 0 deletions Functions/factorial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#include<stdio.h>
int fact(int x);
int main()
{
int x;
printf("Enter the value of x:\n");
scanf("%d",&x);
//z=fact(x);
printf("The factorial of x is :%d",fact(x));
return 0;
}
int fact(int x)
{
int i,fact=1;
for(i=x;i>=1;i--)
{
fact*=i;
}
return fact;
}
Binary file added Functions/factorial.exe
Binary file not shown.
Binary file added Functions/factorial.o
Binary file not shown.
21 changes: 21 additions & 0 deletions Functions/factors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include<stdio.h>
void factors(int);
main()
{
int x;
printf("Enter the value of x:\n");
scanf("%d",&x);
factors(x);
}
void factors(int x)
{
int i;
for(i=1;i<=x;i++)
{
if(x%i==0)
{
printf("%d",i);
}

}
}
Binary file added Functions/factors.exe
Binary file not shown.
Binary file added Functions/factors.o
Binary file not shown.
28 changes: 28 additions & 0 deletions Functions/functions.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#include<stdio.h>
void italy();
void germany();
void india();

main()
{
printf("I am in main.\n");
italy();
printf("I am back in main.\n");
}
void italy()
{
printf("I am in ITALY.\n");
germany();
printf("I am back in ITALY.\n");
}
void germany()
{
printf("I am in GERMANY.\n");
india();
printf("I am back in GERMANY.\n");
}
void india()
{
printf("I am in INDIA.\n");
}

Binary file added Functions/functions.exe
Binary file not shown.
Binary file added Functions/functions.o
Binary file not shown.
17 changes: 17 additions & 0 deletions Functions/functions1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
main()
{
int sum(int x,int y);
int x,y,s;
printf("Enter x:\n");
scanf("%d",&x);
printf("Enter y:\n");
scanf("%d",&y);
s=sum(x,y);
printf("The sum is %d.\n",s);
}
sum(a,b)
{
int z;
z=a+b;
}
Binary file added Functions/functions1.exe
Binary file not shown.
Binary file added Functions/functions1.o
Binary file not shown.
29 changes: 29 additions & 0 deletions Functions/lcm.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include<stdio.h>
int lcm(int,int);
main()
{
int x,y;
printf("Enter the value of x:\n");
scanf("%d",&x);
printf("Enter the value of y:\n");
scanf("%d",&y);
if(x<y)
{
x=x+y;
y=x-y;
x=x-y;

}
printf("The lcm of x and y is %d.\n",lcm(x,y));
}
int lcm(int x,int y)
{
int i;
for(i=x;;i++)
{
if(i%x==0&&i%y==0)
{
return i;
}
}
}
Binary file added Functions/lcm.exe
Binary file not shown.
Binary file added Functions/lcm.o
Binary file not shown.
19 changes: 19 additions & 0 deletions Functions/multiply2values.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/*Use of functions*/
#include<stdio.h>
int sum(int,int);
main()
{
int x,y,a;
printf("Enter the value of x:\n");
scanf("%d",&x);
printf("Enter the value of y:\n");
scanf("%d",&y);
a=sum(x,y);
printf("The sum of x and y is %d.\n",a);
}
int sum(int x,int y)
{
int z;
z=x*y;
return z;
}
Binary file added Functions/multiply2values.exe
Binary file not shown.
Binary file added Functions/multiply2values.o
Binary file not shown.
17 changes: 17 additions & 0 deletions Functions/oddoreven.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#include<stdio.h>
int check(int);
int main()
{
int x;
printf("Enter the number:\n");
scanf("%d",&x);
return check(x);
}
int check(int x)
{
int i;
if(x%2==0)
return 1;
else
return 0;
}
Binary file added Functions/oddoreven.exe
Binary file not shown.
Binary file added Functions/oddoreven.o
Binary file not shown.
24 changes: 24 additions & 0 deletions Functions/primeornot.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include<stdio.h>
int prime(int);
main()
{
int x,z;
printf("Enter the value of x:\n");
scanf("%d",&x);
z=prime(x);
if(z==1)
printf("The number is not a prime number.\n");
else
printf("The number is a prime number.\n");
}
int prime(int x)
{
int num;
for(int i=2;i<=x-1;i++)
{
if(x%i==0)
return 1;
else
return 0;
}
}
Binary file added Functions/primeornot.exe
Binary file not shown.
Binary file added Functions/primeornot.o
Binary file not shown.
16 changes: 16 additions & 0 deletions Functions/printnaturalnos.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#include<stdio.h>
int numbers(int);
int main()
{
int x;
printf("Enter the number upto which you want to print the numbers from 1:\n");
scanf("%d",&x);
numbers(x);
return 0;
}
int numbers(int x)
{
int i;
for(i=1;i<=x;i++)
printf("%d\t",i);
}
Binary file added Functions/printnaturalnos.exe
Binary file not shown.
Binary file added Functions/printnaturalnos.o
Binary file not shown.
20 changes: 20 additions & 0 deletions Functions/sumof2numbers.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*Use of functions*/
#include<stdio.h>
main()
{
float sum(float,float);
float x,y,a;
printf("Enter the value of x:\n");
scanf("%f",&x);
printf("Enter the value of y:\n");
scanf("%f",&y);
a=x+y;
a=sum(x,y);
printf("The sum of x and y is %f.\n",a);
}
float sum(float x,float y)
{
float z;
z=x+y;
return z;
}
Binary file added Functions/sumof2numbers.exe
Binary file not shown.
19 changes: 19 additions & 0 deletions Recursion/factorial.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include<stdio.h>
int sum(int);
main()
{
int x,z;
printf("Enter the value of x:\n");
scanf("%d",&x);
z=sum(x);
printf("The sum of %d numbers is %d.\n",x,z);
}
int sum(int a)
{
int s;
if(a==1)
return(a);
s=a*sum(a-1);
return(s);
}

Binary file added Recursion/factorial.exe
Binary file not shown.
Binary file added Recursion/factorial.o
Binary file not shown.
Loading