Experiment: / Program To Print The ASCII Equivalent of Any Character
Experiment: / Program To Print The ASCII Equivalent of Any Character
Experiment: / Program To Print The ASCII Equivalent of Any Character
#include<iostream.h>
#include<conio.h>
void main()
{
char ch;
int a;
cout<<"Enter the character"
cin>>ch;
a=ch;
cout<<"The ASCII value of entered character is "<<a;
getch();
}
EXPERIMENT
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,n,l;
cout<<"enter the no. of lines";
cin>>n;
for(i=1;i<=n;i++)
{
l=n-(i-1);
for(j=n;j>=i;j--)
{
cout<<l;
l--;
}
cout<<endl;
}
getch();
}
EXPERIMENT
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<string.h>
void main()
{
char str[20],rev[20],ch;
int i,j,l;
clrscr();
#include<iostream.h>
#include<conio.h>
int max(int a[],int) ;
int min(int a[],int) ;
int main()
{
int a[10],i,n,large,small;
cout<<"Enter the size of the array";
cin>>n;
cout<<"\nENTER THE ELEMENTS OF THE ARRAY";
for(i=0;i<n;i++)
{
cout<<"\nElement"<<i+1;
cin>>a[i];
}
large=max(a,n);
small=min(a,n);
cout<<"\nThe largest element is"<<large;
cout<<"\nThe smallest element is"<<small;
return(0);
}
int max(int a[],int n)
{
int large=a[0],i;
for(i=0;i<n;i++)
{
if(a[i]>large)
large=a[i];
}
return large;
}
int min(int a[],int n)
{
int small=a[0],i;
for(i=0;i<n;i++)
{
if(a[i]<small)
small=a[i];
}
return small;
}
EXPERIMENT
//Program to perform matrix addition
#include<iostream.h>
#include<conio.h>
int main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,l,m,n,o,p;
cout<<"enter the no.of rows in 1st matrix";
cin>>k;
cout<<"enter the no.of columns in 1st matrix";
cin>>l;
cout<<"enter the no.of rows in 2nd matrix";
cin>>m;
cout<<"enter the no. of columns in 2nd matrix";
cin>>n;
if((k==m)&&(l==n))
{
cout<<"ENTER FIRST MATRIX";
for(i=0;i<k;i++)
{
for(j=0;j<l;j++)
{
cin>>a[i][j];
}
}
cout<<"ENTER SECOND MATRIX";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
cout<<"THE SUM OF MATRICES IS\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]+b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
}
else
cout<<"MATRICS CAN'T BE ADDED";
getch();
return(0);
}
EXPERIMENT
//Program to perform matrix subtraction
#include<iostream.h>
#include<conio.h>
int main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,l,m,n,o,p;
cout<<"enter the no.of rows in 1st matrix";
cin>>k;
cout<<"enter the no.of columns in 1st matrix";
cin>>l;
cout<<"enter the no.of rows in 2nd matrix";
cin>>m;
cout<<"enter the no. of columns in 2nd matrix";
cin>>n;
if((k==m)&&(l==n))
{
cout<<"ENTER FIRST MATRIX";
for(i=0;i<k;i++)
{
for(j=0;j<l;j++)
{
cin>>a[i][j];
}
cout<<"\n";
}
cout<<"ENTER SECOND MATRIX";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
cout<<"\n";
}
cout<<"THE DIFFERENCE OF MATRICES IS\n ";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
c[i][j]=a[i][j]-b[i][j];
cout<<c[i][j]<<"\t";
}
cout<<"\n\n" ;
}
}
else
cout<<"MATRICS CAN'T BE SUBTRACTED";
getch();
return(0);
}
EXPERIMENT
//Program to do matrix multiplication
#include<iostream.h>
#include<conio.h>
void main()
{
int a[5][5],b[5][5],c[5][5],i,j,k,l,m,n,o,sum;
cout<<"Enter the no.of rows of matrix 1";
cin>>k;
cout<<"Enter the no.of columns of matrix 2";
cin>>l;
cout<<"Enter the no.of rows of matrix 2";
cin>>m;
cout<<"Enter the no.of columns of matrix 2";
cin>>n;
if(l==m)
{
cout<<"MATRIX CAN BE MULTIPLIED";
cout<<"\n\nENTER MATRIX 1";
for(i=0;i<k;i++)
{
for(j=0;j<l;j++)
{
cin>>a[i][j];
}
}
cout<<"\n\nENTER MATRIX 2";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
{
cin>>b[i][j];
}
}
cout<<"\nPRODUCT OF MATRIX IS ";
for(i=0;i<k;i++)
{
for(j=0;j<n;j++)
{
sum=0;
for(o=0;o<l;o++)
{
sum+=a[i][o]*b[o][j];
}
c[i][j]=sum;
cout<<c[i][j]<<"\t";
}
cout<<"\n";
}
}
else
cout<<"MATRIX CAN'T BE MULTIPLIED";
getch();
}
EXPERIMENT
#include<iostream.h>
#include<conio.h>
int max(int,int,int);
int main()
{
int a,b,c,large;
cout<<"Enter the 1st number";
cin>>a;
cout<<"Enter the 2nd number";
cin>>b;
cout<<"Enter the 3rd number";
cin>>c;
large=max(a,b,c);
cout<<"\nThe largest number is"<<large;
getch();
return(0);
}
int max(int a,int b,int c)
{
if(a>b)
{
if(a>c)
return a;
}
else if(b>c)
{
return b;
}
else
return c;
}
EXPERIMENT
//program to depict call by value and call by refernce
#include<iostream.h>
#include<conio.h>
int addone(int) ;
int *change(*int);
int main()
{
int x;
cout<<"Enter the value of x";
cin>>x;
x=addone(x);
cout<<"\nCALL BY VALUE";
cout<<"\nThe value of x in main is "<<x;
*change(*x);
cout<<"\n\nCALL BY REFERNCE";
cout<<"\nThe value of x in main is "<<x;
getch();
return(0);
}
int addone(int x)
{
x+=1;
cout<<"\nthe value of x in func. is "<<x;
return x;
}
int *change(int *x)
{
*x+=1;
cout<<"\nthe value of x in finc. is "<<*x;
return *x;
}
EXPERIMENT
#include<iostream.h>
#include<conio.h>
long int fact1(int);
int main()
{
int n;
long fact;
clrscr();
cout<<"Enter the number";
cin>>n;
fact=fact1(n);
cout<<"The factorial of the number is "<<fact;
getch();
return(0);
}
long int fact1(int n)
{
long int fact=1;
int i;
for(i=1;i<=n;i++)
{
fact*=i;
}
return fact;
}
EXPERIMENT
#include<iostream.h>
#include<conio.h>
void fibbonacci(int,int,int);
int main()
{
int n,first=0,second=1;
clrscr();
cout<<"Enter number of terms you want";
cin>>n;
fibbonacci(first,second,n);
getch();
return(0);
}
void fibbonacci(int first,int second,int n)
{
int third,i;
cout<<first <<","<<second <<",";
for(i=3;i<=n;i++)
{
third=first+second;
cout<<third <<",";
first=second;
second=third;
}
}
EXPERIMENT
//To print the sum, difference, product, quotient,remainder of two numbers
#include<iostream.h>
#include<conio.h>
void main()
{
int x,y;
clrscr();
cout<<”Enter first number”;
cin>>x;
cout<<”Enter second number”;
cin>>y;
cout<<”The sum of numbers is”<<x+y;
cout<<”\nThe diference of numbers is<<x-y;
cout<<”The product of numbers is”<<x*y;
cout<<”The quotient on dividing the numbers is”<<x/y;
cout<<”The remainder obtained on dividing the numbers is”<<x%y;
getch();
}
EXPERIMENT
//Program using functions to swap two numbers
#include<iostream.h>
#include<conio.h>
void swap(int&,int&);
void main()
{
int x,y;
clrscr();
cout<<”Enter the value of x”;
cin>>x;
cout<<”Enter the value of y”;
cin>>y;
cout<<”\n\nVALUES BEFORE SWAPPING”;
cout<<”\nx= “<<x<<”\ny= “<<y;
swap(x,y);
cout<<”\n\nVALUES AFTER SWAPPING”;
cout<<”\nx= “<<x<<”\ny= “<<y;
getch();
}
void swap(int &x, int &y)
{
int temp;
temp=x;
x=y;
y=temp;
}