Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                

C++ File.m

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 45

//Write a program that reads three numbers, the display

//a) The largest

//b) The smallest

//(a)C++ program

#include<iostream.h>

void main()

float x,y,z;

cout<<"enter x,y,z";

cin>>x>>y>>z;

if(x>y)

if(x>z)

cout<<"largest is"<<x;

else

cout<<"largest is"<<z;

(a)alternative method or way for largest number

#include<iostream.h>

void main()

float x,y,z,max;

cout<<"enter x,y,z";
1
cin>>x>>y>>z;

max=x;

if(y>max)

max=y;

if(z>max)

max=z;

cout<<"largest is"<<max;

(b)The smallest number

#include<iostream.h>

void main()

float x,y,z,min;

cout<<"enter x,y,z";

cin>>x>>y>>z;

if(x<y)

{if(x<z)

cout<<"smallest is"<<x;

else

cout<<"smallest is"<<z;

else if(y<z)

cout<<"smallest is"<<y;

//(a)alternative method or way for largest number

#include<iostream.h>
2
void main()

float x,y,z,max;

cout<<"enter x,y,z";

cin>>x>>y>>z;

max=x;

if(y>max)

max=y;

if(z>max)

max=z;

cout<<"largest is"<<max;

(b)Alternative for smallest number

#include<iostream.h>

void main()

float x,y,z,min;

cout<<"enter x,y,z";

cin>>x>>y>>z;

min=x;

if(y<min)

min=y;

if(z<min)

min=z;

cout<<"smallest is"<<min;

}
3
//Write C++ programs to coefficients of a quadratic equation
//ax2+bx+c=0, the display roots of the equation (assume that the
//equation has real roots, such that √(b2-4ac)>=0)

//Solutions formula for a quadratic equation with real roots

#include<iostream.h>

#include<math.h>

void main ()

float a,b,c,x1,x2;

cout<<"enter a: ";

cin>>a;

cout<<"enter b: ";

cin>>b;

cout<<"enter c: ";

cin>>c;

x1=(-b+sqrt(b*b-4*a*c))/2*a;

x2=(-b-sqrt(b*b-4*a*c))/2*a;

cout<<"x1= "<<x1<<endl;

cout<<"x2= "<<x2;

//Write C++ programs to coefficients of a quadratic equation


//ax2+bx+c=0, the display roots of the equation (assume that the
//equation has real roots, such that ?(b2-4ac)>=0)

//Write a program that reads two numbers, x and y, then calculate

//a. x+y ,

//b. x-y,

4
//c. x/y,

//d. x*y,

//e. x%y,

//C++ program

#include<iostream.h>

void main()

int x;

int y;

int a;

int b;

float c;

int d;

int e;

cout<<"x: ";

cin>>x;

cout<<"y: ";

cin>>y;

a=x+y;

cout<<"a= "<<a<<endl;

b=x-y;

cout<<"b= "<<b<<endl;

c=x/y;

cout<<"c= "<<c<<endl;

d=x*y;

cout<<"d= "<<d<<endl;

e=x%y;
5
cout<<"e= "<<e;

//Write C++ program to read a real number x and then evaluate the
//following functions

a) f(x)=x3+3x2-4x+2,

b) f(x)=(x2+5)(x2-5)

x2 +3

c) f(x)=x2√(x3+4)

d) f(x) = x-3

√(x^1.5-23)

C++ program

#include<iostream.h>

#include<math.h>

void main()

float x,f1,f2,f3,f4;

cout<<"x: ";

cin>>x;

f1=(x*x*x)*3*(x*x)-4*x+2;

f2=(x*x*+5)*(x*x-5)/(x*x+3);

f3=(x*x)*sqrt(x*x*x+4)/8;

f4=fabs(x-3)/sqrt(fabs(sqrt(x*x*x+4)-25));

cout<<"f1= "<<f1<<endl;

cout<<"f2= "<<f2<<endl;

6
cout<<"f3= "<<f3<<endl;

cout<<"f4= "<<f4;

The sides length a triangle are given as a=20,b=15,c=19,.write a C+


+program to

a) Display the area of the triangle

b) Find the angles of the triangle.

#include<iostream.h>

#include<math.h>

void main()

int a=20;

int b=15;

int c=19;

float s,A0,A,B,C;

s=(a+b+c)/2;

A0=sqrt(s*(s-a)*(s-b)*(s-c));

A=asin(2*A0/(b*c));

B=asin(2*A0/(a*c));

C=asin(2*A0/(a*b));

cout<<"A0= "<<A0<<endl;

cout<<"A= "<<A<<endl;

cout<<"B= "<<B<<endl;

cout<<"C= "<<C;

A supplier has only one customer for a product. The customer purchases
the product only once a week. When the order is received, the supplier
7
meets the demand, if the sufficient stock is available. Otherwise, the
customer either lifts the entire stock available with the supplier or
refuses any purchases and goes elsewhere. Write a program to read the
existing stock with the supplier, the demand and the customer options
in case the demand exceeds the supply and to display the closing stock.

#include<iostream.h>

void main()

int openingstock;

int closingstock;

int demand;

int choice;

cout<<"enter openingstock";

cin>>openingstock;

cout<<"ente demand";

cin>>demand;

if(openingstock>=demand)

closingstock=openingstock-demand;

cout<<"closingstock= "<<closingstock;

else

cout<<"enter 1 to take all, else enter any other key to take none";

cin>>choice;

if(choice==1)

closingstock=0;}

8
else

closingstock=openingstock;

cout<<"closiningstock= "<<closingstock;

A cinema currently sells tickets for a full price of $6,but always sells
tickets for half price to people who are less than 16years old, and for a
third of the price for people who are 60years old or more. Use “cin” and
“if…else…”statements to complete the following program.

#include<iostream.h>

//Const float FULL_PRICE=6.0;

Void main ()

Int user age;

cout<<”inter the user age”;

add statement(s) here

return 0;

//So that it produces output such as enter your age: 63

//Your ticket costs $2.00

//(The number "63" in bold is a user input.)

//prgram to test arithmetic assignment operators

#include<iostream.h>

void main()
9
{

int n=22;

cout<<"n="<<n<<endl;

n+=9;

cout<<"n+=9,n="<<n<<endl;

n-=5;

cout<<"n-=5,n="<<n<<endl;

n*=2;

cout<<"n*=2,n="<<n<<endl;

n/=3;

cout<<"n/=3,n="<<n<<endl;

n%=7;

cout<<"n%=7,n="<<n;

//CONVERT FAHRENHEIT INTO CELICIUS

#include<iostream.h>

const int freeze=32;

const float ratio=5.0/9;

void main ()

float fahrenheit,celicius;

cout<<"enter temperature in Fahrenheit: ";

cin>>fahrenheit;

//compute

celicius=ratio*(fahrenheit-freeze);

cout<<"result temperature in degree celicius: "<<celicius;


10
}

//shows the use of variables

#include<iostream.h>

void main()

int var1=10;

int var2;

int var3=50;

cout<<"var1: "<<var1<<endl;

cout<<"var3: "<<var3<<endl;

var2=var3-var1;

cout<<"var3-var1= "<<var2<<endl;

//PROGRAM TO TEST ARITHMETIC OPERATORS

#include<iostream.h>

void main ()

int n=22;

cout<<"n= "<<n<<endl;

n+=9;

cout<<"after n+=9,n="<<n<<endl;

n-=5;

cout<<"after n-=5,n="<<n<<endl;

n*=2;

cout<<"after n*=2,n="<<n<<endl;
11
n/=3;

cout<<"after n/=3,n="<<n<<endl;

n%=7;

cout<<"after n%=7,n="<<n<<endl;

//program to print character

#include<iostream.h>

void main()

char c='A';

cout<<"c= "<<c<<endl;

c='B';

cout<<"c= "<<c<<endl;

c='t';

cout<<"c= "<<c<<endl;

//program to print 2 integers,three decimal numbers,and four


characters;

#include<iostream.h>

void main ()

int m;

int n;

cout<<"two integers";

cin>>m>>n;

cout<<"m: ="<<"n: = "<<m<<n<<endl;

cout<<"three decimal numbers";

12
double a,b,c;

cin>>a>>b>>c;

cout<<"a=: "<<"b: ="<<"c: ="<<a<<b<<c<<endl;

char c1,c2,c3,c4;

cout<<"four charater";

cin>>c1>>c2>>c3>>c4;

cout<<"c1: ="<<"c2: ="<<"c3: ="<<"c4:


="<<c1<<c2<<c3<<c4<<endl;

#include<iostream.h>

void main()

int openingstock;

int closingstock;

int demand;

int choice;

cout<<"enter openingstock";

cin>>openingstock;

cout<<"ente demand";

cin>>demand;

if(openingstock>=demand)

closingstock=openingstock-demand;

cout<<"closingstock= "<<closingstock;

else

13
{

cout<<"enter 1 to take all, else enter any other key to take none";

cin>>choice;

if(choice==1)

closingstock=0;}

else

closingstock=openingstock;

cout<<"closiningstock= "<<closingstock;

//8. THE ROOT OF THE POLYNOMIAL USING THE BISECTION METHOD

#include<iostream.h>

void main()

float x0,x1,x2,x3,fx1,fx2;

cout<<"enter x0: ";

cin>>x0;

cout<<"enter x1: ";

cin>>x1;

x2=(x0+x1)/2;

fx1=600*x1*x1*x1*x1-500*x1*x1*x1-200*x1*x1-20*x1-1;

fx2=600*x2*x2*x2*x2-550*x2*x2-20*x2-1;

x3=(x2+x1)/2;

if (fx1*fx2<0)
14
{

cout<<"x3=(x1+x2)/2"<<endl;

else

cout<<"x3=(x0+x2)/2"<<endl;

cout<<"the root is :"<<x3<<endl;

//fabs(fx3)<0.0000001;

//WRITE C++ PROGRAM TO DISPLAY ALL PRIME NUMBER BETWEEN 0 AND


100

#include<iostream.h>

void main()

long int i;

cout<<"the prime number is 2"<<endl;

cout<<"the prime number is 3"<<endl;

cout<<"the prime number is 5"<<endl;

cout<<"the prime number is 7"<<endl;

i=10;

while(i<100)

i=i+1;

if((i%2!=0)&&(i%3!=0)&&(i%5!=0)&&(i%7!=0))

15
cout<<"the prime number is"<<i<<endl;

#include<iostream.h>

void main()

int day1, nodays,i,dcount;

cout<<"enter day1";

cin>>day1;

cout<<"enter nodays";

cin>>nodays;

cout<<endl<<endl;

cout<<"the calender is \n";

cout<<"mon\ttue\twen\tthu\tfr\tsat\sun";

for(i=1;i<=nodays;i++)

cout<<i<<"\t";

if(dcount%7==0)

cout<<endl;

dcount++;

//this program read a number and calculate its factorial

#include<iostream.h>

void main()
16
{

int number,i;

long int fact;

cout<<"enter the no whose factorial is requred: ";

cin>>number;

fact=1;

i=1;

fact=fact*i;

while(i<number)

i++;

fact=fact*i;

cout<<"factorial of: "<<number<<"is: "<<fact;

//this program read an integer nummber and sum to n term

#include<iostream.h>

void main()

int n,i=1;

cout<<"enter a positive integer : "<<endl;

cin>>n;

long sum=0;

while(i<=n)

sum=sum+i++;
17
{

cout<<"the sum of the first stated numbers of integers: is "<<sum<<endl;

#include<iostream.h>

void main()

int number,i;

long int fact;

cout<<"enter the no whose factorial is requred: ";

cin>>number;

fact=1;

i=1;

do

fact=fact*i;

i++;

while(i<=number);

cout<<"factorial of a number: "<<"is:"<<fact;

#include<iostream.h>

void main()

{
18
int n,i=0;

cout<<"enter a positive integer:"<<endl;

cin>>n;

long sum=0;

do

sum+=i++;

while(i<=n);

cout<<"the sum of the first n: "<<n<<"positive integers = "<<sum<<endl;

#include<iostream.h>

void main()

int n;

for(n=1;n<=20;n++)

cout<<"the square of"<<n<<"is"<<n*n<<endl;

//THE SQUARE OF A NUMBER

#include<iostream.h>

void main()

int n;
19
for(n=1;n<=10;n++)

cout<<"the square of n is equal to"<<n<<" is = "<<n*n<<endl;

//The sum of even numbers

//Use for

#include<iostream.h>

void main()

int i;

long int s;

s=0;

for(i=0;i<=6;i+=2)

s=s+i;

cout<<"the sum is "<<s;

Use while

#include<iostream.h>

void main()

int i;

long int s;

i=0;
20
s=0;

while(i<6)

i+=2;

s=s+i;

cout<<"the sum of even number is"<<s;

#include<iostream.h>

void main()

int i=0;

int t=1;

long int s=1;

while(i<4)

i++;

t=2*i+1;

s=s+t;

cout<<"the sum of odd numbers is"<<s;

#include<iostream.h>

void main()

int i=0;

int t=1;
21
long int s=1;

while(i<4)

i++;

t=2*i+1;

s=s+t;

cout<<"the sum of odd numbers is"<<s;

//WRITE A C++ PROGRAM THAT FIND THE SUM OF ODD NUMBERS BTN 0
AND 1000.

#include<iostream.h>

void main()

int i;

long int s;

i=1;

s=1;

for(i=1;i<999;i+=2)

s=s+i;

cout<<"sum is"<<s;

22
//THE PROGRAM TO CALCULATE THE FACTORIAL OF A NUMBER

#include<iostream.h>

//a program using te while loop to calculate

//the factorial number of a number

void main()

long unsigned int number,i;

long unsigned int fact;

cout<<"enter the number whose factorial is needed: ";

cin>>number;

fact=1;

i=1;

while(i<number)

i++;

fact=fact*i;

cout<<"factorial of "<<number<<"="<<fact;

//1. THE SUM OF EVEN NUMBERS BTN 0 AND 1000

#include<iostream.h>

void main()

int i;

long int s;

s=0;

for(i=0;i<=1000;i+=2)
23
{

s=s+i;

cout<<"THE SUM IS= "<<s;

//2.THE SUM OF ODD NUMBERS FROM O TO 100;

#include<iostream.h>

void main()

int i;

long int s;

i=1;

s=1;

while(i<999)

i+=2;

s=s+i;

cout<<"the sum is: "<<s;

//3.PRIME NUMBER

#include<iostream.h>

void main()

int i;

i=10;
24
cout<<" "<<2<<" "<<3<<" "<<5<<" "<<7;

do

if((i%2!=0)&&(i%3!=0)&&(i%5!=0)&&(i%7!=0))

cout<<" "<<i;

i++;

while(i<97);

cout<<" "<<i;

//4.READ THE SERIES OF DATA AND FIND THE MEAN

//FOR LOOP

#include<iostream.h>

void main()

float x,s,mean;

int i;

int n;

s=0;

cout<<"enter the value of n: ";

cin>>n;

for(i=1;i<=n;i++)

cout<<"enter the value of x: ";

cin>>x;

s=s+x;

}
25
mean=s/n;

cout<<"the mean of n series of data is "<<mean<<endl;

//DO WHILE

#include<iostream.h>

void main()

int i,n;

double x,s,mean;

i=1;

s=0;

cout<<"enter the value x";

cin>>x;

cout<<"enter the value of n";

cin>>n;

do

i++;

s=s+x;

while(i<n);

mean=s/n;

cout<<"mean is: "<<mean;

//5.THE SUM OF THE SERIES IS


26
#include<iostream.h>

//program to read x for the series of e^x and display the sum

#include<math.h>

void main()

double x,t, E;

int i;

i=0;

t=1;

E=1;

cout<<"enter the value of x";

cin>>x;

do

i++;

t=x*t/i;

E=E+t;

while(fabs(t)>(0.0000001));

cout<<"exp("<<x<<")= "<<E;

//NEWTON'S RAPHSONS METHOD

#include<iostream.h>

#include<math.h>

float F(float x);

float DF(float x);


27
void main()

float x1,x2;

x1=0.1;

x2=x1-F(x1)/DF(x1);

do

x1=x2;

x2=x1-F(x1)/DF(x1);

while(fabs(x1-x2)>0.0000001);

cout<<"\n the root is "<<x2<<endl;

float F(float x)

return 600*(x*x*x*x)-550*(x*x*x)+200*(x*x)-20*(x)-1;

float DF(float x)

return 2400*(x*x*x)-1650*(x*x)+400*x-20;

//THE ARRAY OF A NUMBER

#include<iostream.h>

void main()

int sample[10];//this reserves 10 integer elements

int t;
28
//load the array

for(t=0;t<10;t++)

sample[t]=t;

//display the array

for(t=0;t<10;t++)

{cout<<"this is the sample["<<t<<"]: "<<sample[t]<<endl;

//ARROYS.

#include<iostream.h>

void main()

int nums[5];

int i;

for(i=0;i<5;i++)

nums[i]=i;

cout<<"nums[i]: "<<nums[i]<<endl;

READ MATRICES A AND B AND FIND THE SUM OF A NAD B WHICH EQUAL
C

//program read matrices A,B

//display the sum matrix

29
#include<iostream.h>

void read(float M[10][10]);

void findsum(float A[10][10],float B[10][10],float C[10][10]);

void display (float C[10][10]);

int n,m;

void main()

float A[10][10],B[10][10],C[10][10];

cout<<"enter row";

cin>>n;

cout<<"enter column";

cin>>m;

read(A);

read(B);

findsum(A,B,C);

display(C);

void read(float M[10][10])

int i,j;

for(i=0;i<n;i++)

for(j=0;j<m;j++)

cin>>M[i][j];

}
30
void findsum(float A[10][10],float B[10][10],float C[10][10])

int i,j;

for(i=0;i<n;i++)

for(j=0;j<m;j++)

C[i][j]=A[i][j]+B[i][j];

void display(float C[10][10])

int i,j;

cout<<"the sum matrix is \n";

for(i=0;i<n;i++)

for(j=0;j<m;j++)

cout<<C[i][j]<<"\t";

cout<<endl;

SOME ARRAY

#include <iostream.h>

int main()
31
{

int SomeArray[5][2] = { {0,0}, {1,2}, {2,4}, {3,6}, {4,8}};

for (int i = 0; i<5; i++)

for (int j=0; j<2; j++)

cout << "SomeArray[" << i << "][" << j << "]: ";

cout << SomeArray[i][j]<< endl;

return 0;

ILLUSTRATIONS OF ARRAY

#include<iostream.h>

int main()

int i,number[10];

cout<<"enter YOUR 10 numbers: ";

for(i=0;i<10;++i)

cin>>number[i];

cout<<"the following is a list of the entered numbers, "<<"In reversing


order are;"<<" \t";

for(i=9;i>=0;--i)

cout<<number[i]<<"\t";

32
}

return 0;

//the following is an arrangement of the numbers in ascending order

#include<iostream.h>

void read_data();

void sort_data();

void display_data();

int i,j;

int number[100];

int store,n;

void main()

read_data();

sort_data();

display_data();

void read_data()

cout<<"how many numbers do you want to sort?: ";

cin>>n;

cout<<"enter the number "<<n<<"numbers: ";

for(i=0;i<n;++i)

cin>>number[i];

void sort_data()

{
33
for(i=0;i<n;++i)

for(j=0;j<n;++j)

if(number[j]>number[j+1])

store=number[j];

number[j]=number[j+1];

number[j+1]=store;

void display_data()

cout<<"the following is an arrangement of the numbers in ascending


order: \n";

for(i=0;i<n;++i)

cout<<number[i]<<" ";

//the program to read number computes average and evaluates the


minimum and maximum

#include<iostream.h>

int avg,range;

int sum;

void main()

int i,minvalue,maxvalue;

int nums[10];

nums[0]=10;

nums[1]=18;
34
nums[2]=75;

nums[3]=0;

nums[4]=1;

nums[5]=56;

nums[6]=100;

nums[7]=12;

nums[8]=-19;

nums[9]=88;

//compute the average

avg=0;

sum=0;

for(i=0;i<10;i++)

sum+=nums[i];

avg=sum/10;//calculate the average

cout<<"average is: "<<avg<< " \t "<<endl;

//find the minimum and maximum values

minvalue=maxvalue=nums[0];

for(i=0;i<10;++i)

if(nums[i]< minvalue)

minvalue=nums[i];

if(nums[i]> maxvalue)

maxvalue=nums[i];
35
}

cout<<"minimum value: "<<minvalue<<endl<<endl;

cout<<"maximum value: "<<maxvalue<<endl<<endl;

range=maxvalue-minvale;

cout<<”The range is :”<<range:

The program to read a string from the keyboard

#include<iostream.h>

int main()

char str[80];

cout<<"enter a string: ";

cin>>str;//read string from keyboard

cout<<"here is your string:";

cout<<str;

return 0;

//Sorting data.cpp

//the program read the maximum 100 numbers and arrange them in
ascending order

#include<iostream.h>

void readdata();

void sortdata();

36
void displaydata();

int i,j;

int number[100];

int store,n;

void main()

readdata();

sortdata();

displaydata();

void readdata()

cout<<"how many numbers do you want to sort?:";

cin>>n;

cout<<"enter"<<n<<"number: ";

for(i=0;i<n;i++)

cin>>number[i];

void sortdata()

for(i=0;i<n;i++)

for(j=0;j<n-1;j++)

if(number[j]>number[j+1])

store=number[j];

number[j]=number[j+1];

number[j+1]=store;
37
}

void displaydata()

cout<<"the following is an arrangement of the numbers in ascending


order:\n";

for(j=0;j<n;j++)

cout<<number[j]<<" ";

//Sorting data.cpp

//the program read the maximum 100 numbers and arrange them in
descending order

#include<iostream.h>

void readdata();

void sortdata();

void displaydata();

int i,j;

int number[100];

int store,n;

void main()

readdata();

sortdata();

displaydata();

void readdata()

cout<<"how many numbers do you want to sort?:";


38
cin>>n;

cout<<"enter the numbers"<<n<<"number: ";

for(i=0;i<n;i++)

cin>>number[i];

void sortdata()

for(i=0;i<n;i++)

for(j=0;j<n-1;j++)

if(number[j]<number[j+1])

store=number[j];

number[j]=number[j+1];

number[j+1]=store;

void displaydata()

cout<<"the following is an arrangement of the numbers in descending


order:\n";

for(j=0;j<n;j++)

cout<<number[j]<<" ";

//This program demostrates some string functions

#include<iostream.h>

39
#include<string.h>

void main()

char Firstname[20],Lastname[20];

cout<<"Enter the first name: ";

cin>>Firstname;

cout<<"Enter the last name: ";

cin>>Lastname;

cout<<endl<<endl;

cout<<"THE FIRST NAME HAS:"<<strlen(Firstname)<<"letters"<<"\n";

cout<<"THE LAST NAME HAS: "<<strlen(Lastname)<<"letters"<<endl;

cout<<"THE FULL NAME IN CAPITAL LETTERS IS:"<<strupr(Firstname)<<"


"<<strupr(Lastname)<<endl<<endl;

cout<<"THe reverse of First name and the Lastname in capital


is:"<<strrev(Firstname)<<” “<<strrev(Lastname)<<endl;

#include<iostream.h>

void main()

int i,j;

int X[6][6];

for(i=0;i<6;i++)

for(j=0;j<6;j++)

if(i==j)

X[i][j]=0;

else if(i<j)
40
X[i][j]=3*i+j;

else

X[i][j]=2*i+3*j;

for(i=0;i<6;i++)

for(j=0;j<6;j++)

cout<<X[i][j]<<"\t";

cout<<endl<<endl;

//This program demostrates some string functions

#include<iostream.h>

#include<string.h>

void main()

char Firstname[20],Lastname[20];

cout<<"Enter the first name: ";

cin>>Firstname;

cout<<"Enter the last name: ";

cin>>Lastname;

cout<<endl<<endl;
41
cout<<"THE FIRST NAME HAS:"<<strlen(Firstname)<<"letters"<<"\n";

cout<<"THE LAST NAME HAS: "<<strlen(Lastname)<<"letters"<<endl;

cout<<"THE FULL NAME IN CAPITAL LETTERS IS:"<<strupr(Firstname)<<"


"<<strupr(Lastname)<<endl<<endl;

cout<<"THe reverse of First name and the Lastname in capital


is:"<<strrev(Firstname)<<" "<<strrev(Lastname)<<endl;

#include<iostream.h>

#include<string.h>

void main()

char Str1[50],Str2[50],Str3[50] ;

cout<<"enter your first string please:";

cin>>Str1;

cout<<"enter your second string please:";

cin>>Str2;

cout<<"The length of the first and the second string


have :"<<strlen(Str1)<<"characters"<<"and"<<strlen(Str2)<<"characters"<<
"\t";

cout<<endl<<endl;

cout<<"The comparison of the first and the second string


are :"<<strcmp(Str1,Str2)<<" "<<stricmp(Str1,Str2)<<" "<<"\t";

cout<<endl<<endl;

cout<<"Concatenate of the first and the second string


is:"<<strcat(Str1,Str2)<<Str3<<endl;

cout<<endl<<endl;

cout<<"convert all characters in third string int capital


letters:"<<strupr(Str3)<<endl;
42
cout<<"Display the third string: "<<Str3<<endl;

cout<<"The reverse of the first string:"<<strrev(Str1)<<endl;

#include<iostream.h>

void main()

int i,j,n,m;

long unsigned int X[20][20];

cout<<"Enter numbers of rows:";

cin>>n;

cout<<"Enter numbers of column:";

cin>>m;

for(i=0;i<n;i++)

for(j=0;j<m;j++)

if(i==j)

X[i][j]=0;

else if(i<j)

X[i][j]=3*i+j;

else

X[i][j]=2*i+3*j;

43
for(i=0;i<n;i++)

for(j=0;j<m;j++)

cout<<X[i][j]<<"\t";

cout<<endl<<endl;

#include<iostream.h>

#include<string.h>

void main()

char Str1[50],Str2[50];

cout<<"Enter the first string :";

cin>>Str1;

cout<<"Enter the second string:";

cin>>Str2;

cout<<"The length of Str1 and Str2 respectivelly


are :"<<strlen(Str1)<<"characters"<<strlen(Str2)<<"character"<<endl;

cout<<"Comparison of Str1 and Str2 gives:"<<strcmp(Str1,Str2)<<"


"<<stricmp(Str1,Str2)<<" "<<endl;

//concanate of str1 and str2 gives str3=str1(new one)

cout<<"Concanate Str1 and Str2 gives Str3:="<<strcat(Str1,Str2)<<endl;


44
//str1=str3

cout<<"Convert all characters in Str3 in the


uppercase:"<<strupr(Str1)<<endl;

//str1=str3

cout<<"Display Str3:"<<Str1<<endl;

cout<<"Reverse of the Str1:"<<strrev(Str1)<<endl;

45

You might also like