0% found this document useful (0 votes)
21 views15 pages

Analysis: Input Output

Use this material.

Uploaded by

jamsibro140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views15 pages

Analysis: Input Output

Use this material.

Uploaded by

jamsibro140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Q.

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;

cout<<"\" Triangle Shape SHAPE \":\n\n";

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()

//loop counter declaration

int number;

//assign initial value

//from where we want to print the numbers

number =0;

//print statement

printf("Numbers from 0 to 10: \n");

//while loop, that will print numbers

//from 0 to 10

while(number<=10)

//printing the numbers

printf("%d ",number);

//increasing loop counter by 1

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;

cout << "Enter number of rows: ";


cin >> rows;

for(int i = rows; i >= 1; --i)


{
for(int j = 1; j <= i; ++j)
{
cout << j << " ";
}
cout << endl;
}

return 0;
}
b)

number pattern program 5

#include <iostream>

#include <conio.h>

using namespace std;

int main()

int rows,i,j;

cout<<"Enter the number of rows: \n";

cin>>rows;

for(i=1; i<=rows; i++){//outer for loop - parent

for(j=1; j<=rows-i; j++){

cout<<" ";//print space-inner for loop

}
for(j=1; j<i; j++){

cout<<j;

cout<<" ";

cout<<"\n" ;//move to next line

getch();

return 0;

}
8)

C++ Program to Find Sum and Average of n


numbers using for loop

SOURCE CODE : :

#include<iostream>

using namespace std;

int main()

int i,n,x,sum=0;

float avg;

cout<<"How many numbers u want to enter :: ";

cin>>n;

for(i=1;i<=n;++i)

cout<<"\nEnter number "<<i<<" :: ";

cin>>x;

sum+=x;
}

avg=(float)sum/(float)n;

cout<<"\n\nSum of "<<n<<" Numbers :: "<<sum;

cout<<"\n\nAverage of "<<n<<" Numbers :: "<<avg;

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";

cout<<"Your full name is:"<<meti<<fekede<<endl;

int a,b = 0;

for(a=0;a<=50;a)
{
if(Id no___)
{
printf("id”);

}
}
printf(");

You might also like