Experiment: / Program To Print The ASCII Equivalent of Any Character

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 26

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

/* Program to print the following pattern 1


12
123
1234 */
#include<iostream.h>
#include<conio.h>
void main()
{
int i,j,n;
clrscr();
cout<<"Enter the no.of lines you want";
cin>>n;
for(i=1;i<n+1;i++)
{
for(j=1;j<=i;j++)
{
cout<<j;
}
cout<<"\n";
}
getch();
}
EXPERIMENT

/* Program to print the pattern


54321
4321
321
21
1 */

#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

//PROGRAM TO REVERSE A STRING

#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();

cout<<"Enter the string";


gets(str);
l=strlen(str);
for(i=l-1,j=0;str[i]!='\0';i--,j++)
{
rev[j]=str[i];
}
cout<<"The reversed string is ";
puts(rev);
getch();
}
EXPERIMENT
//Program to find the max and min in a 1D array

#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

//CREATING A FUNCTION AND CALLING IN MAIN FUNCTION

#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

//calculating factorial of a number by using function (iterative call)

#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

//Program to print fibbonacci series using iterative call of function

#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;
}

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy