Analysis: Input Output
Analysis: Input Output
Analysis
Input − a,b,c values
Output − r1, r2 values
Procedure
r1=−b+b2−4ac√2ar1=−b+b2−4ac2a
r2=−b−b2−4ac√2ar2=−b−b2−4ac2a
Design (Algorithm)
Start
Read a, b, c values
Compute d = b2 4ac
if d > 0 then
o r1 = b+ sqrt (d)/(2*a)
o r2 = b sqrt(d)/(2*a)
Otherwise if d = 0 then
o compute r1 = -b/2a, r2=-b/2a
o print r1,r2 values
Otherwise if d < 0 then print roots are imaginary
Stop
Implementation Code
# include<stdio.h>
# include<conio.h>
# include<math.h>
main (){
float a,b,c,r1,r2,d;
printf (“enter the values of a b c”);
scanf (“ %f %f %f”, &a, &b, &c);
d= b*b – 4*a*c;
if (d>0){
r1 = -b+sqrt (d) / (2*a);
r2 = -b-sqrt (d) / (2*a);
printf (“The real roots = %f %f”, r1, r2);
}
else if (d= =0){
r1 = -b/(2*a);
r2 = -b/(2*a);
printf (“roots are equal =%f %f”, r1, r2);
}
else
printf(“Roots are imaginary”);
getch ();
}
Q 2.
C++ Code:
#include<iostream>
using namespace std;
int main()
{
int e=1;
for(int a=1;a<=5;a++)
{
for(int b=4;b>=a;b--)
{
cout<<" "; // Printing Space Here
}
for(int c=0;c<e;c++)
{
cout<<"*"; // Printing asterisk hre
}
cout<<endl; // new line
e=e+2;
}
}
Program Output:
Q.3
int main()
int number;
number =0;
//print statement
//from 0 to 10
while(number<=10)
printf("%d ",number);
number++;
}
return 0;
}
Q5
a)
#include<iostream>
#include<cmath>
int main()
{
float a,b,c,x1,x2,d,real,imaginary;
cout<<"Quadratic Equation : ax^2 + bx + c";
cout<<"\nEnter coefficient of a : ";
cin>>a;
cout<<"Enter coefficient of b : ";
cin>>b;
cout<<"Enter coefficient of c : ";
cin>>c;
d=b*b-4*a*c;
if(d>0)
{
cout<<"Roots are real and distinct";
x1=(-b + sqrt(d)) / (2*a);
x2=(-b - sqrt(d)) / (2*a);
cout<<"\nx1 = "<<x1;
cout<<"\nx2 = "<<x2;
}
else if(d==0)
{
cout<<"Roots are real and same";
x1=(-b + sqrt(d)) / (2*a);
cout<<"\nx1 = "<<x1;
cout<<"\nx2 = "<<x1;
}
else
{
cout<<"Roots are complex and distinct";
real = -b/(2*a);
imaginary = sqrt(-d) / (2*a);
cout<<"\nx1 = "<<real<<"+"<<imaginary<<"i";
cout<<"\nx2 = "<<real<<"-"<<imaginary<<"i";
}
return 0;
}
Q. 7
a)
Source Code
#include <iostream>
using namespace std;
int main()
{
int rows;
return 0;
}
b)
#include <iostream>
#include <conio.h>
int main()
int rows,i,j;
cin>>rows;
}
for(j=1; j<i; j++){
cout<<j;
cout<<" ";
getch();
return 0;
}
8)
SOURCE CODE : :
#include<iostream>
int main()
int i,n,x,sum=0;
float avg;
cin>>n;
for(i=1;i<=n;++i)
cin>>x;
sum+=x;
}
avg=(float)sum/(float)n;
cout<<"\n";
return 0;
Q. 10
#include<iostream>
int main()
{
char fname[20],lname[20];
cout<<"meti:";
cin>>"meti";
cout<<"fekede:";
cin>>"fekede";
cout<<"Id No:";
cin>>"female";
cout<<"batch:";
cin>>"computer science";
int a,b = 0;
for(a=0;a<=50;a)
{
if(Id no___)
{
printf("id”);
}
}
printf(");