Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 7

‫بسم هللا الرحمن الرحيم‬

‫االسم ‪ /‬عبدالعزيز ايوب الزمام‬

‫‪202102084‬‬ ‫الرقم الجامعي ‪/‬‬


Question 1: Write a C++ program having this
expected output:
1
2
3
4
5
The sum is : 15
The average is: 3

#include <iostream>
using namespace std;
void main()
{
int a,b,c,d,e,sum;
float arg =0;
cin>>a>>b>>c>>d>>e;
sum =a+b+c+d+e;
avg=sum/5;

cout << "the sum is : "<< sum ;


cout << "end\ ";
cout << "the average is : "<< avg ;

return 0;
}
:Question 2
Write a C++ program that accepts four
integer from the user and prints “equal” if
all four are equal, and “not equal”
.otherwise

#include <iostream>
using namespace std;
void main()
{

int a,b,c,d,;
cout << "enter four number " ;
cin>>a>>b>>c>>d;

if(a==b|| a==c|| a==d)

cout << "equal " ;


else
cout << "not equal " ;
return 0;
}
Question 3
Write a C++ program that accepts two
double variables and test if both strictly
between 0 and 1 and false otherwise.
Sample Output:
Input first number: 5
Input second number: 1
false
#include <iostream>
using namespace std;
int main()
{ double n1,n2;
cout << "Input first number: ";
cin >> n1;
cout << "Input second number: ";
cin >> n2;
if(n1>0&&n1<1&&n2>0&&n2<1)
{ cout<<"input numbers are in between 0 and
1"; }
Else
{ cout<<"false";

} return 0;
}
Question 4
Write a C++ program to get a number from
the user and print whether it is positive or
negative.

#include <iostream>

using namespace std;

int main()

{int n; //variable declaration

cout<<"enter number:"; //prompt for


user input

cin>>n; //reading input

if(n>0) //check whether n is posuitive or


not

cout<<"entered number is positive


number"; //

if positive print positive number

else //

if not

cout<<"entered number is negative


number";
//print negative number
return 0;

}
Question 5
Write a C++ program to take three
numbers from the user and print the
greatest number.

#include <iostream>
using namespace std;
int main()
{
int n1,n2,n3;
//variable declaration cout<<"enter first number:";
cin>>n1;
cout<<"enter second number:";
cin>>n2;
cout<<"enter third number:";
cin>>n3;
if (n1>n2&&n1>n3)
//check whether n1 is greatest than n2 and n3
{
cout<<"greatest number is:"<<n1;
//if yes print this
}
else if(n2>n1&&n2>n3) //check whether n2 is
greatest than n1 and n3
{
cout<<"greatest number is:"<<n2;
//if yes print this
}
else //if not

{
cout<<"greatest number is:"<<n3;
//print this
}

return 0;
}

You might also like