2.program To Find The Roots of A Quadratic Equation Source Code
2.program To Find The Roots of A Quadratic Equation Source Code
2.program To Find The Roots of A Quadratic Equation Source Code
SOURCE CODE:
#include <iostream>
#include <math.h>
int main()
{ float r1,r2;
int a,b,c,d;
cin>>a;
cin>>b;
cin>>c;
d=(b*b)-(4*a*c);
r1=(-b+sqrt(d))/(2*a);
r2=(-b-sqrt(d))/(2*a);
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
3. PROGRAM TO FIND THE FACTORIAL OF THE NUMBER
SOURCE CODE:
#include <iostream>
int main()
int a,n;
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>
int main()
{ int num,a,rem,sum=0;
cin>>a;
num=a;
while(a=0)
{ rem=a%10;
sum=rem*rem*rem+sum;
a/=10;
if(sum==num){
else
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>
int main()
{ int b,a,rem,rev=0;
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
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>
int main()
long dec,rem,i=1,sum=0;
cin>>dec;
do
rem=dec%2;
sum=sum+(i*rem);
dec=dec/2;
i=i*10;
while(dec>0);
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>
int main()
float area;
int n,a,b,c,d;
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:
cin>>a;
area=3.14*a*a;
cout<<"Area: "<<area<<endl;
break;
case 2:
cin>>a;
area=a*a;
cout<<"Area: "<<area<<endl;
break;
case 3:
cin>>a;
cin>>b;
area=a*b;
cout<<"Area: "<<area<<endl;
break;
case 4:
cin>>a;
cin>>b;
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>
int main()
int sum = 0;
char a[50];
cin.getline(a,50);
int d = strlen(a);
for(int i=0;i<d;i++){
sum+=1;
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>
int main()
char a[50];
cin.getline(a,50);
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>
int main()
gets(a);
gets(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>
int main()
{ char a[50],b[50];
int c,d;
cin>>a;
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
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
SOURCE CODE:
#include <iostream>
#include<stdio.h>
#include<string.h>
int main()
{ char a[50],b[50];
int c,d;
gets(a);
gets(b);
c=strlen(a);
d=strlen(b);
if(c>d)
else if (d>c)
{ cout<<"string2 is bigger"<<endl;
else{
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
#include <iostream>
int main()
int a[50],n,item,s=0,x;
cout<<"---------------------Linear Search------------------------"<<endl;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
cin>>item;
for(int i=0;i<n;i++){
if(a[i]==item){
x=i;
if(s==1){
else{
cout<<"Data is not found"<<endl;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
SOURCE CODE:
#include <iostream>
int main()
{
float a[100],s=0;
int n,i;
cin>>n;
for(i=1;i<=n;i++)
cin>> a[i];
s+= a[i];
cout<<s/n;
return 0;
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
int main()
int a[2][2];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cin>>a[i][j];
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.
int main()
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cin>>a[i][j];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
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>
int main()
int a[2][2],b[2][2],s=0;
cout<<"--------------Equality of Matrices---------------"<<endl;
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
cin>>a[i][j];
for(int i=0;i<2;i++){
for(int j=0;j<2;j++){
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){
else{
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.
18. PROGRAM TO FIND TOTAL AND AVERAGE USING
STRUCTURE
SOURCE CODE:
#include <iostream>
struct student
char name[20];
int s1,s2,s3,tot,av;
};
int main()
student a;
cin.getline(a.name,50);
cin>>a.s1;
cin>>a.s2;
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.
SOURCE CODE:
#include <iostream>
int main()
int a,b,c,d,n;
char m[20];
cin>>a>>b>>c>>d;
n=getmarks(a,b,c,d);
cout<<"Total is "<<n<<endl;
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>
int main()
int a,b,c,d;
float n;
cin>>a>>b;
cin>>c>>d;
n=dist(a,b,c,d);
return 0;
}
OUTPUT:
RESULT:
The Program Is Compiled And Executed Successfully.