You are on page 1of 4

Question 2

#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{
float x, y, z, area, theta;
char next;

next='y';
while ( next == 'y'|| next=='Y' )
{
cout <<"\nEnter positive x and y : ";
cin>>x>>y;

if (x<=0 || y<=0 )
cout<<"Input error!"<<endl;
else
{
z=sqrt( x*x +y*y );
area= 0.5*x*y;
theta= atan(x/y);
cout<<"z="<<z<<endl;
cout<<"area ABC = "<<area<<endl;
cout<<"theta="<<theta<<endl;
}
cout<<"Do you want to continue?(y/n):";
cin>>next;
}cout<<"\n\nPress any key to exit...";
getch();
}

Question 3

#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{
float P,L,N,x;

cout<<"Please input theload, P, the beam span, L, and the diatance, x : ";
cin>>P>>L>>x;
if (x<0)
cout<<"Input Error ! "<<endl;
else if (x<(L/2.0))
{
N=P * (x/2.0);
cout<<"\nThe bending moment,N("<<x<<")="<<N;
}
else if(x<=L)
{
N=(P/2.0)*(L-x);
cout<<"\nThe bending moment,N("<<x<<")="<<N;
}
else
cout<<"Input Error !"<<endl;

cout<<"\n\nPress any key to exit...";


getch();
}

Question 4

#include <iostream.h>
#include <conio.h>
#include <math.h>
void main()
{
float number, marks, sum, min, max, average;

number=marks =sum = 0;
max = -1 ;
min = 1000;

cout<<"Please enter marks, type -1 if you want to stop : ";


cin>>marks;

while (marks>=0)
{
sum = sum + marks;
number = number +1;

if (marks > max)


max=marks;

if (marks<min)
min = marks;
}
cout<<endl;

average = sum/number;

cout<<"The average of marks entered is "<<average<<".";


cout<<"\nThe minimum is"<<min<<"and the maximun is "<<max<<".";

cout<<"\n\nPress any key to exit...";


getch();
}

Question 5

#include <iostream.h>
#include <conio.h>
#define size 8

void main()
{
int num, sum=0,count=0;

while(count<size)
{
cout<<"Please enter an integer : ";
cin>>num;

sum=sum+num;
count++;
}

cout<<"\nSum of the"<<size<<"integer is"<<sum;

cout<<"\n\nPress any key to exit...";


getch();
}

Question 6

#include <iostream.h>
#include <conio.h>
#include <math.h>
#define size 100

void main()
{
float n, sum,pi;
sum=0.0;
n=1;

while(n<=size)
{
sum= sum + (pow(-1,(n-1))/(2*n-1));
n++;
}

pi=4.0*sum;
cout<<"\nThe value of pi is "<<pi<<".";

cout<<"\n\nPress any key to exit...";


getch();
}

You might also like