2.
PROGRAM TO FIND THE ROOTS OF A QUADRATIC EQUATION
SOURCE CODE:
#include <iostream>
#include <math.h>
using namespace std;
int main()
{ float r1,r2;
int a,b,c,d;
cout<<"enter the coefficient of x2"<<endl;
cin>>a;
cout<<"enter the coefficient of x"<<endl;
cin>>b;
cout<<"enter the constant"<<endl;
cin>>c;
d=(b*b)-(4*a*c);
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
cout<<"The roots are "<<r1<<" and "<<r2<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
3. PROGRAM TO FIND THE FACTORIAL OF THE NUMBER
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
int a,n;
cout<<"enter the number "<<endl;
cin>>n;
for(a=n-1;a>=1;a--){
n=n*a;
cout<<n;
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
4. PROGRAM TO FIND IF THE GIVEN NUMBER IS AN
ARMSTRONG NUMBER
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
{ int num,a,rem,sum=0;
cout<<"enter the armstrong number"<<endl;
cin>>a;
num=a;
while(a=0)
{ rem=a%10;
sum=rem*rem*rem+sum;
a/=10;
if(sum==num){
cout<<"yes it is an armstrong number"<<endl;
else
cout<<"no it is not armstrong number"<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
5. PROGRAM TO FIND IF GIVEN NUMBER IS PALINDROME OR
NOT
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
{ int b,a,rem,rev=0;
cout<<"enter the number below 10 digits"<<endl;
cin>>a;
b=a;
do
{ rem=a%10;
rev=(rev*10)+rem;
a=a/10; }
while(a!=0);
if(b==rev)
{ cout<<"yes it is an palindrome"<<endl; }
else
{ cout<<"no it is not palindrome"<<endl; }
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
6.PROGRAM TO CONVERT A DECIMAL NUMBER TO BINARY
NUMBER
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
long dec,rem,i=1,sum=0;
cout<<"enter the decimal number to be convert"<<endl;
cin>>dec;
do
rem=dec%2;
sum=sum+(i*rem);
dec=dec/2;
i=i*10;
while(dec>0);
cout<<"the binary of the given number is "<<sum<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
7.PROGRAM TO FIND AREA OF SHAPES
SOURCE CODE:
#include <iostream>
#include <math.h>
using namespace std;
int main()
float area;
int n,a,b,c,d;
cout<<"Enter your choice"<<endl;
cout<<"1.Area of circle"<<endl;
cout<<"2.Area of square"<<endl;
cout<<"3.Area of rectangle"<<endl;
cout<<"4.Area of triangle"<<endl;
cin>>n;
switch(n)
{
case 1:
cout<<"Enter the radius"<<endl;
cin>>a;
area=3.14*a*a;
cout<<"Area: "<<area<<endl;
break;
case 2:
cout<<"Enter the side"<<endl;
cin>>a;
area=a*a;
cout<<"Area: "<<area<<endl;
break;
case 3:
cout<<"Enter the length"<<endl;
cin>>a;
cout<<"Enter the breadth"<<endl;
cin>>b;
area=a*b;
cout<<"Area: "<<area<<endl;
break;
case 4:
cout<<"Enter side 1"<<endl;
cin>>a;
cout<<"Enter side 2"<<endl;
cin>>b;
cout<<"Enter side 3"<<endl;
cin>>c;
d=(a+b+c)/2;
area=sqrt(d*(d-a)*(d-b)*(d-c));
cout<<"Area: "<<area<<endl;
break;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
8.PROGRAM TO CALCULATE SPACES IN A STRING
SOURCE CODE:
#include <iostream>
#include <string.h>
using namespace std;
int main()
int sum = 0;
char a[50];
cout<<"Enter the string"<<endl;
cin.getline(a,50);
int d = strlen(a);
for(int i=0;i<d;i++){
if(a[i]== ' '){
sum+=1;
cout<<"The number of spaces: "<<sum<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
9. PROGRAM CONVERT STRING FORM TO LOWER CASE TO
UPPER CASE
SOURCE CODE:
#include <iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
char a[50];
cout<<"enter the string"<<endl;
cin.getline(a,50);
cout<<"string in upper case "<<strupr(a)<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
10.PROGRAM TO APPEND TWO SEPERATE STRINGS
SOURCE CODE:
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int main()
char a[50], b[50];
cout<<"Enter the string 1:"<<endl;
gets(a);
cout<<"Enter the string 2:"<<endl;
gets(b);
cout<<"\n\nString after appending \n"<<strcat(a,b);
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
11. PROGRAM TO COMPARE TWO STRING AND COPY THE
SMALLER TO BIGGER
SOURCE CODE:
#include <iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int main()
{ char a[50],b[50];
int c,d;
cout<<"enter the string1"<<endl;
cin>>a;
cout<<"enter the string 2"<<endl;
cin>>b;
c=strlen(a);
d=strlen(b);
if(d>c)
strcpy(b,a);
cout<<"copied"<<endl;
else if(d<c)
{ strcpy(a,b);
cout<<"copied"<<a;
else
cout<<"both string are equal";
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
12. PROGRAM TO COMPARE AND CHECK WHICH STRING IS
BIGGER
SOURCE CODE:
#include <iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
int main()
{ char a[50],b[50];
int c,d;
cout<<"enter the string 1"<<endl;
gets(a);
cout<<"enter the string 2"<<endl;
gets(b);
c=strlen(a);
d=strlen(b);
if(c>d)
{ cout<<"string 1is bigger"<<endl; }
else if (d>c)
{ cout<<"string2 is bigger"<<endl;
else{
cout<<"both are equal "<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
13.PROGRAM TO PERFORM LINEAR SEARCH
SOURCE CODE :
#include <iostream>
using namespace std;
int main()
int a[50],n,item,s=0,x;
cout<<"---------------------Linear Search------------------------"<<endl;
cout<<"\n\n\nEnter the number of elements"<<endl;
cin>>n;
cout<<"Enter the elements"<<endl;
for(int i=0;i<n;i++){
cin>>a[i];
cout<<"Enter the number to search"<<endl;
cin>>item;
for(int i=0;i<n;i++){
if(a[i]==item){
x=i;
if(s==1){
cout<<"Data is found in location "<<x<<endl;
else{
cout<<"Data is not found"<<endl;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
14.PROGRAM TO CALCULATE TOTAL AVERAGE SALES IN A
MONTH
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
{
float a[100],s=0;
int n,i;
cout<<"\n-----total average sales----\n";
cout<<"enter the no of sales records="<<endl;
cin>>n;
cout<<"enter the record"<<endl;
for(i=1;i<=n;i++)
cin>> a[i];
s+= a[i];
cout<<"total average sale is "<<endl;
cout<<s/n;
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
15.PROGRAM TO FIND THE TRANSPOSE OF A MATRIX USING 2-
DIMENSIONAL ARRAYS
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
int a[2][2];
cout<<"Enter the elements of the matrix"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Enter element "<<i<<" "<<j<<endl;
cin>>a[i][j];
cout<<"The transpose of the matrix is:"<<endl<<endl<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<a[j][i]<<" ";
cout<<endl<<endl;
}
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
16. PROGRAM TO ADD TWO MATICES AND PRINT THIR RESULT:
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
int a[2][2], b[2][2];
cout<<"Enter the elements of first matrix"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Enter element "<<i<<j<<endl;
cin>>a[i][j];
cout<<"Enter the elements of second matrix"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Enter element "<<i<<j<<endl;
cin>>b[i][j];
}
}
cout<<endl<<endl<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<a[i][j]+b[i][j]<<" ";
cout<<endl<<endl;
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
17. PROGRAM TO CHECK THE EQUALITY OF MATRICES
SOURCE CODE:
#include <iostream>
using namespace std;
int main()
int a[2][2],b[2][2],s=0;
cout<<"--------------Equality of Matrices---------------"<<endl;
cout<<"Enter the elements of the first matrix"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Enter element "<<i<<j<<endl;
cin>>a[i][j];
cout<<"Enter the elements of the second matrix"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cout<<"Enter element "<<i<<j<<endl;
cin>>b[i][j];
}
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
if(a[i][j]==b[i][j]){
s+=1;
if(s==4){
cout<<"They are equal"<<endl;
else{
cout<<"They are not equal"<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
18. PROGRAM TO FIND TOTAL AND AVERAGE USING
STRUCTURE
SOURCE CODE:
#include <iostream>
using namespace std;
struct student
char name[20];
int s1,s2,s3,tot,av;
};
int main()
student a;
cout<<"Enter the student name"<<endl;
cin.getline(a.name,50);
cout<<"Enter mark 1:"<<endl;
cin>>a.s1;
cout<<"Enter mark 2:"<<endl;
cin>>a.s2;
cout<<"Enter mark 3:"<<endl;
cin>>a.s3;
a.tot = a.s1+a.s2+a.s3;
a.av = a.tot/3;
cout<<"Total: "<<a.tot<<endl;
cout<<"Average: "<<a.av<<endl;
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
19. PROGRAM TO PRINT TOTAL MARKS OF A STUDENT
USING FUNCTION
SOURCE CODE:
#include <iostream>
using namespace std;
float getmarks(int w,int x,int y,int z);
int main()
int a,b,c,d,n;
char m[20];
cout<<"Enter the marks"<<endl;
cin>>a>>b>>c>>d;
n=getmarks(a,b,c,d);
cout<<"Total is "<<n<<endl;
float getmarks(int w,int x,int y,int z)
float total = w+x+y+z;
return total;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
20. PROGRAM TO FIND THE DISTANCE BETWEEN TWO POINTS
USING FUNCTIONS
SOURCE CODE:
#include <iostream>
#include <math.h>
using namespace std;
float dist(int w,int x, int y, int z);
int main()
int a,b,c,d;
float n;
cout<<"Enter the first point"<<endl;
cin>>a>>b;
cout<<"Enter the second point"<<endl;
cin>>c>>d;
n=dist(a,b,c,d);
cout<<"The distance is "<<n<<" units"<<endl;
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.