#include"iostream.h" #include"conio.h" #include"stdio.h" void findlength() { char str[30]; int l=0; cout<<"\n Enter the string (size < =30) "; gets(str); while(str[l]!='\0') { l++; } cout<<"\n Length Of the given String is: "<< l<< endl; } void compare() { char str1[30], str2[30]; int l1=0,l2=0,i=0,flag=0; cout<<"\n Enter the string1 (size< =30) "; gets(str1); while(str1[l1]!='\0') { l1++; } cout<<"\n Enter the string2 (size< =30) "; gets(str2); while(str2[l2]!='\0') { l2++; } if(l2!=l1) { cout<<"\n Strings are not Equal "; } else { for(i=0;i< l1; i++ ) { if(str1[i]!=str2[i]) { flag=1; break; } } if(flag==1) { cout<< "\n Strings are not Equal "; } else { cout<< "\n Strings are Equal "; } } } void concat() { char str1[30], str2[30]; int l1=0,l2=0,i=0,flag=0; cout<<"\n Enter the string1 (size< =30 ) "; gets(str1); while(str1[l1]!='\0') { l1++; } cout<<"\n Enter the string2 (size< =30 ) "; gets(str2); while(str2[l2]!='\0') { l2++; } for(i=0;i < l2;i++) { str1[l1+i]=str2[i]; } str1[l1+l2]='\0'; cout<<"\n The concatenated String is: "; puts(str1); } void main() { clrscr(); cout<<" Enter your choice \n \t1.Find length of string\n\t" "2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n"; char ch; cin>> ch; do { if(ch=='1') findlength(); if(ch=='2') compare(); if(ch=='3') concat(); cout<< "Enter your choice \n \t1.Find length of string\n\t" "2.Compare two Strings \n\t3.Concatenate two strings\n\t4.Exit \n"; cin>> ch; }while(ch!='4'); getch(); }

## Tuesday, 20 December 2011

### C and C++ program to perform various operations on strings

## Monday, 19 December 2011

### C and C++ program Program to convert the lowercase letter into uppercase and to increment an integer

# include "iostream.h" # include "conio.h" char convert(char ch) { return(ch -32); } int increment(int n) { return(++n); } void main() { int num; char ch1; clrscr(); cout<< "Enter a character in lower case "; cin >> ch1; cout << "Enter an integer "; cin >> num; cout<< "\nUpper Case Aplhabet is => " << convert(ch1); cout<< "\nIncremented Integer is => " << increment(num); }

### C and C++ program to find the minimum of two numbers using function overloading

# include "iostream.h" # include "conio.h" int min(int a, int b) { if (a< b ) return(a); else return(b); } char min(char a, char b) { if (a< b ) return(a); else return(b); } double min(double a, double b) { if (a< b ) return(a); else return(b); } void main() { int n, n1; char ch, ch1; double d, d1; clrscr(); cout << "Enter two integers "; cin >> n >> n1; cout << "Enter two characters "; cin >> ch >> ch1; cout << "Enter two double precision quantity "; cin >> d >> d1; cout << "\nMinimum of two integer "<< min(n,n1); cout << "\nMinimum of two characters "<< min(ch,ch1); cout << "\nMinimum of two double precision quantity "<< min(d,d1); }

### C and C++ program to calculate the square root of different numbers

# include"iostream.h" # include"math.h" int sroot(int n) { return(sqrt(n)); } long int sroot(long int n) { return(sqrt(n)); } double sroot(double n) { return(sqrt(n)); } void main() { int num; long int num1; double num2; cout << "Enter the value of num "; cin >> num; cout << "Enter the value of num1"; cin >> num1; cout << "Enter the value of num2 "; cin >> num2; cout << "\nSquare root of int is " << sroot(num); cout << "\nSquare root of long int is " << sroot(num1); cout << "\nSquare root of double is " << sroot(num2); }

### C and C++ program to calculate area of square and area of rectangle using function

#include "iostream.h" int area(int s) { return(s * s); } float area(int b , int h) { return(0.5 * b * h); } main() { cout << area(5) << endl; cout << area(4,3) << endl; cout << area(6, area(3)) << endl; return 0; }

### C and C++ program to calculate the area of rectangle, area of triangle, and area of circle.

#include "iostream.h" #include "conio.h" #include "iomanip.h" #include "math.h" float area(float a, float b , float c); float area(float l, float w); float area(float r); void main() { char ch; float len, wid, n1, n2, n3, ar; float radius; int choice1; clrscr(); cout << "\n1. For area of triangle "; cout << "\n2. For area of rectangle "; cout << "\n3. For area of circle "; cout << "\nEnter choice : "; cin >> choice1; if (choice1 == 1) { cout << "\nEnter the three sides of triangle : "; cin >> n1 >> n2 >> n3; ar = area(n1, n2, n3); cout << "\nArea of triangle is : " << ar; } if (choice1 == 2) { cout << "\nEnter the length : "; cin >> len; cout << "\nEnter the width : "; cin >> wid; cout << "\nArea of rectangle is: " << area(len, wid); } if (choice1 == 3) { cout << "\nEnter the radius : "; cin >> radius; cout << "\nArea of circle : " << area(radius); } } float area(float a, float b , float c) { float s; float a1; s = (a + b + c) / 2; a1 = sqrt(s * (s-a) * (s-b) * (s-c)); return(a1); } float area(float l, float w) { return(l*w); } float area( float radius) { return(3.14 * radius * radius); }Source: www.LearnCandCpp.com

### C and C++ program to calculate area of rectangle and triangle using function overloading

#include "iostream.h" #include "conio.h" #include "iomanip.h" #includefloat area(float a, float b , float c); float area(float l, float w); float area(float r); void main() { char ch; float len, wid, n1, n2, n3, ar; float radius; int choice1; clrscr(); cout << "\n1. For area of triangle "; cout << "\n2. For area of rectangle "; cout << "\n3. For area of circle "; cin >> choice1; if (choice1 == 1) { cout << "\nEnter the three sides of triangle : "; cin >> n1 >> n2 >> n3; ar = area(n1, n2, n3); cout << "\nArea of triangle is: " << ar; } if (choice1 == 2) { cout << "\nEnter the length "; cin >> len; cout << "\nEnter the width: "; cin >> wid; cout << "\nArea of rectangle is: " << area(len, wid); } if (choice1 == 3) { cout << "\nEnter the radius "; cin >> radius; cout << "\n Area of circle " << area(radius); } } Source: www.LearnCandCpp.com