0% found this document useful (0 votes)
9 views14 pages

Computer Programs Solved (2014-2019)

The document contains past programming exam questions and solutions for a Computer course in the Physics curriculum from 2016 to 2019. It includes C++ programs for various mathematical computations such as calculating products, squares, cubes, voltage, power, areas, and circumferences. Each section provides a specific problem statement followed by the corresponding C++ code implementation.

Uploaded by

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

Computer Programs Solved (2014-2019)

The document contains past programming exam questions and solutions for a Computer course in the Physics curriculum from 2016 to 2019. It includes C++ programs for various mathematical computations such as calculating products, squares, cubes, voltage, power, areas, and circumferences. Each section provides a specific problem statement followed by the corresponding C++ code implementation.

Uploaded by

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

Computer Third Semester past papers programs

Bs physics 3rd semester computer-211 (2019)


Past papers (2019-2014) all programs only
By: Mha Physics
Gmail; [email protected].
Govt. Post Graduate College, Sheikhupura.
2019
Q#2 (4) write a program to print out the product of first five integers?

Program:
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int i,p;
p=1;
cout<<"print five integers:\n";
for(i=1;i<=5;i++)
{
cout<<i<<endl;
p=p*i;
}
cout<<"product of first 5 integers is ="<<p;
getch();
}

Q#3 (b) write C++ program to print a number ,its square and cube such that the
numbers are from 1 to 500. How you can print only odd numbers in the above series?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
long int i,j,odd;
cout<<"number:\t:square:\tcube\n";
for(i=1;i<=500;i++)
{
cout<<i<<"\t"<<pow(i,2)<<"\t"<<pow(i,3)<<endl;
}
cout<<"\nprint odd series in the range of 1 to 500:\n";
for(i=1;i<=500;i++)
{
if(i%2==1)
odd=i;
cout<<odd<<endl;
}
getch();
}

Q#4 (a) write a program to read from the user value of “t” and print out as Y1,Y2,Y3 in
C++. Such that : Y1=sin(2t), Y2=cos(4t),Y3=Y1+Y2 ?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
int n;
const float pi=3.14;
long double t,y1,y2,y3;
cout<<"enter the number:\n";
cin>>n;
t=(n*pi)/180;
y1=sin(2*t);
y2=cos(4*t);
y3=y1+y2;
cout<<"value of y1 is ="<<y1<<endl;
cout<<"value of y2 is ="<<y2<<endl;
cout<<"value of y3 is ="<<y3<<endl;
getch();
}

Q#4(b) write a c++ program to print the table of number 5?

Program:
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
int i,a,n;
n=5;
cout<<"Table of number 5 :\n";
for(i=1;i<=10;i++)
{
a=n*i;
cout<<n<<"x"<<i<<"="<<a<<endl;
}
getch();
}

Q#5(a) Write a program to read from the user a value of resistance “R” and current “I”
and prints out values of voltage “V” and power “P” such that V=IR and P=VI?

Program:
#include<iostream>
#include<conio.h>
using namespace std;
main()
{
long double p,i,v,r;
cout<<"enter the value of resistance:\n";
cin>>r;
cout<<"enter the value of current:\n";
cin>>i;
v=i*r;
p=v*i;
cout<<"value of voltage when couurent="<<i<<"and resistance="<<r<<"is v:"<<v<<endl;
cout<<"value of power when couurent="<<i<<"and voltage="<<v<<"isp:"<<p;
getch();
}

End 2019

2018
Q#3 (b) write C++ program to print the series and also display corresponding average
and sum of even numbers in the range from 2 to 88. How you can print only odd numbers
in the above series?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
long int i,even;
long int sum=0;
float avg;
cout<<"series of number from 2 to
88:\n";
for(i=2;i<=88;i++)
{
cout<<i<<endl;
if(i%2==0)
{
even=i;
sum=sum+even;
avg=sum/44;
}
}
cout<<"\n sum of even integers in
the range of 2 to 88="<<sum<<endl;
cout<<"average="<<avg;
cout<<"\nprint odd series in the
range of 2 to 88:\n";
for(i=2;i<=88;i++)
{
if(i%2==1)
cout<<i<<endl;
}
getch();
}

Q#4 (a) write a program to read from the user value of “t” and print out as Y1,Y2,Y3 in
𝟐𝒕−𝟒
√𝟐𝒕𝟑
C++. Such that : Y1=sin(𝒆 ), Y2=𝒆 cos(sin𝒆𝒕 ) ?
𝟒 ,Y3=

Program:

#include<iostream>
#include<conio.h>
#include<math.h>
#define e 2.7182
using namespace std;
main()
{
long double t,y1,y2,y3;
cout<<"enter the number:\n";
cin>>t;
y1=sin(pow(e,sqrt(2*t*t*t)));
y2=pow(e,((2*t-4)/4));
y3=cos(sin(pow(e,t)));
cout<<"value of y1 is ="<<y1<<endl;
cout<<"value of y2 is ="<<y2<<endl;
cout<<"value of y3 is ="<<y3<<endl;
getch();
}

Q#5(a) For an object thrown at an angle "𝜃" and initial velocity "u", the horizontal range "R" is given by:
𝑢2 sin(2𝜃)
R= , where g=9.8m𝑠 −2 ,u=120m/s.
𝑔
𝟎
Write a program to print out “R” against ,angle "𝜃" values. Take angle varies from "𝟑𝟎 " to “𝟔𝟎𝟎 ”in step
size of 𝟑𝟎 ?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
int t,u,a;
a=0;
long double R[50],b;
const float pi=3.14, g=9.8;
u=120;
for(t=30;t<=60;t=t+3)
{
b=(t*pi)/180;
R[a]=(pow(u,2)*sin(2*b))/g;
cout<<"value of range at angle :"<<t<<"and velocity u="<<u<<"is
R="<<R[a]<<endl;
a++;
}
getch();
}

End 2018

2017

Q#3 (a) Write program to read a, b and c values for a triangle sides and
calculate area such that A =√(𝒔(𝒔 − 𝒂)(𝒔 − 𝒃)(𝒔 − 𝒄)) where , S=(a+b+c)/2.?
Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
float a,b,c,s,p;
long double A;
cout<<"enter one side of triangle:\n";
cin>>a;
cout<<"enter second side of triangle:\n";
cin>>b;
cout<<"enter third side of triangle:\n";
cin>>c;
s=(a+b+c)/2;
p=s*(s-a)*(s-b)*(s-c);
A=sqrt(p);
cout<<"area of triangle is="<<A;
getch();
}

Q#3 (b) write C++ program to print the series and also display corresponding average
and sum of numbers in the range from 1 to 100. How you can print only even numbers in
the above series?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
long int i,j;
long int sum=0;
float avg;
cout<<"series of number from 1 to 100:\n";
for(i=1;i<=100;i++)
{
cout<<i<<endl;
sum=sum+i;
}
cout<<"\n sum of even integers in the range of 1 to 100="<<sum<<endl;
avg=sum/100;
cout<<"average="<<avg;
cout<<"\nprint even series in the range of 1 to 100:\n";
for(j=1;j<=100;j++)
{
if(j%2==0)
cout<<j<<endl;
}
getch();
}

𝒍
Q#4 The time period of simple period is given by T=2𝝅√ , write a program to
𝒈
determine and print the Time “T” against length “l” varies from 1 to 20 meters with step
5. Take g=9.8 m/s^2?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
const float pi=3.14, g=9.8;
long double T[50];
int l,a=0;
cout<<"values of Time period are:\n";
for(l=1;l<=20;l=l+5)
{
T[a]=2*pi*sqrt(l/g);
cout<<"Time period against lenght l=:\t"<<l<<"\t\t T="<<T[a]<<endl;
a++;
}
getch();
}

Q#5 write a program to calculate the are “A” and circumference “C” of circle, where
A=𝝅𝒓𝟐 ,and C= 𝟐𝝅𝒓 ?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
const float pi=3.14;
int r;
float A,C;
cout<<"enter the radius:\n";
cin>>r;
A=pi*r*r; //Area of circle formula
C=2*pi*r; //Circumference of circle formula
cout<<"Area of circle having Radius r="<<r<<"is eqal to : A="<<A<<endl;
cout<<"Circumference of circle having Radius r="<<r<<"is eqal to : C="<<C<<endl;
getch();
}
2017 End
2016
Q#4(a) write a program that input the radius of circle to calculate the circumference “C”
of circle, where C= 𝟐𝝅𝒓 ?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
const float pi=3.14;
int r;
float C;
cout<<"enter the radius:\n";
cin>>r;
C=2*pi*r; //Circumference of circle formula
cout<<"Circumference of circle having Radius r="<<r<<"is eqal
to : C="<<C<<endl;
getch();
}

Q#5(a) write a program to calculate the surface area and volume of sphere, where surface
area is A== 𝟒𝝅𝒓𝟐 , & volume V== 𝟒/𝟑𝝅𝒓𝟑?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
const float pi=3.14;
int r;
float A,V;
cout<<"enter the radius:\n";
cin>>r;
A=4*pi*r*r; //Area of sphere formula
V=(4*pi*r*r*r)/3; //Volume of sphere formula
cout<<"Area of sphere having Radius r="<<r<<"is eqal to : A="<<A<<endl;
cout<<"Volume of sphere having Radius r="<<r<<"is eqal to : V="<<V<<endl;
getch();
}

Q#5 (b) write C++ program to print the series and also display corresponding average
and sum of numbers in the range from 1 to 100. How you can print only odd numbers in
the above series?

Program:
#include<iostream>
#include<conio.h>
#include<math.h>
using namespace std;
main()
{
long int i,j;
long int sum=0;
float avg;
cout<<"series of number from 1 to 100:\n";
for(i=1;i<=100;i++)
{
cout<<i<<endl;
sum=sum+i;
}
cout<<"\n sum of even integers in the range of 1 to 100="<<sum<<endl;
avg=sum/100;
cout<<"average="<<avg;
cout<<"\nprint even series in the range of 1 to 100:\n";
for(j=1;j<=100;j++)
{
if(j%2==1)
cout<<j<<endl;
}
getch();
}

2016 End

Thanks For Reading


Regard: MhaPhysics
Session : 2017-2021
Instituation: Govt. Post Graduate clg,Sheikhupura.

You might also like