100 Programs Part 2
100 Programs Part 2
Output:
PROGRAM 52:
Aim: Program to swap two values.
Input: #include<iostream.h>
int main()
{
void swap(int &,int &);
int a,b;
a=7;
b=4;
cout<<"\nThe original values are: \n";
cout<<"a= "<<a<<" ,b= "<<b<<"\n";
swap(a,b);
cout<<"\nThe values after swap() are: \n";
cout<<"a= "<<a<<" ,b= "<<b<<"\n";
return 0;
}
void swap(int &x,int &y)
{
int temp;
temp=x;
x=y;
y=temp;
cout<<"\nThe swapped values are: \n";
cout<<"a= "<<x<<" ,b="<<y<<"\n";
}
Output:
PROGRAM 53:
Aim: Program to convert distance in feet or inches using a call by reference method.
Input: #include<iostream.h>
#include<process.h>
int main()
{
void convert(float &,char &,char);
float distance;
char choice,type='F';
cout<<"\nEnter distance in feet: ";
cin>>distance;
cout<<"\nYou want distance in feets or inches ?(F/I):\n";
cin>>choice;
switch(choice)
{
case'F':convert(distance,type,'F');
break;
case'I':convert(distance,type,'I');
break;
default:cout<<"\nYou have entered a wrong choice!!!\n";
exit(0);
}
cout<<"\nDistance= "<<distance<<""<<type<<"\n";
return 0;
}
void convert(float &d,char &t,char ch)
{
switch(ch)
{
case'F':if(t=='I')
{
d=d/12;
t='F';
}
break;
P.T.O.
case'I':if(t=='F')
{
d=d*12;
t='I';
}
break;
}
return ;
}
Output 1:
Output 2;
PROGRAM 54:
Aim: Program to check whether a given character is contained in a string or not and find its
position.
Input: #include<iostream.h>
int main()
{
int findpos(char s[],char c);
char string[80],ch;
int y=0;
cout<<"Enter main string:\n";
cin.getline(string,80);
cout<<"\nEnter charachter to be searched for:\n";
cin.get(ch);
y=findpos(string,ch);
if(y==-1)
{
cout<<"\nSorry! character is not in the string\n";
}
return 0;
}
int findpos(char s[],char c)
{
int flag=-1;
for(int i=0;s[i]!='\0';i++)
{
if(s[i]==c)
{
flag=0;
cout<<"\nThe character is in the string at position "
<<i+1<<endl;
}
}
return 0;
}
Output 1:
Output 2:
PROGRAM 53:
Aim: Program to read an alphabet and display its next character in the ASCII list.
Input: #include<iostream.h>
int main()
{
char ch,nxt;
cout<<"Enter any character:";
ch=getchar();
nxt=ch+1;
cout<<"The next character is:";
putchar(nxt);
cout<<"\n";
return 0;
}
Output:
PROGRAM 55:
Aim: Program to count number of spaces in a string.
Input: #include<iostream.h>
#include<stdio.h>
int main()
{
char s[80];
int i,count=0;
cout<<"Enter any string(max. 80 chars):";
gets(s);
for(i=0;s[i]!='\0';i++)
if(s[i]==' ')
count++;
cout<<"Number of spaces in the given string are: "<<count<<endl;
return 0;
}
Output:
PROGRAM 55:
Aim: Program to count number of lowercase characters entered.
Input: #include<iostream.h>
int main()
{
int c=0;
const char ent='\n';
char ch;
cout<<"Enter charcter\n";
cin.get(ch);
while(ch!=ent)
{
if(ch>='a'&&ch<='z')
{
c++;
cout.put(ch);
}
cin.get(ch);
}
cout<<"\nThe number of charcter = "<<c<<endl;
return 0;
}
Output:
PROGRAM 56:
Aim: Program to compare lengths of two strings.
Input: #include<iostream.h>
#include<string.h>
int main()
{
char string1[50],string2[50];
cout<<"Enter strings\n";
cin.getline(string1,50);
cin.getline(string2,50);
int i,j;
for(i=0;string1[i]!='\0';i++);
for(j=0;string2[j]!='\0';j++);
if(i==j)
{
cout<<"Both strings contain equal number of charcters.\n";
}
else
{
cout<<"The given strings have different number of character.\n";
}
return 0;
}
Output:
PROGRAM 57:
Aim: Program to read marks of 5 students and store theme under an array.
Input: #include<iostream.h>
int main()
{
const int size=5;
float marks[size];
for(int i=0;i<size;i++)
{
cout<<"Enter marks of student "<<i+1<<endl;
cin>>marks[i];
}
cout<<"\n";
for(int i=0;i<size;i++)
{
cout<<"Marks["<<i<<"]="<<marks[i]<<endl;
}
return 0;
}
Output:
PROGRAM 58:
Aim: Program to read price of 20 items in array and then display sum of all price, product of
all the price and average of them.
Input: #include<iostream.h>
int main()
{
double Price[5],sum,avg,prod;
cout<<"Enter the price of product :\n";
sum=avg=0;
prod=1;
for(int i=0;i<5;++i)
{
cin>>Price[i];
sum+=Price[i];
prod*=Price[i];
}
avg=sum/5;
cout<<"Sum of all price = "<<sum<<endl;
cout<<"Product of all price = "<<prod<<endl;
cout<<"Average of all price = "<<avg<<endl;
return 0;
}
Output:
PROGRAM 59:
Aim: Program to accept sales of each day of the month and print the total sales and average
sales of the month.
Input: #include<iostream.h>
int main()
{
const int size=3;
float sales[size],avg=0,total=0;
for(int i=0;i<size;++i)
{
cout<<"Enter sales made on day "<<i+1<<":";
cin>>sales[i];
total+=sales[i];
}
avg=total/size;
cout<<"\nTotal sales = "<<total;
cout<<"\nAverage sales = "<<avg<<endl;
return 0;
}
Output:
PROGRAM 60:
Aim: Program to count the number of employees earning more than Rs. 1 lakh per annum.
The monthly salaries of 100 employees are given.
Input: #include<iostream.h>
int main()
{
const int size=5;
float Sal[size],an_sal;
int count=0;
for(int i=0;i<size;i++)
{
cout<<"Enter monthly salary for employee "<<i+1<<":";
cin>>Sal[i];
}
for(int i=0;i<size;i++)
{
an_sal=Sal[i]*12;
if(an_sal>100000)
count++;
}
cout<<count<<" employees out of "<<size
<<" employees are earing more than Rs. 1 Lakh per annum."<<endl;
return 0;
}
Output:
PROGRAM 61:
Aim: Program to search for a specific element in a 1-D array (Linear Search)
Input: #include<iostream.h>
int main()
{
int A[20],size,i,flag=0,num,pos;
cout<<"\nEnter the number of elements in the array:";
cin>>size;
cout<<"\nEnter the element of array(in ascending order):";
for(i=0;i<size;i++)
cin>>A[i];
cout<<"\nEnter the element to be searched for:\n";
cin>>num;
for(i=0;i<size;i++)
if(A[i]==num)
{
flag=1;
pos=i;
break;
}
if(flag==0)
{
cout<<"\nElement not found";
}
else
{
cout<<"\nElement found at position "<<(pos+1)<<endl;;
}
return 0;
}
Output:
PROGRAM 62:
Aim: Program to check if a string is palindrome or not.
Input: #include<iostream.h>
int main()
{
char string[80],len;
cout<<"Enter string(max. 79 character):";
cin.getline(string,80);
for(len=0;string[len]!='\0';len++);
int i,j,flag=1;
for(i=0,j=len-1;i<len/2;i++,j--)
{
if(string[i]!=string[j])
{
flag=0;
break;
}
}
if(flag!=0)
{
cout<<"It is a palindrome. \n";
}
else
{
cout<<"It is not a palindrome. \n";
}
return 0;
}
Output 1:
Output 2:
PROGRAM 63:
Aim: Program to replace every space in a string with a hyphen
Input: #include<iostream.h>
#include<string.h>
int main()
{
char s[80];
cout<<"Enter string(max. 79 character)\n";
cin.getline(s,80);
int x1=strlen(s);
for(int i=0;s[i]!='\0';i++)
{
if(s[i]==' ')
{
s[i]='-';
}
}
cout<<"The changed string is\n";
cout.write(s,x1);
cout<<"\n";
return 0;
}
Output:
PROGRAM 64:
Aim: Program to find number of vowels in a given line of text.
Input: #include<iostream.h>
#include<stdio.h>
int main()
{
char line[80];
int vow_ctr=0;
cout<<"Enter the line:\n";
gets(line);
for(int i=0; line[i]!='\0';i++)
{
switch(line[i])
{
case'a':
case'A':
case'e':
case'E':
case'i':
case'I':
case'o':
case'O':
case'u':
case'U':++vow_ctr;
}
}
cout<<"The total number of vawels in the given line is "<<vow_ctr<<endl;
return 0;
}
Output:
PROGRAM 65:
Aim: Program to reverse words of a string individually e.g., if you enter: I love C++, it
should display:
I evol ++C
Input: #include<iostream.h>
#include<stdio.h>
#include<string.h>
int main()
{
int i,k=0;
char str[80],word[80];
cout<<"Enter any string(max. 80 chars)"<<endl;
gets(str);
strcat(str," ");
for(i=0;str[i]!='\0';i++)
{
if(str[i]!=' ')
{
word[k]=str[i];
k=k+1;
}
else
{
while(k>0)
{
cout<<word[--k];
}
cout<<str[i];
}
}
cout<<endl;
return 0;
}
Output:
PROGRAM 66:
Aim: Program to convert a string to proper case i.e., to capitalize first letter of each word of
the string e.g., if the string is: mira rehaan augustine, it should output it as:
Mira Rehaan Augustine
Input: #include<iostream.h>
#include<stdio.h>
#include<ctype.h>
int main()
{
char str[80];
int i;
cout<<"Enter any string(max. 80 chars): ";
gets(str);
str[0]=toupper(str[0]);
for(i=0;str[i]!='\0';i++)
{
if(str[i]==' ')
{
str[i+1]=toupper(str[i+1]);
}
}
cout<<"\n Updated string is: "<<str<<endl;
return 0;
}
Output:
PROGRAM 67:
Aim: Program to read sales of 2 salesmen in 12 months and to print total sales made by each
salesman.
Input: #include<iostream.h>
int main()
{
int sales[5][12];
int i,j;
unsigned long total;
for(i=0;i<5;i++)
{
total=0;
cout<<"\nEnter sales for salesman "<<i+1<<endl;
for(j=0;j<12;j++)
{
cout<<"Month "<<j+1<<" ";
cin>>sales[i][j];
total+=sales[i][j];
}
cout<<"\n";
cout<<"Total sales of salesman "<<i+1<<" =Rs."<<total<<"\n";
}
return 0;
}
Output:
PROGRAM 68:
Aim: Program to calculate grades of 4 students from 3 test scores.
Input: #include<iostream.h>
int main()
{
float marks[4][3],sum,avg;
char grade[4];
int i,j;
for(i=0;i<4;i++)
{
sum=avg=0;
cout<<"Enter 3 scores of students "<<i+1<<" :\n";
for(j=0;j<3;j++)
{
cin>>marks[i][j];
sum+=marks[i][j];
}
avg=sum/3;
if(avg<45.0)
{
grade[i]='D';
}
else if(avg<60.0)
{
grade[i]='C';
}
else if(avg<75.0)
{
grade[i]='B';
}
else
{
grade[i]='A';
}
}
for(i=0;i<4;i++)
{
cout<<"Student "<<i+1<<"\tTotal Marks ="
<<marks[i][0]+marks[i][1]+marks[i][2]
<<"\tGrade= "<<grade[i]<<"\n";
}
return 0;
}
Output:
PROGRAM 69:
Aim: Program to read and check the equality of two matrices.
Input: #include<iostream.h>
int main()
{
int A[3][3],B[3][3],r,c;
cout<<"Enter first matrix row wise\n";
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{
cin>>A[r][c];
}
}
cout<<"Enter second matrix row wise\n";
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{
cin>>B[r][c];
}
}
int flag=0;
for(r=0;r<3;r++)
{
for(c=0;c<3;c++)
{
if(A[r][c]!=B[r][c])
{
flag=1;
break;
}
}
if(flag==1)
{
break;
}
}
if(flag!=0)
{
cout<<"Matrices are unequal\n";
}
else
{
cout<<"Matrices are equal\n";
}
return 0;
}
Output 1:
Output 2:
PROGRAM 70:
Aim: Program to reverse all the strings stored in an array.
Input: #include<iostream.h>
#include<string.h>
int main()
{
char string[3][31],ch;
int i,j,len,k;
cout<<"Enter 3 strings\n";
for(i=0;i<3;i++)
{
cin.getline(string[i],31);
}
cout<<"\nThe list of original strings follows:";
for(i=0;i<3;i++)
{
cout<<"\n"<<string[i];
}
for(i=0;i<3;i++)
{
len=strlen(string[i]);
for(j=0,k=len-1;j<len/2;j++,k--)
{
ch=string[i][j];
string[i][j]=string[i][k];
string[i][k]=ch;
}
}
cout<<"\nThe list of reversed strings follows: ";
for(i=0;i<3;i++)
{
cout<<"\n"<<string[i];
}
cout<<"\n";
return 0;
}
Output:
PROGRAM 71:
Aim: Program to print the largest element of an array (using a function).
Input: #include<iostream.h>
int main()
{
float large(float arr[],int n);
char ch;
int i;
float amount[50],big;
for(i=0;i<50;i++)
{
cout<<"\nEnter element no "<<i+1<<"\n";
cin>>amount[i];
cout<<"\nWant to enter more?(y/n)\n";
cin>>ch;
if(ch!='y')
{
break;
}
}
if(i<50)
{
i++;
}
big=large(amount,i);
cout<<"\nThe largest element of the array is : "<<big<<"\n";
return 0;
}
float large(float arr[],int n)
{
float max= arr[0];
{
for(int j=1;j<n;j++)
if(arr[j]>max)
{
max=arr[j];
}
}
return (max);
}
Output:
PROGRAM 72:
Aim: Write a C++ program that reads two strings and appends the first string to the second.
For example, if the first string is entered as Good and second string as Morning, the program
should print MorningGood. Use string library header.
Input: #include<iostream.h>
#include<string.h>
int main()
{
char str1[25],str2[50];
cout<<"\nEnter first string(max 25 character)\n";
cin.getline(str1,25);
cout<<"\nEnter second string(max 25 character)\n";
cin.getline(str2,25);
strcat(str2,str1);
int len=strlen(str2);
cout.write(str2,len);
cout<<"\n";
return 0;
}
Output:
PROGRAM 73:
Aim: Write a C++ program that reads two strings and copies the smaller string into the bigger
string. Use functions from string library header.
Input: #include<iostream.h>
#include<string.h>
int main()
{
char str1[25],str2[25];
int len1,len2;
cout<<"Enter first string:\n";
cin.getline(str1,25);
cout<<"\nEnter second string:\n";
cin.getline(str2,25);
if(strlen(str1)>strlen(str2))
{
strcpy(str1,str2);
cout<<"\nSecond string is copied onto first string\n";
len1=strlen(str1);
cout.write(str1,len1);
}
else if(strlen(str2)>strlen(str1))
{
strcpy(str2,str1);
cout<<"\nFirst string is copied onto second string\n";
len2=strlen(str2);
cout.write(str2,len2);
}
else if(strlen(str1)==strlen(str2))
{
cout<<"\nStrings are of equal length.\n";
len1=strlen(str1);
cout<<"\nString1 is:";
cout.write(str1,len1);
cout<<"\nString2 is:";
len2=strlen(str2);
cout.write(str2,len2);
}
cout<<"\n";
return 0;
}
Output:
PROGRAM 74:
Aim: Write a C++ program to find the largest and smallest elements in a vector.
Input: #include<iostream.h>
int main()
{
int v[50],large,small;
int i,n;
cout<<"Enter how many elements(max 50)?\n";
cin>>n;
cout<<"Enter values in the vector\n";
for(i=0;i<n;i++)
{
cin>>v[i];
}
large=v[1];
small=v[1];
for(i=0;i<n;i++)
{
if(v[i]>large)
{
large=v[i];
}
else if(v[i]<small)
{
small=v[i];
}
}
cout<<"\nLargest element = "<<large;
cout<<"\nSmallest element = "<<small<<endl;
return 0;
}
Output:
PROGRAM 75:
Aim: Program to add two matrices.
Input: #include<iostream.h>
#include<process.h>
int main()
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q;
cin>>p>>q;
if((m==p)&&(n==q))
else
exit(0);
cout<<"\nInput matrix-A\n";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"\nMATRIX-A:";
for(i=0;i<m;i++)
cout<<"\n";
for(j=0;j<n;j++)
cout<<" "<<a[i][j];
cout<<"\nInput matrix-B\n";
for(i=0;i<p;i++)
for(j=0;j<q;j++)
{
cin>>b[i][j];
cout<<"\nMATRIX-B:";
for(i=0;i<p;i++)
cout<<"\n";
for(j=0;j<q;j++)
cout<<" "<<b[i][j];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]+b[i][j];
for(i=0;i<m;i++)
cout<<"\n";
for(j=0;j<n;j++)
cout<<" "<<c[i][j];
cout<<"\n";
return 0;
Output:
PROGRAM 76:
Aim: Write a C++ program to find the largest and smallest elements in a vector.
Input: #include<iostream.h>
#include<process.h>
int main()
int a[10][10],b[10][10],c[10][10];
int i,j,m,n,p,q;
cin>>p>>q;
if((m==p)&&(n==q))
else
exit(0);
cout<<"\nInput matrix-A\n";
for(i=0;i<m;i++)
for(j=0;j<n;j++)
cin>>a[i][j];
cout<<"\nMATRIX-A:";
for(i=0;i<m;i++)
cout<<"\n";
for(j=0;j<n;j++)
cout<<" "<<a[i][j];
cout<<"\nInput matrix-B\n";
for(i=0;i<p;i++)
for(j=0;j<q;j++)
{
cin>>b[i][j];
cout<<"\nMATRIX-B:";
for(i=0;i<p;i++)
cout<<"\n";
for(j=0;j<q;j++)
cout<<" "<<b[i][j];
for(i=0;i<m;i++)
for(j=0;j<n;j++)
c[i][j]=a[i][j]-b[i][j];
for(i=0;i<m;i++)
cout<<"\n";
for(j=0;j<n;j++)
cout<<" "<<c[i][j];
cout<<”\n”;
return 0;
}
Output:
PROGRAM 77:
Aim: Program to find row sum and column sum of a matrix.
Input: #include<iostream.h>
int main()
int A[10][10],i,j,r[10],c[10],row,col;
cin>>row>>col;
for(j=0;j<col;++j)
cout<<A[i][j];
for(i=0;i<row;++i)
cout<<"\n";
for(j=0;j<col;++j)
cout<<A[i][j]<<" ";
for(i=0;i<row;i++)
r[i]=0;
for(j=0;j<col;j++)
r[i]+=A[i][j];
for(j=0;j<col;j++)
c[j]=0;
for(i=0;i<row;i++)
c[j]+=A[i][j];
for(i=0;i<row;i++)
{
for(i=0;i<col;i++)
cout<<"\n";
return 0;
Output:
PROGRAM 78:
Aim: Write a program to read two numbers and print their quotient and remainder.
Input: #include<iostream.h>
int main()
{
int a,b,q,r;
cout<<"Enter two numbers\n";
cin>>a>>b;
if(a>b)
{
q=a/b;
r=a%b;
cout<<"Quotient of "<<a<<" and "<<b<<" is "<<q<<endl;
cout<<"Remainder of "<<a<<" and "<<b<<" is "<<r<<endl;
}
else
{
q=b/a;
r=b%a;
cout<<"Quotient of "<<a<<" and "<<b<<" is "<<q<<endl;
cout<<"Remainder of "<<a<<" and "<<b<<" is "<<r<<endl;
}
return 0;
}
Output 1:
Output 2:
PROGRAM 79:
Aim: Program to transpose a matrix.
Input: #include<iostream.h>
int main()
{
int a[20][20],b[20][20],i,j,m,n;
cout<<"Input row & column of matrix-A\n";
cin>>m>>n;
cout<<"\nInput matrix-A\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>a[i][j];
}
cout<<"\nMATRIX-A:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<m;j++)
{
cout<<" "<<a[i][j]<<endl;
}
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
cout<<" "<<b[i][j];
}
cout<<"\n";
}
return 0;
}
Output:
PROGRAM 80:
Aim: Program to find a substring of given string.
Input: #include<iostream.h>
#include<string.h>
#include<process.h>
int main()
{
char mainstr[50],substr[50];
int count,pos,i,j,len,num,x1;
cout<<"\nEnter the main string(max 49 characters)\n";
cin.getline(mainstr,50);
len=strlen(mainstr);
cout<<"\nEnter starting position of substring\n";
cin>>pos;
if(pos>len)
{
cout<<"\nStarting position exceeds the total "
<<"length of the string!!!";
exit(0);
}
cout<<"\nThe number of characters in substring?\n";
cin>>count;
if(pos<=0)
{
cout<<"\nExtracted string is EMPTY!!!\n";
exit(0);
}
else if(((pos+count)-1)>len)
{
cout<<"\nString to be extracted exceeds length\n";
num=(len-pos);
}
else
{
num=count;
cout<<"\nNum "<<num;
}
j=0;
for(i=--pos;i<=(pos+num);i++)
{
substr[j]=mainstr[i];
j++;
}
cout<<"\nSubstring is\n";
cout.write(substr,j);
cout<<"\n";
return 0;
}
Output:
PROGRAM 81:
Aim: Program to print largest element of an array using a function.
Input: #include<iostream.h>
int Large(int[],int);
int main()
{
int A[50],i,n,MAX;
cout<<"\n Enter the size of the array:";
cin>>n;
cout<<"\n Enter the elements of the array:\n";
for(i=0;i<n;i++)
{
cin>>A[i];
}
MAX= Large(A,n);
cout<<"\n Largest element of the given array is:"<<MAX<<endl;
return 0;
}
Output:
PROGRAM 82:
Aim: Program to multiply two matrices.
Input: #include<iostream.h>
#include<process.h>
int main()
{
int A[3][3],B[3][3],C[3][3],m,n,p,q,k,i,j;
cout<<"\nEnter the rows and columns of Matrix A:";
cin>>m>>n;
cout<<"\nEnter the rows and columns of matrix B:";
cin>>p>>q;
if(n==p)
{
cout<<"\nEnter the elements of matrix A:\n";
for(i=0;i<m;i++)
{
for(j=0;j<n;j++)
cin>>A[i][j];
}
cout<<"\nEnter the element of matrix B:\n";
for(i=0;i<p;i++)
{
for(j=0;j<q;j++)
cin>>B[i][j];
}
cout<<"\nMatrix A is : ";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<n;j++)
cout<<A[i][j]<<" ";
}
cout<<"\nMatrix B is : ";
for(i=0;i<p;i++)
{
cout<<"\n";
for(j=0;j<q;j++)
cout<<B[i][j]<<" ";
}
cout<<"Product of two matrices:";
for(i=0;i<m;i++)
{
cout<<"\n";
for(j=0;j<q;j++)
{
C[i][j]=0;
for(k=0;k<n;k++)
C[i][j]=C[i][j]+A[i][k]*B[k][j];
cout<<C[i][j]<<" ";
}
}
}
else
cout<<"\nMatrix are not compatiable for multiplication.";
return 0;
}
Output:
PROGRAM 83:
Aim: Write a program to find area of a triangle.
Input: #include<iostream.h>
int main()
{
int b,h,a;
cout<<"Enter base of a triangle:";
cin>>b;
cout<<"Enter hight of a triangle:";
cin>>h;
a=0.5*b*h;
cout<<"Area of triangle = "<<a<<endl;
return 0;
}
Output:
PROGRAM 84:
Aim: Write a program to compute simple interest and compound interest.
Input: #include<iostream.h>
#include<math.h>
int main()
{
float p,t,r,si,ci,amt1,amt2;
cout<<"Enter the Principal amount : ";
cin>>p;
cout<<"Enter the Time period : ";
cin>>t;
cout<<"Enter the Rate of interest : ";
cin>>r;
si=p*t*r/100;
amt1=p+si;
amt2=p*pow((1+r/100),t);
ci=amt2-p;
cout<<"Simple interest = "<<si<<" Total Amt = "<<amt1<<endl;
cout<<"compound interest = "<<ci<<" Total Amt = "<<amt2<<endl;
return 0;
}
Output: