C++ Program to do Addition,subtraction and multiplication of two numbers using function

#include<iostream.h> #include<conio.h> int res; void main() { clrscr(); int sum(int,int); int sub(int,int); int mul(int,int); int a,b,m,su,s; cout<<“Enter two numbers:”; cin>>a>>b; s=sum(a,b); su=sub(a,b); m=mul(a,b); cout<<“Sum:”<<s<<“nSubtraction:”<<su<<“nMultiplication:”<<m; getch(); } sum(int a,int b) { res=a+b; return(res); } sub(int a,int b) { res=a-b; return(res); } mul(int a,int b) { res=a*b; return(res); }

C++ Program to do arithmetic operations according to user choice using switch case

include<iostream.h> #include<conio.h> void main() {       clrscr(); int a,b; char c; cout<<“Enter any expression(ex:3*7):”; cin>>a>>c>>b; switch(c) { case’+’: cout<<“nResult:”<<a+b; break; case’-‘: cout<<“nResult:”<<a-b; break; case’*’: cout<<“nResult:”<<a*b; break; case’/’: cout<<“nResult:”<<a/b; break; case’%’:  cout<<“nResult:”<<a%b; break; } getch(); }

C++ Program to convert first letter of each word of a string to uppercase and other to lowercase

#include<iostream.h> #include<conio.h> #include<stdio.h> #include<ctype.h> void main() { clrscr(); int i; char a[30]; cout<<“Enter a string:”; gets(a); for(i=0;a[i]!=’’;++i) { if(i==0) { if(islower(a[i])) a[i]=toupper(a[i]); } else { if(a[i]!=’ ‘) { if(isupper(a[i])) a[i]=tolower(a[i]); } else { i++; if(islower(a[i])) a[i]=toupper(a[i]); } } } cout<<“nnNew string is: “<<a; getch(); }

C++ Program to Find Highest and Lowest Element of a Matrix

Here you will get a C++ program to find highest or largest and lowest or smallest element of a matrix. #include<iostream> using namespace std; int main() { int m,n,a[10][10],i,j,high,low; cout<<“Enter no. of rows and coloumns:”; cin>>m>>n; cout<<“\nEnter matrix:\n”; for(i=0;i<m;++i) { for(j=0;j<n;++j) cin>>a[i][j]; } high=a[0][0]; low=a[0][0]; for(i=0;i<m;++i) { for(j=0;j<n;++j) { if(a[i][j]>high) high=a[i][j]; else if(a[i][j]<low) low=a[i][j]; } …

C++ Program to Find Highest and Lowest Element of a Matrix Read More »

C++ Program to Concatenate Two Strings

Here you will get C++ program to concatenate two string without using library function. Below program will read two strings from user and then concatenate them to form third string. #include<iostream> using namespace std; int main() { char str1[30],str2[30],str3[60]; int i,j; cout<<“Enter first string:”; gets(str1); cout<<“\nEnter second string:”; gets(str2); for(i=0;str1[i]!=’\0′;++i) str3[i]=str1[i]; for(j=0;str2[j]!=’\0′;++j) str3[i+j]=str2[j]; str3[i+j]=’\0′; cout<<“\nThe …

C++ Program to Concatenate Two Strings Read More »

C++ Program to Reverse All the Strings Stored in an Array

Here you will get C++ program to reverse all the strings stored in an array. #include<iostream> #include<string.h> #include<stdio.h> using namespace std; int main() { char a[3][50]; int i,j,k,len; cout<<“Enter 3 strings:\n”; for(i=0;i<3;i++) { gets(a[i]); } cout<<“\nThe list of orignal strings:\n” ; for(i=0;i<3;i++) { cout<<a[i]<<“\n”; } cout<<“\nThe list of changed strings:\n”; for(i=0;i<3;i++) { len=strlen(a[i]); for(j=0,k=len-1;k>=0;j++,k–) { …

C++ Program to Reverse All the Strings Stored in an Array Read More »