//Documentation Section
/*This program will accept the radius of circle
and calculates the area of circle.*/
//Linking Section
#include<conio.h>
#include<stdio.h>
//Definition Section
#define pi 3.14
//Global Declaration Section
float r;
//main() function Section
void main()
{
//Local Declaration Part
float a;
//Executable Part
clrscr();
printf("\nEnter the radius of circle ");
scanf("%f",&r);
a=pi*r*r;
printf("\nArea of circle = %f",a);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
printf("Welcome to BIIT");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float y;
char z;
x=5;
y=55.4;
z='a';
printf("\nx = %d",x);
printf("\ny = %f",y);
printf("\nz = %c",z);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float y;
char z;
printf("Enter the value of x ");
scanf("%d",&x);
printf("Enter the value of y ");
scanf("%f",&y);
printf("Enter the value of z ");
scanf(" %c",&z);
printf("\nx = %d",x);
printf("\ny = %0.2f",y);
printf("\nz = %c",z);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float y;
char z;
printf("Enter the values of x, y & z ");
scanf("%d%f %c",&x,&y,&z);
printf("\nx = %d\ny = %f\nz = %c",x,y,z);
getch();
}
#include<stdio.h>
#include<conio.h>
//Usage of getchar() & putchar() functions
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf("Enter any character ");
ch=getchar();
printf("\nCharacter entered by you is ");
putchar(str);
}
//Usage of getche() & putchar() functions
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf("Enter any character ");
ch=getche();
printf("\nCharacter entered by you is ");
putchar(str);
}
//Usage of getch() & putch() functions
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf("Enter any character ");
ch=getch();
printf("\nCharacter entered by you is ");
putch(str);
}
//Usage of gets() & puts() functions
#include<stdio.h>
#include<conio.h>
void main()
{
char str[50];
printf("Enter Your name ");
gets(str);
printf("\nYour name is ");
puts(str);
}
if(Condition)
{
Statement 1;
Statement 2;
Statement 3;
Statement 4;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter the number ");
scanf("%d",&n);
if(n%2==0)
{
printf("\nEven");
}
if(n%2!=0)
{
printf("\nOdd");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int per;
printf("Enter your percentage ");
scanf("%d", per);
if(per>=60)
{
printf("\nFirst Division");
}
if(per>=50 && p<60)
{
printf("\nSecond Division");
}
if(per>=40 && p<50)
{
printf("\nThird Division");
}
if(per< 40)
{
printf("\nFail");
}
getch();
}
if(Condition)
{
Statement 1;
Statement 2;
Statement 3;
}
else
{
Statement 1;
Statement 2;
Statement 3;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
printf("Enter the number ");
scanf("%d",&n);
if(n%2==0)
{
printf("\nEven");
}
else
{
printf("\nOdd");
}
getch();
}
if(Condition 1)
{
Statement 1;
Statement 2;
Statement 3;
}
else if(Condition 2)
{
Statement 1;
Statement 2;
Statement 3;
}
else if(Condition 3)
{
Statement 1;
Statement 2;
Statement 3;
}
else
{
Statement 1;
Statement 2;
Statement 3;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y;
printf("Enter two numbers ");
scanf("%d%d",&x,&y);
if(x>y)
{
printf("\nx is greater");
}
else if(x<y)
{
printf("\ny is greater");
}
else
{
printf("\nBoth are equal");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int per;
printf("Enter your percentage ");
scanf("%d",&per);
if(per>=60)
{
printf("\nFirst Division");
}
else if(per>=50)
{
printf("\nSecond Division");
}
else if(per>=40)
{
printf("\nThird Division");
}
else
{
printf("\nFail");
}
getch();
}
if(Condition1)
{
Statement;
if(Condition2)
{
Statement;
}
else
{
Statement;
}
}
else
{
if(Condition3)
{
Statement;
}
}
//Write A Program to input three unequal numbers and show which one is greatest
#include<stdio.h>
#include<conio.h>
void main()
{
int x,y,z;
printf("Enter three unequal numbers ");
scanf("%d%d%d",&x,&y,&z);
if(x>y)
{
if(x>z)
printf("\nx is greatest");
else
printf("\nz is greatest");
}
else
{
if(y>z)
printf("\ny is greatest");
else
printf("\nz is greatest");
}
getch();
}
switch(ch)
{
case val1:
Statement;
case val2:
Statement;
case val3:
Statement;
case val4:
Statement;
default:
Statement;
}
//Write A Menu Driven Program for a Restaurant as fallows:
/* Menu
1. Dosa
2. Paw Bhaji
3. Burgur
Enter your choice */
#include<stdio.h>
#include<conio.h>
void main()
{
int ch;
printf("\nMenu\n1.Dosa\n2.Paw Bhaji\n3.Burgur");
printf("\nEnter your choice ");
scanf("%c",&ch);
switch(ch)
{
case 1:
printf("\nDosa");
break;
case 2:
printf("\nPav Bhaji");
break;
case 3:
printf("\nBurgur");
break;
default:
printf("\nWrong Choice");
}
getch();
}
//Write A Menu Driven Program for a Restaurant as fallows:
/* Menu
a. Dosa
b. Paw Bhaji
c. Burgur
Enter your choice */
#include<stdio.h>
#include<conio.h>
void main()
{
char ch;
printf("\nMenu\na.Dosa\nb.Paw Bhaji\nc.Burgur");
printf("\nEnter your choice ");
scanf(" %c",&ch);
switch(ch)
{
case 'a':
case 'A':
printf("\nDosa");
break;
case 'b':
case 'B':
printf("\nPav Bhaji");
break;
case 'c':
case 'C':
printf("\nBurgur");
break;
default:
printf("\nWrong Choice");
}
getch();
}
for(initialization;condition;inc/dec)
{
statement 1;
statement 2;
statement 3;
statement 4;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
for(i=1;i<=10;i++)
{
printf("\n%d",i);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
printf("\nEnter the number ");
scanf("%d",&n);
for(i=1;i<=10;i++)
{
printf("\n%d X %d = %d",n,i,i*n);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum;
for(i=1;i<=10;i++)
{
sum=sum+i;
printf("\nsum = %d",sum);
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
long i,f=1,n;
printf("Enter the number ");
scanf("%ld",&n);
for(i=1;i<=n;i++)
{
f=f*i;
}
printf("\nfactorial = %ld",f);
getch();
}
while(condition)
{
statement 1;
statement 2;
statement 3;
statement 4;
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0,r,n;
printf("\nEnter the number ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+r;
}
printf("\nSum of digits = %d",sum);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,rev=0,r,n;
printf("\nEnter the number ");
scanf("%d",&n);
while(n>0)
{
r=n%10;
n=n/10;
rev=rev*10+r;
}
printf("\nReverse No = %d",rev);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,rev=0,r,n,org;
printf("\nEnter the number ");
scanf("%d",&n);
org=n;
while(n>0)
{
r=n%10;
n=n/10;
rev=rev*10+r;
}
if(org==rev)
{
printf("\nPalindrome No");
}
else
{
printf("\nNon Palindrome No");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,sum=0,r,n,org;
printf("\nEnter the number ");
scanf("%d",&n);
org=n;
while(n>0)
{
r=n%10;
n=n/10;
sum=sum+r*r*r;
}
if(org==sum)
{
printf("\nArmstrong No");
}
else
{
printf("\nNot an Armsrong No");
}
getch();
}
do
{
statement 1;
statement 2;
statement 3;
statement 4;
}while(condition);
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
char ch;
do
{
printf("Enter the number ");
scanf("%d",&n);
if(n%2==0)
{
printf("\nEven");
}
else
{
printf("\nOdd");
}
printf("\nDo you want more ");
scanf(" %c",&ch);
}while(ch=='y');
getch();
}
for(initialization;condition;inc/dec)
{
statement 1;
for(initialization;condition;inc/dec)
{
statement 2;
statement 3;
statement 4;
}
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,k;
for(i=1;i<=3;i++)
{
for(j=1;j<=3;j++)
{
for(k=1;k<=3;k++)
{
if(i!=j && j!=k && i!=k)
printf("\n\t%d%d%d",i,j,k);
}
}
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
printf("%d\t",i*j);
}
printf("\n");
}
getch();
}
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++) //row
{
for(j=1;j<=i;j++) //col
{
printf(" *");
}
printf("\n");
}
getch();
}
* * * * *
* * * *
* * *
* *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=5;i>=1;i--) //row
{
for(j=1;j<=i;j++) //col
{
printf(" *");
}
printf("\n");
}
getch();
}
* * * * *
* * * *
* * *
* *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++) //row
{
for(j=1;j<i;j++) //col
{
printf(" ");
}
for(j=1;j<=6-i;j++) //col
{
printf(" *");
}
printf("\n");
}
getch();
}
*
* *
* * *
* * * *
* * * * *
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++) //row
{
for(j=1;j<6-i;j++) //col
{
printf(" ");
}
for(j=1;j<=i;j++) //col
{
printf(" *");
}
printf("\n");
}
getch();
}
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++) //row
{
for(j=1;j<6-i;j++) //col
{
printf(" ");
}
for(j=1;j<=i;j++) //col
{
printf(" *");
}
printf("\n");
}
for(i=1;i<=4;i++) //row
{
for(j=1;j<=i;j++) //col
{
printf(" ");
}
for(j=1;j<=5-i;j++) //col
{
printf(" *");
}
printf("\n");
}
getch();
}
A
A B
A B C
A B C D
A B C D E
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++) //row
{
for(j=1;j<=i;j++) //col
{
printf(" %c",64+j);
}
printf("\n");
}
getch();
}
A
B B
C C C
D D D D
E E E E E
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j;
for(i=1;i<=5;i++) //row
{
for(j=1;j<=i;j++) //col
{
printf(" %c",64+i);
}
printf("\n");
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("\nBefore Loop (B1)");
for(i=1;i<=10;i++)
{
printf("\nEnter any number(B2) ");
scanf("%d",&n);
if(n%5==0)
{
printf("\nOh! No. is divisible by 5(B3)");
break;
}
printf("\nDouble of your number is %d(B4)",n*2);
}
printf("\nAfter Loop(B5)");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n,i;
printf("\nBefore Loop (B1)");
for(i=1;i<=10;i++)
{
printf("\nEnter any number(B2) ");
scanf("%d",&n);
if(n%5==0)
{
printf("\nOh! No. is divisible by 5(B3)");
continue;
}
printf("\nDouble of your number is %d(B4)",n*2);
}
printf("\nAfter Loop(B5)");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf("\nEnter any number ");
scanf("%d",&n);
if(n%2==0)
{
goto ev; //conditional goto
}
else
{
goto od; //conditional goto
}
ev:
printf("\nEven");
goto ed; //unconditional goto
od:
printf("\nOdd");
ed:
printf("\nThank you");
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int ch;
float a,b,c;
clrscr();
printf("\nMenu\n1.Add\n2.Sub\n3.Div\n4.Mul");
printf("\nEnter your choice ");
scanf("%d",&ch);
if(ch>=1&&ch<=4)
{
printf("\nEnter the two numbers ");
scanf("%f%f",&a,&b);
}
switch(ch)
{
case 1:
c=a+b;
break;
case 2:
c=a-b;
break;
case 3:
c=a/b;
break;
case 4:
c=a*b;
break;
default:
printf("Wrong choice");
getch();
exit(0);
}
printf("\nResult is %f",c);
getch();
}
return_type function_name (arguments)
{
Statement 1;
Statement 2;
Statement 3;
}
void show()
{
printf("\nWelcome");
}
int add(int a, int b)
{
int c;
c=a+b;
return c;
}
#include<stdio.h>
void main()
{
void show(); //Prototype (Declaration)
show(); //calling(Invoking)
} //Body(Definition)
void show()
{
printf("\nWelcome");
}
#include<stdio.h>
void main()
{
void add(); //Prototype
add(); //Calling
}
void add() //Body
{
int x,y,z;
x=55;
y=44;
z=x+y;
printf("\nSum is %d",z);
}
#include<stdio.h>
void main()
{
void add(int,int); //Prototype
int a,b;
a=22;
b=33;
add(a,b); //Calling
}
void add(int x,int y) //Body
{
int z;
z=x+y;
printf("\nSum is %d",z);
}
#include<stdio.h>
void main()
{
int add(); //Prototype
int r;
r=add(); //Calling
printf("Sum is %d",r);
}
int add() //Body
{
int x,y,z;
x=55;
y=33;
z=x+y;
return z;
}
#include<stdio.h>
void main()
{
int add(int,int); //Prototype
int p,q,r;
p=33;
q=11;
r=add(p,q); //Calling
printf("Sum is %d",r);
}
int add(int x,int y) //Body
{
int z;
z=x+y;
return z;
}
#include<stdio.h>
void main()
{
void show();
show();
}
void show() //Recursive Function
{
printf("Welcome to BIIT");
show();
}
#include<stdio.h>
void main()
{
int fact(int);
int i,f,n;
printf("\nEnter the number ");
scanf("%d",&n);
f=fact(n);
printf("\nFactorial of %d = %d",n,f);
}
int fact(int num)
{
int fa;
if(num==1||num==0)
{
return 1;
}
else
{
fa=num*fact(num-1);
return fa;
}
}
#include<stdio.h>
void main()
{
void show(int));
int x;
x=5;
show(x);
}
void show(int p)
{
printf("\nx = %d",p);
}
#include<stdio.h>
void main()
{
void swap(int x,int y);
int x,y;
x=5;
y=4;
printf("\nBefore swap");
printf("\nx = %d",x);
printf("\ny = %d",y);
swap(x,y);
printf("\nAfter swap");
printf("\nx = %d",x);
printf("\ny = %d",y);
}
void swap(int x,int y)
{
int temp;
temp=x;
x=y;
y=temp;
printf("\nInside swap");
printf("\nx = %d",x);
printf("\ny = %d",y);
}
#include<stdio.h>
void main()
{
void swap(int *x,int *y);
int x,y;
x=5;
y=4;
printf("\nBefore swap");
printf("\nx = %d",x);
printf("\ny = %d",y);
swap(&x,&y);
printf("\nAfter swap");
printf("\nx = %d",x);
printf("\ny = %d",y);
}
void swap(int *x,int *y)
{
int temp;
temp=*x;
*x=*y;
*y=temp;
printf("\nInside swap");
printf("\nx = %d",*x);
printf("\ny = %d",*y);
}
int rn[5];
for(i=0;i<5;i++)
{
printf(“Enter the rn ”);
scanf(“%d”,&rn[i]);
}
int rn[5];
for(i=0;i<5;i++)
{
printf(“\nYour rno is %d”,rn[i]);
}
int m[5][3];
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
printf(“Enter the marks”);
scanf(“%f”,&m[i][j]);
}
}
int m[5][3];
for(i=0;i<5;i++)
{
for(j=0;j<3;j++)
{
printf(“\nYour marks = %f”,m[i][j]);
}
}
#include<stdio.h>
//Initializing the elements of SDA
void main()
{
int rn[]={33,44,55,66,77};
int i;
clrscr();
for(i=0;i<5;i++)
{
printf("\nYour rn is %d",rn[i]);
}
}
#include<stdio.h>
void main()
{
int rn[]={33,44,55,66,77};
int i,n;
clrscr();
printf("\nEnter the student number ");
scanf("%d",&n);
printf("\nYour rn is %d",rn[n-1]);
}
#include<stdio.h>
void main()
{
int rn[5];
int i;
clrscr();
for(i=0;i<5;i++)
{
printf("\nEnter the rn ");
scanf("%d",&rn[i]);
}
for(i=0;i<5;i++)
{
printf("\nYour rn is %d",rn[i]);
}
}
#include<stdio.h>
void main()
{
float m[5],tot,per,i;
clrscr();
for(i=0;i<5;i++)
{
printf("\nEnter your marks ");
scanf("%f",&m[i]);
}
for(i=0;i<5;i++)
{
printf("\nYour marks is %0.2f",m[i]);
tot+=m[i];
}
per=tot/5;
printf("\nYour total of marks %f",tot);
printf("\nYour percentage of marks %f",per);
if(per>=60)
printf("\nFirst Division");
else if(per>=50)
printf("\nSecond Division");
else if(per>=40)
printf("\nThird Division");
else
printf("\nFail");
}
#include<stdio.h>
void main()
{
float m[2][3],i,j;
clrscr();
for(i=0;i<2;i++)
{
printf("\nStudent");
for(j=0;j<3;j++)
{
printf("\nEnter your marks ");
scanf("%f",&m[i][j]);
}
}
for(i=0;i<2;i++)
{
printf("\nStudent");
for(j=0;j<3;j++)
{
printf("\nYour marks is %0.2f",m[i][j]);
}
}
}
#include<stdio.h>
void main()
{
float m[2][3]={{11,22,33},{55,66,77}};
int i,j;
clrscr();
printf("\nEnter the student and subject no ");
scanf("%d%d",&i,&j);
printf("\nYour marks is %0.2f",m[i-1][j-1]);
}
#include<stdio.h>
void main()
{
float m[2][3],tot,per;
int i,j;
clrscr();
for(i=0;i<2;i++)
{
printf("\nStudent");
for(j=0;j<3;j++)
{
printf("\nEnter your marks ");
scanf("%f",&m[i][j]);
}
}
for(i=0;i<2;i++)
{
printf("\nStudent");
tot=0;
for(j=0;j<3;j++)
{
printf("\nYour marks is %0.2f",m[i][j]);
tot+=m[i][j];
}
printf("\nyour total of marks = %f",tot);
per=tot/3;
printf("\nYour percentage of marks %f",per);
if(per>=60)
printf("\nFirst Division");
else if(per>=50)
printf("\nSecond Division");
else if(per>=40)
printf("\nThird Division");
else
printf("\nFail");
}
}
#include<stdio.h>
void main()
{
float m[2][3][4]={{{1,1,1,1},{2,2,2,2},{3,3,3,3}},{{4,4,4,4},{5,5,5,5},{6,6,6,6}}};
int i,j,k;
for(i=0;i<2;i++)//Z
{
printf("\n\nClass %d",i+1);
printf("\n\t\tM1\tM2\tM3\tM4");
for(j=0;j<3;j++)//Y
{
printf("\nStudent %d",j+1);
for(k=0;k<4;k++)//X
{
printf("\t%0.2f",m[i][j][k]);
}
}
}
}
#include<stdio.h>
void main()
{
float m[2][3][4];
int i,j,k;
for(i=0;i<2;i++)//Z
{
printf("\nClass #%d#",i+1);
for(j=0;j<3;j++)//Y
{
printf("\nStudent #%d#",j+1);
for(k=0;k<4;k++)//X
{
printf("\nEnter your marks in subject #%d# = ",k+1);
scanf("%f",&m[i][j][k]);
}
}
}
for(i=0;i<2;i++)//Z
{
printf("\n\nClass %d",i+1);
printf("\n\t\tM1\tM2\tM3\tM4");
for(j=0;j<3;j++)//Y
{
printf("\nStudent %d",j+1);
for(k=0;k<4;k++)//X
{
printf("\t%0.2f",m[i][j][k]);
}
}
}
}
#include<stdio.h>
void main()
{
int m[3][3];
int i,j;
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\nEnter element ");
scanf("%d",&m[i][j]);
}
}
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m[i][j]);
}
printf("\n");
}
}
#include<stdio.h>
void main()
{
int m[3][3];
int i,j;
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\nEnter element ");
scanf("%d",&m[i][j]);
}
}
printf("\nOriginal Matrix\n");
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m[i][j]);
}
printf("\n");
}
printf("\nTranspose Matrix\n");
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m[j][i]);
}
printf("\n");
}
}
#include<stdio.h>
void main()
{
int m1[3][3]={{11,2,3},{4,5,6},{7,8,9}};
int m2[3][3]={{1,2,3},{4,5,6},{7,8,9}};
int m3[3][3];
int i,j;
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
m3[i][j]=m1[i][j]+m2[i][j];
}
printf("\n");
}
printf("\nMatrix 1\n");
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m1[i][j]);
}
printf("\n");
}
printf("\nMatrix 2\n");
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m2[i][j]);
}
printf("\n");
}
printf("\nMatrix 3\n");
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m3[i][j]);
}
printf("\n");
}
}
#include<stdio.h>
void main()
{
int m[3][3];
int i,j,sum=0;
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\nEnter element ");
scanf("%d",&m[i][j]);
}
}
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m[i][j]);
sum+=m[i][j];
}
printf("\n");
}
printf("\nSum is %d",sum);
}
#include<stdio.h>
void main()
{
int m[3][3];
int i,j,sumr,sumc;
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\nEnter element ");
scanf("%d",&m[i][j]);
}
}
for(i=0;i<3;i++)//row
{
sumr=0;
sumc=0;
for(j=0;j<3;j++)//col
{
printf("\t%d",m[i][j]);
sumr+=m[i][j];
sumc+=m[j][i];
}
printf("\tsum of row = %d\tsum of col = %d\n",sumr,sumc);
}
}
#include<stdio.h>
void main()
{
int m[3][3];
int i,j,sumr=0,suml=0;
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\nEnter element ");
scanf("%d",&m[i][j]);
}
}
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
printf("\t%d",m[i][j]);
if(i==j)
suml+=m[i][j];
if(i+j==2)
sumr+=m[i][j];
}
printf("\n");
}
printf("\nsum of elements of Left Diagonal = %d",suml);
printf("\nsum of elements of Right Diagonal = %d",sumr);
}
#include<stdio.h>
void main()
{
int m1[3][3]={{1,2,3},{4,5,6},{7,8,9}},m2[3][3]={{1,2,3},{4,5,6},{7,8,9}},m3[3][3];
int i,j,k;
for(i=0;i<3;i++)//row
{
for(j=0;j<3;j++)//col
{
m3[i][j]=0;
for(k=0;k<3;k++)
{
m3[i][j]+=m1[i][k]*m2[k][j];
}
printf("\t%d",m3[i][j]);
}
printf("\n");
}
}
#include<stdio.h>
void main()
{
int m1[5][5],m2[5][5],m3[5][5];
int i,j,k,r1,r2,c1,c2;
printf("\nEnter the no. of rows & columns for matrix 1 = ");
scanf("%d%d",&r1,&c1);
printf("\nEnter the no. of rows & columns for matrix 2 = ");
scanf("%d%d",&r2,&c2);
if(c1==r2)
{
printf("\nInput For Matrix 1\n");
for(i=0;i<r1;i++)//row
{
for(j=0;j<c1;j++)//col
{
printf("\nEnter the element : ");
scanf("%d",&m1[i][j]);
}
}
printf("\nInput For Matrix 2\n");
for(i=0;i<r2;i++)//row
{
for(j=0;j<c2;j++)//col
{
printf("\nEnter the element : ");
scanf("%d",&m2[i][j]);
}
}
for(i=0;i<r1;i++)//row
{
for(j=0;j<c2;j++)//col
{
m3[i][j]=0;
for(k=0;k<r2;k++)//for(k=0;k<c1;k++)
{
m3[i][j]+=m1[i][k]*m2[k][j];
}
}
}
printf("\nMatrix 1\n");
for(i=0;i<r1;i++)//row
{
for(j=0;j<c1;j++)//col
{
printf("\t%d",m1[i][j]);
}
printf("\n");
}
printf("\nMatrix 2\n");
for(i=0;i<r2;i++)//row
{
for(j=0;j<c2;j++)//col
{
printf("\t%d",m2[i][j]);
}
printf("\n");
}
printf("\nMatrix 3\n");
for(i=0;i<r1;i++)//row
{
for(j=0;j<c2;j++)//col
{
printf("\t%d",m3[i][j]);
}
printf("\n");
}
}
else
{
printf("Multiplication of Matrix is not Possible ");
}
}
#include<stdio.h>
void main()
{
int x,*ptr;
x=55;
ptr=&x
printf("\nValue of x is %d",x);
printf("\nValue of x is %d",*ptr);
printf("\nAddress of x is %u",&x);
printf("\nAddress of x is %d",ptr);
printf("\nAddress of x is %p",ptr);
}
#include<stdio.h>
void main()
{
int x,*ptr1,**ptr4; //ptr1 is Pointer to integer & ptr4 is Pointer to Pointer
float y,*ptr2; //ptr2 is Pointer to float
char z,*ptr3; //ptr3 is Pointer to char
void *ptr; //ptr is Pointer to void
x=55;
y=45.4;
z='p';
ptr1=&x;
ptr2=&y;
ptr3=&z;
printf("\nValue of x is %d",*ptr1);
printf("\nAddress of x is %d",ptr1);
printf("\nValue of y is %f",*ptr2);
printf("\nAddress of y is %d",ptr2);
printf("\nValue of z is %c",*ptr3);
printf("\nAddress of z is %d",ptr3);
ptr=&x;
printf("\nAddress of x is %d",ptr);
ptr=&y;
printf("\nAddress of y is %d",ptr);
ptr=&z;
printf("\nAddress of z is %d",ptr);
ptr4=&ptr1;
printf("\nAddress of ptr1 is %d",ptr4);
printf("\nValue of ptr1 is %d",*ptr4);
printf("\nValue of x is %d",**ptr4);
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int i,*ptr[5];
for(i=0;i<5;i++)
{
ptr[i]=&x[i];
}
for(i=0;i<5;i++)
{
printf("\nx[%d]=%d",i,*ptr[i]);
}
}
#include<stdio.h>
void main()
{
int x=5;
int *ptr,*pt;
ptr=&x;
printf("\nx = %d",*ptr);
printf("\nptr = %d",ptr);
pt=ptr+1;
printf("\npt = %d",pt);
pt=ptr-1;
printf("\npt = %d",pt);
pt=ptr+2;
printf("\npt = %d",pt);
pt=--ptr;
printf("\npt = %d",pt);
printf("\nptr = %d",ptr);
pt=++ptr;
printf("\npt = %d",pt);
pt=ptr--;
printf("\npt = %d",pt);
printf("\nptr = %d",ptr);
pt=ptr++;
printf("\npt = %d",pt);
pt=ptr*2; //Error
printf("\npt = %d",pt);
pt=ptr/2; //Error
printf("\npt = %d",pt);
pt=ptr%2; //Error
printf("\npt = %d",pt);
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr;
ptr=x;
printf("\nx=%d",*ptr);
printf("\nAddress of x=%d",ptr);
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nValue = %d",*ptr+i); //11,12,13,14,15
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nValue = %d",*(ptr+i));//11,22,33,44,55
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nValue = %d",*x+i); //11,12,13,14,15
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nValue = %d",*(x+i)); //11,22,33,44,55
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nValue = %d",*ptr++); //11,22,33,44,55
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nValue = %d",*x++);//error
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nAddress = %d",ptr+i); //All Addresses
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nAddress = %d",x+i); //All Addresses
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nAddress = %d",ptr++); //All Addresses
}
}
#include<stdio.h>
void main()
{
int x[5]={11,22,33,44,55};
int *ptr,i;
ptr=x;
for(i=0;i<5;i++)
{
printf("\nAddress = %d",x++);//Error
}
}
#include<stdio.h>
void main()
{
int x,*ptr;
void show(int*);
x=55;
ptr=&x;
show(ptr);
}
void show(int *p)
{
printf("x is %d",*p);
}
#include<stdio.h>
void main()
{
int *ptr;
int* get();
ptr=get();
printf("x = %d",*ptr);
}
int* get()
{
int x,*p;
x=55;
p=&x;
return p;
}
#include<stdio.h>
void main()
{
int x,*ptr;
int* show(int*);
x=45;
ptr=&x;
printf("\nx = %d",*ptr);//45
ptr=show(ptr);
printf("\nx = %d",*ptr);//70
}
int* show(int *p)
{
int *pt,xx;
printf("\nx is %d",*p);//45
xx=*p+25;
pt=&xx;
return pt;
}
#include<stdio.h>
void main()
{
void showArray(float[],int);
float m[5];
int i,n=5;
for(i=0;i<n;i++)
{
printf("\nEnter your marks = ");
scanf("%f",&m[i]);
}
showArray(m,n);
}
void showArray(float mm[],int size)
{
int i;
for(i=0;i<size;i++)//row
{
printf("\nYour marks = %0.2f",mm[i]);
}
}
#include<stdio.h>
int n;
void main()
{
float *getArray();
float *m;
int i;
m=getArray();
for(i=0;i<n;i++)
{
printf("\nYour marks = %0.2f",*m++);
}
}
float *getArray()
{
int i;
static float marks[5];
n=5;
for(i=0;i<5;i++)//row
{
printf("\nEnter your marks = ");
scanf("%f",&marks[i]);
}
return marks;
}
#include<stdio.h>
int n=5;
void main()
{
float *show(float[],int);
float *ptr,m[5];
int i;
for(i=0;i<n;i++)
{
printf("\nEnter your marks = ");
scanf("%f",&m[i]);
}
ptr=show(m,n);
for(i=0;i<n;i++)
{
printf("\nYour marks = %0.2f",*ptr++);
}
}
float *show(float mm[],int size)
{
int i;
static float marks[5];
for(i=0;i<size;i++)//row
{
marks[i]=mm[i]*2;
}
return marks;
}
'W' | 'e' | 'l' | 'c' | 'o' | 'm' | 'e' | ' ' | 't' | 'o' | ' ' | 'B' | 'I' | 'I' | 'T' | '\0' |
#include<stdio.h>
void main()
{
char str[10]="BIIT";
printf("\nString = %s",str);
}
#include<stdio.h>
void main()
{
char str[10];
printf("Enter the string ");
scanf("%s",str);
printf("\nString = %s",str);
}
#include<stdio.h>
void main()
{
char str[30];
printf("Enter the string ");
gets(str);
printf("\nString = ");
puts(str);
}
#include<stdio.h>
void main()
{
char str[20];
int l;
printf("\nEnter any String ");
gets(str);
l=strlen(str);
printf("\nLength of your String = %d",l);
}
#include<stdio.h>
void main()
{
char str1[20]="",str2[20]="";
printf("\nEnter any String ");
gets(str1);
printf("\nBefore Copy");
printf("\nStr1 = %s",str1);
printf("\nStr2 = %s",str2);
strcpy(str2,str1);
printf("\nAfter Copy");
printf("\nStr1 = %s",str1);
printf("\nStr2 = %s",str2);
}
#include<stdio.h>
void main()
{
char str1[10]="",str2[20]="";
printf("\nEnter any two Strings ");
gets(str1);
gets(str2);
printf("\nBefore Concatenate");
printf("\nStr1 = %s",str1);
printf("\nStr2 = %s",str2);
strcat(str2," ");
strcat(str2,str1);
printf("\nAfter Concatenate");
printf("\nStr1 = %s",str1);
printf("\nStr2 = %s",str2);
}
#include<stdio.h>
void main()
{
char str1[20]="",str2[20]="";
int dif;
printf("\nEnter any two Strings ");
gets(str1);
gets(str2);
dif=strcmp(str1,str2);
printf("\nDifference = %d",dif);
if(dif>0)
printf("\n%s is greater than %s",str1,str2);
else if(dif<0)
printf("\n%s is less than %s",str1,str2);
else
printf("\n%s is equal to %s",str1,str2);
}
#include<stdio.h>
void main()
{
char str1[20];
printf("\nEnter any String ");
gets(str1);
strrev(str1);
printf("\nStr1 = %s",str1);
}
#include<stdio.h>
#include<ctype.h>
#include<conio.h>
void main()
{
char ch;
clrscr();
printf("\nEnter the character ");
ch=getche();
if(isalnum(ch)!=0)
{
printf("\nAlphabet or Digit");
if(isalpha(ch)!=0)
{
printf("\nEnglish Alphabet");
if(isupper(ch)!=0)
{
printf("\nUpper Case Letter");
printf("\nLower equivalent = %c",tolower(ch));
}
else
{
printf("\nLower Case Letter");
printf("\nUpper equivalent = %c",toupper(ch));
}
}
else
{
printf("\nDigit");
}
}
else
{
printf("\nNeither Alphabet nor Digit");
if(isspace(ch)!=0)
{
printf("\nWhite Space");
}
else
{
printf("\nSpecial Character");
}
}
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
char str[10];
printf("\nEnter the string ");
gets(str);
for(i=0;str[i]!='\0';i++);
printf("\nLength of string = %d",i);
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
int length(char*);
int l;
char str[20];
printf("\nEnter the string ");
gets(str);
l=length(str);
printf("\nLength of string = %d",l);
getch();
}
int length(char *st)
{
int i;
for(i=0;st[i]!='\0';i++);
return i;
}
#include<stdio.h>
#include<conio.h>
void main()
{
void copy(char*,char*);
char str1[20]="",str2[20]="";
printf("\nEnter the string ");
gets(str1);
printf("\nBefore Copy");
printf("\nStr1 = %s",str1);
printf("\nStr2 = %s",str2);
copy(str2,str1);
printf("\nAfter Copy");
printf("\nStr1 = %s",str1);
printf("\nStr2 = %s",str2);
getch();
}
void copy(char *st1,char *st2)
{
int i;
for(i=0;st2[i]!='\0';i++)
{
st1[i]=st2[i];
}
st1[i]='\0';
}
#include<stdio.h>
#include<conio.h>
int chkpalin(char*);
int length(char*);
void main()
{
char str[20]="";
int res;
printf("\nEnter the string ");
gets(str);
res=chkpalin(str);
if(res==0)
{
printf("\nPalindrome");
}
else
{
printf("\nNon Palindrome");
}
getch();
}
int chkpalin(char *st)
{
int i,len,flag=0;
len=length(st);
for(i=0;i<=len/2;i++)
{
if(st[i]!=st[len-1-i])
{
flag=1;
break;
}
}
return flag;
}
int length(char *st)
{
int i;
for(i=0;st[i]!='\0';i++);
return i;
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
}s;
//struct student s;
void main()
{
// struct student s;
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s.rn,&s.n,&s.m);
printf("\nYour Roll No. is %d",s.rn);
printf("\nYour Name is %c",s.n);
printf("\nYour Marks is %f",s.m);
}
#include<stdio.h>
#include<conio.h>
void main()
{
struct student
{
int rn;
float m;
char n;
}s1,s2;
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s1.rn,&s1.n,&s1.m);
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s2.rn,&s2.n,&s2.m);
printf("\nYour Roll No. is %d",s1.rn);
printf("\nYour Name is %c",s1.n);
printf("\nYour Marks is %f",s1.m);
printf("\nYour Roll No. is %d",s2.rn);
printf("\nYour Name is %c",s2.n);
printf("\nYour Marks is %f",s2.m);
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
}s[2];
void main()
{
int i;
for(i=0;i<2;i++)
{
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s[i].rn,&s[i].n,&s[i].m);
}
for(i=0;i<2;i++)
{
printf("\nYour Roll No. is %d",s[i].rn);
printf("\nYour Name is %c",s[i].n);
printf("\nYour Marks is %f",s[i].m);
}
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m[5];
char n[10];
}s;
void main()
{
int i;
printf("Enter the Roll No. & Name ");
scanf("%d%s",&s.rn,s.n);
for(i=0;i<5;i++)
{
printf("Enter your Marks ");
scanf("%f",&s.m[i]);
}
printf("\nYour Roll No. is %d",s.rn);
printf("\nYour Name is %s",s.n);
for(i=0;i<5;i++)
{
printf("\nYour Marks is %0.2f",s.m[i]);
}
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m[5];
char n[10];
}s;
void main()
{
int i;
float total=0,per;
printf("Enter the Roll No. & Name ");
scanf("%d%s",&s.rn,&s.n);
for(i=0;i<5;i++)
{
printf("Enter your Marks ");
scanf("%f",&s.m[i]);
}
printf("\nYour Roll No. is %d",s.rn);
printf("\nYour Name is %s",s.n);
for(i=0;i<5;i++)
{
printf("\nYour Marks is %0.2f",s.m[i]);
total+=s.m[i];
}
printf("\nYour total of marks = %0.2f",total);
per=total/5;
printf("\nYour percentage of marks = %0.2f",per);
if(per>=60)
printf("\nFirst Division");
else if(per>=50)
printf("\nSecond Division");
else if(per>=40)
printf("\nThird Division");
else
printf("\nFail");
}
#include<stdio.h>
#include<conio.h>
#define size 20
struct student
{
int rn;
float m[5];
char n[10];
}s[size];
void main()
{
int i,j;
float total,per;
for(i=0;i<size;i++)
{
printf("Enter the Roll No. & Name ");
scanf("%d%s",&s[i].rn,s[i].n);
for(j=0;j<5;j++)
{
printf("Enter your Marks ");
scanf("%f",&s[i].m[j]);
}
}
for(i=0;i<size;i++)
{
total=0;
printf("\nYour Roll No. is %d",s[i].rn);
printf("\nYour Name is %s",s[i].n);
for(j=0;j<5;j++)
{
printf("\nYour Marks is %0.2f",s[i].m[i]);
total+=s[i].m[j];
}
printf("\nYour total of marks = %0.2f",total);
per=total/5;
printf("\nYour percentage of marks = %0.2f",per);
if(per>=60)
printf("\nFirst Division");
else if(per>=50)
printf("\nSecond Division");
else if(per>=40)
printf("\nThird Division");
else
printf("\nFail");
}
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
}s,*ptr;
void main()
{
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s.rn,&s.n,&s.m);
ptr=&s;
printf("\nYour Roll No. is %d",ptr->rn);
printf("\nYour Name is %c",ptr->n);
printf("\nYour Marks is %0.2f",ptr->m);
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
};
typedef struct student stud;
void main()
{
stud s;
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s.rn,&s.n,&s.m);
printf("\nYour Roll No. is %d",s.rn);
printf("\nYour Name is %c",s.n);
printf("\nYour Marks is %f",s.m);
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
}s;
void show(struct student);
void main()
{
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s.rn,&s.n,&s.m);
show(s);
}
void show(struct student st)
{
printf("\nYour Roll No. is %d",st.rn);
printf("\nYour Name is %c",st.n);
printf("\nYour Marks is %0.2f",st.m);
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
};
typedef struct student stud;
void show(stud);
void main()
{
stud s;
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s.rn,&s.n,&s.m);
show(s);
}
void show(stud st)
{
printf("\nYour Roll No. is %d",st.rn);
printf("\nYour Name is %c",st.n);
printf("\nYour Marks is %0.2f",st.m);
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
};
typedef struct student stud;
stud get();
void main()
{
stud st;
st=get();
printf("\nYour Roll No. is %d",st.rn);
printf("\nYour Name is %c",st.n);
printf("\nYour Marks is %0.2f",st.m);
}
stud get()
{
stud s;
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&s.rn,&s.n,&s.m);
return s;
}
#include<stdio.h>
#include<conio.h>
#include<string.h>
struct student
{
int rn;
float m;
char n[10];
};
typedef struct student stud;
stud show(stud);
void main()
{
stud st,rst;
printf("Enter the Roll No., Name and Marks ");
scanf("%d%s%f",&t.rn,&st.n,&st.m);
rst=show(st);
printf("\nYour Roll No. is %d",rst.rn);
printf("\nYour Name is %s",rst.n);
printf("\nYour Marks is %0.2f",rst.m);
getch();
}
stud show(stud s)
{
stud rs;
rs.rn=s.rn+2;
strcpy(rs.n,s.n);
strcat(rs.n," Kumar");
rs.m=s.m+20;
return rs;
}
#include<stdio.h>
#include<conio.h>
union student
{
int rn;
float m;
char n;
}s;
void main()
{
printf("Enter the Roll No., Name and Marks ");
scanf("%f %c%d",&s.m,&s.n,&s.rn);
printf("\nYour Roll No. is %d",s.rn);
printf("\nYour Name is %c",s.n);
printf("\nYour Marks is %0.1f",s.m);
}
#include<stdio.h>
#include<conio.h>
union student_un
{
int rn;
float m;
char n;
};
struct student_str
{
int rn;
float m;
char n;
};
void main()
{
union student_un s1;
struct student_str s2;
printf("\nSize of object s1(ie for union) = %d",sizeof(s1));
printf("\nSize of object s1(ie for union) = %d",sizeof(union student_un));
printf("\nSize of object s2(ie for struct) = %d",sizeof(s2));
printf("\nSize of object s2(ie for struct) = %d",sizeof(struct student_str));
}
#include<stdio.h>
#include<conio.h>
typedef int integer;
void main()
{
integer x;
x=5;
printf("\nx = %d",x);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int x;
float y;
char z;
double w;
printf("\nSize of x is %d",sizeof(x));
printf("\nSize of int is %d",sizeof(int));
printf("\nSize of y is %d",sizeof(y));
printf("\nSize of float is %d",sizeof(float));
printf("\nSize of z is %d",sizeof(z));
printf("\nSize of char is %d",sizeof(char));
printf("\nSize of w is %d",sizeof(w));
printf("\nSize of double is %d",sizeof(double));
getch();
}
#include<stdio.h>
#include<conio.h>
enum week{sunday,monday,tuesday,wednesday,thursday,friday,saturday};
void main()
{
enum week a,b;
int dif;
a=thursday;
b=monday;
dif=a-b;
printf("\nIndex value for thursday = %d",thursday);
printf("\nIndex value for monday = %d",monday);
printf("\nDifference between thursday and monday = %d",dif);
getch();
}
#include<stdio.h>
#include<conio.h>
enum student
{
rakesh=100,mukesh,suresh,harish=200,ramesh,indresh,munesh,jagesh
};
void main()
{
printf("\nIndex for rakesh = %d",rakesh);//100
printf("\nIndex for harish = %d",harish);//200
printf("\nIndex for munesh = %d",munesh);//203
printf("\nIndex for jagesh = %d",jagesh);//204
getch();
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
f=fopen("biit.txt","a");
putc('A',f);
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
char ch;
f=fopen("biit.txt","r");
ch=getc(f);
printf("\nYour Data is %c",ch);
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
char ch,cho;
f=fopen("biit.txt","w");
do
{
printf("\nEnter the character ");
ch=getche();
fputc(ch,f);
printf("\nDo you want more ");
cho=getche();
}while(cho=='y');
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
char ch;
f=fopen("biit.txt","r");
do
{
ch=fgetc(f);
printf("%c",ch);
}while(!feof(f));
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
f=fopen("biit.txt","a");
putc('P',f);
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
f=fopen("biit.txt","w");
putw(7847,f);
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
int i;
f=fopen("biit.txt","r");
i=getw(f);
printf("\nYour Data is %d",i);
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
char cho;
int num;
f=fopen("biit.txt","w");
do
{
printf("\nEnter the number ");
scanf("%d",&num);
putw(num,f);
printf("\nDo you want more ");
cho=getche();
}while(cho=='y');
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
int i;
f=fopen("biit.txt","r");
i=getw(f);
do
{
printf("\nYour Data is %d",i);
i=getw(f);
}while(!feof(f));
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
f=fopen("biit.txt","a");
putw(125,f);
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int rn;
float m;
char n[10];
FILE *f;
f=fopen("biit.txt","w");
printf("\nEnter the rn, name and marks ");
scanf("%d%s%f",&rn,n,&m);
fprintf(f,"%d %f %s",rn,m,n);
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int rn;
float m;
char n[10];
FILE *f;
f=fopen("biit.txt","r");
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int rn;
float m;
char n[10],ch;
FILE *f;
f=fopen("biit.txt","w");
do
{
printf("\nEnter the rn, name and marks ");
scanf("%d%s%f",&rn,n,&m);
fprintf(f,"%d %f %s ",rn,m,n);
printf("\nDo you want more ");
ch=getche();
}while(ch=='y');
printf("\nData is written");
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int rn;
float m;
char n[10];
FILE *f;
f=fopen("biit.txt","r");
fscanf(f,"%d%f%s",&rn,&m,n);
do
{
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
fscanf(f,"%d%f%s",&rn,&m,n);
}while(!feof(f));
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
FILE *f;
int rn;
float m;
char n[10];
f=fopen("biit.txt","r");
printf("\nCurrent position = %ld",ftell(f));
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int rn,stpos,endpos,size,nor=0,sz;
float m;
char n[10];
FILE *f;
f=fopen("biit.txt","r");
stpos=ftell(f);
fscanf(f,"%d%f%s",&rn,&m,n);
do
{
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
nor++;
fscanf(f,"%d%f%s",&rn,&m,n);
}while(!feof(f));
endpos=ftell(f);
size=endpos-stpos;
sz=size/nor;
printf("\nStart = %d",stpos);
printf("\nEnd = %d",endpos);
printf("\nNor = %d",nor);
printf("\nSize = %d",size);
printf("\nSz = %d",sz);
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int rn,num;
long int btn;
float m;
char n[10];
FILE *f;
f=fopen("biit.txt","r");
printf("\nFrom Begining of File");
printf("\nEnter the record number ");
scanf("%d",&num);
printf("\nCurrent position = %ld",ftell(f));
btn=13*(num-1);
fseek(f,btn,0);
printf("\nCurrent position = %ld",ftell(f));
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
printf("\nFrom End of File");
printf("\nEnter the record number ");
scanf("%d",&num);
btn=13*(num);
fseek(f,-btn,2);
printf("\nCurrent position = %ld",ftell(f));
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
printf("\nFrom Current Position of File in Forward Direction ");
printf("\nEnter the record number ");
scanf("%d",&num);
btn=13*(num-1);
fseek(f,btn+1,1);
printf("\nCurrent position = %ld",ftell(f));
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
printf("\nFrom Current Position of File in Backward Direction ");
printf("\nEnter the record number ");
scanf("%d",&num);
btn=13*(num+1);
fseek(f,-btn,1);
printf("\nCurrent position = %ld",ftell(f));
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int rn,num;
long int btn;
float m;
char n[10];
FILE *f;
f=fopen("biit.txt","r");
printf("\nFrom Begining of File");
printf("\nEnter the record number ");
scanf("%d",&num);
printf("\nCurrent position = %ld",ftell(f));
btn=13*(num-1);
fseek(f,btn,0);
printf("\nCurrent position = %ld",ftell(f));
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
rewind(f);
printf("\nAfter rewind Current position = %ld",ftell(f));
fscanf(f,"%d%f%s",&rn,&m,n);
printf("\nYour rn is %d",rn);
printf("\nYour name is %s",n);
printf("\nYour marks is %f",m);
printf("\nCurrent position = %ld",ftell(f));
fclose(f);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int *elm; //pointer to int
elm=(int*)malloc(sizeof(int));
printf("Enter element ");
scanf("%d",elm);
printf("\nElement = %d",*elm);
free(elm);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int *arr,*pt;
int n,i;
printf("Enter number of elements: ");
scanf("%d",&n);
arr=(int*)malloc(n*sizeof(int));
pt=arr;
for(i=0;i<n;i++)
{
printf("Enter element ");
scanf("%d",arr++);
}
arr=pt;
for(i=0;i<n;++i)
{
printf("\nElement = %d",*arr++);
}
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
}*ptr;
typedef struct student std;
void main()
{
ptr=(std*)malloc(sizeof(std));
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&ptr->rn,&ptr->n,&ptr->m);
printf("\nYour Roll No. is %d",ptr->rn);
printf("\nYour Name is %c",ptr->n);
printf("\nYour Marks is %0.2f",ptr->m);
}
#include<stdio.h>
#include<conio.h>
void main()
{
int *arr,*pt;
int n,i;
printf("Enter number of elements: ");
scanf("%d",&n);
arr=(int*)malloc(n*sizeof(int));
printf("\nElement =%d",*arr);
pt=arr;
for(i=0;i<n;i++)
{
printf("Enter element ");
scanf("%d",arr++);
}
arr=pt;
for(i=0;i<n;++i)
{
printf("\nElement = %d",*arr++);
}
}
#include<stdio.h>
#include<conio.h>
struct student
{
int rn;
float m;
char n;
}*ptr,*pt;
typedef struct student std;
void main()
{
int i,num;
printf("\nEnter the no. of objects to store ");
scanf("%d",&num);
ptr=(std*)calloc(num,sizeof(std));
pt=ptr;
for(i=0;i<num;i++)
{
printf("Enter the Roll No., Name and Marks ");
scanf("%d %c%f",&ptr->rn,&ptr->n,&ptr->m);
ptr++;
}
ptr=pt;
for(i=0;i<num;i++)
{
printf("\nYour Roll No. is %d",ptr->rn);
printf("\nYour Name is %c",ptr->n);
printf("\nYour Marks is %0.2f",ptr->m);
ptr++;
}
}
#include<stdio.h>
#include<conio.h>
void main()
{
int *ptr;
int n,i;
printf("Enter number of elements: ");
scanf("%d",&n);
ptr=(int*)malloc(n*sizeof(int));
for(i=0;i<n;i++)
{
printf("Enter element ");
scanf("%d",&ptr[i]);
}
for(i=0;i<n;i++)
{
printf("\nElement = %d",ptr[i]);
}
printf("\nEnter number of elements to Reallocate: ");
scanf("%d",&n);
ptr=realloc(ptr,n*sizeof(int));
for(i=0;i<n;i++)
{
printf("Enter element ");
scanf("%d",&ptr[i]);
}
for(i=0;i<n;i++)
{
printf("\nElement = %d",ptr[i]);
}
}
#include<stdio.h>
#include<conio.h>
void main()
{
int *ptr;
int n,i;
printf("Enter number of elements: ");
scanf("%d",&n);
ptr=(int*)calloc(n,sizeof(int));
for(i=0;i<n;i++)
{
printf("Enter element ");
scanf("%d",&ptr[i]);
}
for(i=0;i<n;i++)
{
printf("\nElement = %d",ptr[i]);
}
printf("\nEnter number of elements to Reallocate: ");
scanf("%d",&n);
ptr=realloc(ptr,n*sizeof(int));
for(i=0;i<n;i++)
{
printf("Enter element ");
scanf("%d",&ptr[i]);
}
for(i=0;i<n;i++)
{
printf("\nElement = %d",ptr[i]);
}
}
#include<stdio.h>
#include<conio.h>
int w;
void main()
{
auto int x;
static int y;
register int z;
extern int w;
x=5;
y=55;
z=555;
w=5555;
printf("\nx(auto) =%d",x);
printf("\ny(static) =%d",y);
printf("\nz(register) =%d",z);
printf("\nw(extern) =%d",w);
}
#include<stdio.h>
#include<conio.h>
void main()
{
void showinc();
showinc();
showinc();
showinc();
}
void showinc()
{
auto int x=0;
static int y=0;
printf("\nCalling Time = #%d#",(y+1));
printf("\nx =%d",x);
printf("\ny =%d",y);
x++;
y++;
printf("\nx =%d",x);
printf("\ny =%d",y);
}
#include<stdio.h>
#include<conio.h>
int a = 11;
int b;
void main()
{
void func();
auto int c=22,d;
extern int b;
register int e;
static int f;
printf("\nThe value of extern variable (a): %d",a);//11
printf("\nThe value of extern variable (b): %d",b);//0
printf("\nThe value of auto variable (c): %d", c);//22
printf("\nThe value of auto variable (d): %d", d);//Garbage
printf("\nThe value of register variable (e): %d",e);//Garbage
printf("\nThe value of static variable (f): %d",f);//0
a = 111;
b = 222;
c = 333;
d = 444;
e = 555;
f = 666;
printf("\nAfter modification");
printf("\nThe value of extern variable (a): %d",a);
printf("\nThe value of extern variable (b): %d",b);
printf("\nThe value of auto variable (c): %d", c);
printf("\nThe value of auto variable (d): %d", d);
printf("\nThe value of register variable (e): %d",e);
printf("\nThe value of static variable (f): %d",f);
func();
}
void func()
{
printf("\nInside function");
a=1111;
b=2222;
c=3333;
d=4444;
e=5555;
f=6666;
printf("\nThe value of extern variable (a): %d",a);
printf("\nThe value of extern variable (b): %d",b);
printf("\nThe value of auto variable (c): %d", c);
printf("\nThe value of auto variable (d): %d", d);
printf("\nThe value of register variable (e): %d",e);
printf("\nThe value of static variable (f): %d",f);
}
#include<stdio.h>
#include<conio.h>
int x; //Global Variable
void main()
{
int y;//Local Variable & Auto Variable
static int z;//Static Variable
y=55;
{
int y;
y=33;
}
}
void func(int p) //p:Formal Function Argument
{
int q;//Local Variable & Auto Variable
static int r;//Static Variable
}
#include<stdio.h>
#include<conio.h>
int x=11; //Global Variable
void main()
{
void func(int);
int y;//Local Variable & Auto Variable
static int z=33;//Static Variable
y=22;
printf("\nx is %d",x);
{
int y;
y=44;
printf("\ny(inside) is %d",y);
}
printf("\ny(outside) is %d",y);
printf("\nz is %d",z);
func(y);
}
void func(int p) //p:Formal Function Argument
{
int q;//Local Variable & Auto Variable
static int r=55;//Static Variable
q=p;
printf("\nInside function");
printf("\np is %d",p);
printf("\nq is %d",q);
printf("\nr is %d",r);
}
#include<stdio.h>
#include<conio.h>
#define one 1 //Macro
void main()
{
printf("One = %d",one);
}
#include<stdio.h>
#include<conio.h>
#define one 1
#define two 2
#define three one+two //Nested Marco
void main()
{
printf("\nOne = %d",one);
printf("\nTwo = %d",two);
printf("\nThree = %d",three);
}
#include<stdio.h>
#include<conio.h>
#define add(x,y) x+y //Argumented Macro
void main()
{
int a=5,b=6;
float c=1.2,d=7.1;
printf("\nadd(3,4) = %d",add(3,4));
printf("\nadd(a,b) = %d",add(a,b));
printf("\nadd(c,d) = %0.1f",add(c,d));
}
#include<stdio.h>
#include<conio.h>
#define one 1 //Macro
void main()
{
printf("\nOne = %d",one);
#undef one
int one=12;
printf("\nOne = %d",one);
}
void show()
{
printf("I am in demoheader.h Header file");
}
#include<stdio.h>
#include<conio.h>
#include "demoheader.h"
void main()
{
show();
printf("\nNow i am in preprocessor.c (Current) File");
}
#include<stdio.h>
#include<conio.h>
#define one 1 //Macro
void main()
{
#ifdef one
printf("One = %d",one);
#endif
}
#include<stdio.h>
#include<conio.h>
#define one 1 //Macro
void main()
{
#ifdef one
printf("One = %d",one);
#endif
#undef one
#ifndef one
printf("\nOne is not Defined");
#endif
}
#include<stdio.h>
#include<conio.h>
#define x 5
#define y 3
void main()
{
#if (x>y)
printf("x is greater");
#endif
}
#include<stdio.h>
#include<conio.h>
#define x 15
#define y 13
void main()
{
#if (x>y)
printf("x is greater");
#else
printf("y is greater");
#endif
}
#include<stdio.h>
#include<conio.h>
#define x 213
#define y 113
void main()
{
#if (x>y)
printf("x is greater");
#elif (x<y)
printf("y is greater");
#else
printf("Both are Equal");
#endif
}
#include<stdio.h>
#include<conio.h>
void end();
#pragma startup start
#pragma exit end
void main()
{
printf("\n Now I am in main function");
}
void start()
{
printf("\nI am in Starting of Program");
}
void end()
{
printf("\nI am in the End of Program");
}