Programming Question Edit
Programming Question Edit
Solution
#include <iostream>
using namespace std;
int main() {
cout<<"It is the programme to find out the larger number
between two number.";
int a,b;
cout<<"\n\nInput a=";
cin>>a;
cout<<"\nInput b=";
cin>>b;
if ((a=b)) {
cout<<"\nThe two integers are equal.";
}
if (a>b) {
cout<<"\n"<<b<<"is larger";
}
else
cout<<"\n"<<a<<" is larger";
return 0;
}
(2014)
Solution
#include <iostream>
using namespace std;
int main()
{
float n1, n2, n3;
cout << "Enter three numbers: \n";
cin >> n1 >> n2 >> n3;
return 0;
}
Solution
#include <iostream>
#include <cmath>
using namespace std;
int main() {
float a, b, c, x1, x2, discriminant, realPart,
imaginaryPart;
cout << "Enter coefficients a, b and c: \n";
cin >> a >> b >> c;
discriminant = b*b - 4*a*c;
if (discriminant > 0) {
x1 = (-b + sqrt(discriminant)) / (2*a);
x2 = (-b - sqrt(discriminant)) / (2*a);
cout << "Roots are real and different." << endl;
cout << "x1 = " << x1 << endl;
cout << "x2 = " << x2 << endl;
}
else if (discriminant == 0) {
cout << "Roots are real and same." << endl;
x1 = (-b + sqrt(discriminant)) / (2*a);
cout << "x1 = x2 =" << x1 << endl;
}
else {
realPart = -b/(2*a);
imaginaryPart =sqrt(-discriminant)/(2*a);
cout << "Roots are complex and different." << endl;
cout << "x1 = " << realPart << "+" << imaginaryPart <<
"i" << endl;
cout << "x2 = " << realPart << "-" << imaginaryPart <<
"i" << endl;
}
return 0;
}
Solution
#include <iostream>
using namespace std;
int main()
{
cout<<"Sum of series 1+2+3+.....+n,where n is any positive
integer.\n";
int n, sum = 0;
cout << "Enter a positive integer: ";
cin >> n;
for (int i = 1; i <= n; ++i) {
sum += i;
}
cout << "Sum = " << sum;
return 0;
}
v) supplying the elements of an array of four
elements, evaluating the sum of the elements;
displaying the array and the sum. (concepts: basic
input output, looping, array)
Solution
#include <iostream>
using namespace std;
int main()
{
int arr[4];
int sum=0;
cout << "Please enter 4 integers:\n\n"; for(int i = 0;
i < 4; i++)
{
cout<<"\tarr["<<i<<"] = ";
cin >> arr[i];
cout<<endl;}
cout << "\n\nValues in array are now:";
for(int i = 0; i < 4; i++)
cout << " " << arr[i];
cout << endl;
for(int i=0; i<4; ++i)
sum+=arr[i];
cout<<"\n\nSum of the elements is = "<<sum<<endl;
return 0;
}
vi) supplying elements to a 2 x 3 matrix, displaying
the matrix and its transpose. (concepts: basic input
output, looping, array)
Solution
#include <iostream>
using namespace std;
int main()
{int arr[4];
int sum=0;
cout << "Please enter 4 integers:\n\n";
for(int i = 0; i < 4; i++)
{
cout<<"\tarr[“<<i<<“] = ";
cin >> arr[i];
cout<<endl;}
cout << "\n\nValues in array are now:";
for(int i=0; i< 4; i++)
cout << " " << arr[i];
cout << endl;
for(int i=0; i<4; ++i)
sum+=arr[i];
cout<<"\n\nSum of the elements is = "<<sum<<endl;
return 0;
}
vii) Write code in c plus plus to count 1 to 10 and
print:
1,2,3,4,5,6,7,8,9,10. Thank You. (2016)
Solution
#include <iostream>
using namespace std;
int main()
{
cout<<"This is the programme to count 1 to 10.";
int num;
num=1;
while (num<=10)
{
cout<<num<<"\t";
num++;
}
cout<<"Thank You";
return 0;
}
Viii) In C++:
(2016)
i. evaluates whether the following identifiers are
valid or not.
double,
4_x,
variable1,
My.Variable
ii. compare the expressions:
x and 'x'
iii. compare the statements:
int a;
int a = 5;
const int a = 5;
iv.compare the statements:
cout<<"Hello";
cout <<Hello;
Solution
i.
double: Here double is a fundamental data type numeric
variable. So double is not valid.
ii.
x: Here x is integer type variable.
‘x’: Here x is character type variable.
iii.
int a: Here a is a changeable variable. The value of a isn't
declaring yet. We can declare a’s value later.
iv.
cout << "Hello"; // prints Hello
cout << Hello; //prints the content of variable Hello
ix) Write code in any high level language for the
determination of area of a circle. (2013)
Solution
#include<iostream>
using namespace std;
int main()
{
float r,area;
cout<< "\nEnter radius of circle : ";
cin>>r;
area = 3.14*r*r;
return 0;
}
x) Write a programming code in C or C++ for conversion of
temperature in Fahrenheit scale from Celsius scale
and vice versa. (2012)
Solution
#include<iostream>
#include<stdio.h>
using namespace std;
int main()
{
char more, equ;
cout<<"\n\n\t Convertion of temperature between celsius and
farenheit.\n\n\t\t";
float C,F; //indicating possition.
Level1:
cout<<" For converting celsius to farenheit
press'c''C'n\n\t for converting farenheit to celsius press
'f''F'.\n\t\n";
cin>>equ;
} //calculating more.
cout<<"\n\n\tIf you want to calculate more press 'y'
otherwise press any key to exit.\n\t";
cin>>more;
if(more=='y'|| more=='Y')
goto Level1;
cout<<"\n\n\t Thank you for using this programme.";
return 0;
}