You are on page 1of 34

/* TO PRINT A LINE OF TEXT */

#include<stdio.h>
#include<conio.h>
void main()
{
clrscr();
printf("HELLO JCD COLLEGE OF ENGINEERING");
getch();
}
OUTPUT
/*PROGRAM TO FIND THE LARGEST OF
THREE NUMBERS*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("Enter value of A,B&C : ");
scanf("%d%d%d",&a,&b,&c);
if(a>b)
{
if(a>c)
printf("A is larger : %d",a);
else
printf("C is larger : %d",c);
}
else
{
if(b>c)
printf("B is larger : %d",b);
printf("C is larger : %d",c);
}
getch();

}
OUTPUT
/*PROGRAM TO CALCULATE SUM
&
AVERAGE OF THREE NUMBERS*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c,sum,avg;
clrscr();
printf("Enter the values of A,B&C : ");
scanf("%d%d%d",&a,&b,&c);
sum=a+b+c;
printf("Sum of A,B&C:%d\n",sum);
avg=sum/3;
printf("Average of A,B&C :%d",avg);
getch();
}
OUTPUT
/*PROGRAM TO FIND WHEATHER
A NO. IS EVEN OR ODD*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the no. : ");
scanf("%d",&a);
if(a%2==0)
printf("No. is even :%d ",a);
else
printf("No. is odd :%d ",a);
getch();
}
OUTPUT
/*PROGRAM FOR SWAPING TWO
NUMBERS*/

/*(A) USING THIRD VARIABLE*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,temp;
clrscr();
printf("Enter the values of A&B : ");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("A&B after swapping :%d,%d",a,b);
getch();
}
OUTPUT
/*(B) WITHOUT USING THIRD VARIABLE*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b;
clrscr();
printf("Enter the values of A&B : ");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("A&B after swapping :%d,%d",a,b);
getch();
}

OUTPUT
/*PROGRAM TO FIND SUM OF DIGITS AND
REVERSE OF A GIVEN NUMBER*/
#include<stdio.h>
#include<conio.h>
void main()
{
int n,a,sum,i,j;
clrscr();
printf("enter the number ");
scan("%d",&n);
a=n;
sum=0;
while(n>0)
{
i=n%10;
n=n/10;
sum=sum+i;
}
printf("sum of digits are %d\n",sum);
printf("reverse of a number is ");
while(a>0)
{
j=a%10;
a=a/10;
printf("%d",j);
}
getch();
}
/*PROGRAM TO FIND FACTORIAL OF GIVEN
NUMBER USING RECURSION*/

#include<stdio.h>
#include<conio.h>
fact(int n)
{
if(n==0)
return 1;
else
return (n*fact(n-1));
}
void main()
{
int n,f;
printf("enter th number");
scanf("%d",&n);
f=fact(n);
printf("%d",f);
getch();
}
OUTPUT
/*PROGRAM TO PRINT FIBONACCI
SERIES UPTO N TERMS*/

#include<stdio.h>
#include<conio.h>
fib (int);
void main()
{
int i,n;
clrscr();
printf("Enter n: ");
scanf("%d",&n);
printf("Fibonacci series is : \n");
for(i=0;i<=n;i++)
{
printf("%d\n",fib(i));
}
getch();
}
fib(int n)
{
if(n<=1)
return n;
else
return (fib(n-1)+fib(n-2));
}
/*PROGRAM FOR CONVERTING A DECIMAL
NO. INTO BINARY NO.*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10],n,i=1,j;
clrscr();
printf("Enter the no. :");
scanf("%d",&n);
do
{
a[i]=n%2;
n=n/2;
i++;
}
while(n>0);
for(j=i-1;j>=1;j--)
{
printf("%d",a[j]);
}
getch();
}
/*PROGRAM TO FIND SUM OF TWO GIVEN
MATRIX*/
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],i,j,n,m,sum[10][10];
clrscr();
printf("Enter the order of matrix :");
scanf("%d%d",&m,&n);
printf("Enter the value of first matrix :\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the value of second matrix :\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&b[i][j]);
}
}
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
sum[i][j]=a[i][j]+b[i][j];
}
}
printf("Resultant matrix :\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
printf("%d\t",sum[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT
/*PROGRAM FOR SUM
OF TEN
NATURAL NO.*/

#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,i,n;
clrscr();
printf("Enter no. of natural no. : ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
a=a+i;
}
printf("Sum of 10 natural no. is : %d",a);
getch();
}
OUTPUT
/* roll.no., name, marks of n students and their
average */

#include<stdio.h>
#include<conio.h>
struct stu
{
char na[10];
int marks,rollno;
};
main()
{
struct stu *s;
int i,n,ss;
printf("enter the no of students\n");
scanf("%d",&n);
s=(struct stu *)malloc(sizeof(struct stu)*n);
for(i=0;i<n;i++)
{
printf("enter the name");
scanf("%s",s[i].na);
printf("enter the Roll no");
scanf("%d",&s[i].rollno);
printf("enter the marks");
scanf("%d",&s[i].marks);

}
ss=0;
for(i=0;i<n;i++)
{
ss=ss+s[i].marks;
}
ss=ss/n;
printf("\nAverage OF marks %d",ss);
getch();
}
/*product of two matrixes */

#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],c[10][10],i,j,k,o,p,m,n;
clrscr();
printf("Enter the order of 1st matrix : ");
scanf("%d%d",&m,&n);
printf("Enter the order of 2nd matrix : ");
scanf("%d%d",&o,&p);
printf("Enter the value of 1st matrix :\n");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the value of 2nd matrix :\n");
for(i=1;i<=o;i++)
{
for(j=1;j<=p;j++)
{
scanf("%d",&b[i][j]);
}
}
if(n==o)
for(i=1;i<=m;i++)
{
for(j=1;j<=p;j++)
{
for(k=1;k<=p;k++)
{
c[i][j]=c[i][j]+a[i][k]*b[k][j];
}
}
}
for(i=1;i<=m;i++)
{
for(j=1;j<=p;j++)
{
printf("%d",c[i][j]);
}
}
getch();
}
/*PROGRAM TO CHECK WHETHER A GIVEN
STRING IS PALINDROME OR NOT*/

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main()
{
char a[10],b[10];
clrscr();
printf("Enter the name: ");
gets(a);
strcpy(b,a);
strrev(b);
if((strcmp(b,a))==0)
printf("The name is palindrome");
else
printf("The name is not palindrome");
getch();
}

/*PROGRAM TO FIND TRANSPOSE OF A GIVEN


MATRIX */
#include<stdio.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],i,j,k,m,n;
clrscr();
printf("enter the row and column of matrix");
scanf("%d%d",&m,&n);
printf("enter the values of matrix");
for(i=1;i<=m;i++)
{
for(j=1;j<=n;j++)
{
scanf("%d",&a[i][j]);
}
}
for(j=1;j<=n;j++)
{
for(i=1;i<=m;i++)
{
printf("/n%d",a[i][j]);
}
}
getch();
}

/*..Call by value../*

#include<stdio.h>
#include<conio.h>
void main()
{
Int a=20,b=40;
clrscr();
printf(“\n value of actual parameter \n”);
printf(“1. before function call is %d %5d \n”,a,b);
swap(a,b);
printf(“2. after function call is %d %5d”,a,b);
getch();
}
swap(int x,int y)
{
Int t;
t=x;
x=y;
y=t;
}
/*..Call by reference../*

#include<stdio.h>
#include<conio.h>
swap(int,int);
void main()
{
Int a=20,b=40;
clrscr();
printf(“\n value of actual parameter \n”);
printf(“1. before function call is %d %5d \n”,a,b);
swap(a,b);
printf(“2. after function call is %d %5d”,a,b);
getch();
}
swap(int *x,int *y)
{
Int t;
t=*x;
*x=*y;
*y=t;
}

You might also like