Professional Documents
Culture Documents
CSCI Lab 1
CSCI Lab 1
Q1. Write a C++ program to read and then Add two numbers type integer and display the
result.
#include <iostream>
using namespace std;
int main()
{ int r=0;
do{
cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers;
cout<< "\n\n Do you want to try again? \n\n Enter 0 to continue";
cin>> r;
}
while(r==0);
Q2. Modify your previous C++ program to enter and Add two numbers type float and display
the result .
#include <iostream>
using namespace std;
int main()
{ int r=0;
do{
cout << firstNumber << " + " << secondNumber << " = " << sumOfTwoNumbers;
cout<< "\n\n Do you want to try again? \n\n Enter 0 to continue";
cin>> r;
}
while(r==0);
Q4. Operators
a) State some binary arithmetic operators
addition, subtraction, multiplication, exponentiation (**), division, and modulus
(%).
b) State some unary arithmetic operators
unary minus(-)
increment(++)
decrement(- -)
NOT(!)
Addressof operator(&)
sizeof()
d) State some boolean logical operator cout << (5>3) && (5<3)
Greater than or equal to
Less than = to
&&
&^
e) Difference between logical and relational operators
Lol I’ll do this soon
Q6. Write a C++ code that enters an integer and output whether the integer is odd or not
(state which operators have you used)
#include <iostream>
using namespace std;
int main()
{ int r=0;
do{
}
while(r==0);
Q7. Write a C++ code to check whether the year entered from console is a leap year or not
(Leap year: 365+1=366 days).
To determine whether a year is a leap year (it has 366 days):
1. If the year is evenly divisible by 4.
2. If the year is evenly divisible by 100
3. If the year is evenly divisible by 100, then it should also be divisible by 400
Q8. Write a C++ code to read an int (between 1 to 12 ) and use Swicth case Statement to print
the name of the month (1 for January, ...)
Q9. Write a C++ code to calculate the Factorial of an integer. Read the number k from
console
0! = 1
k! = 1*2*3*…k
use a for statement and then write a recursive function.
Q10. Write a recursive function to calculate the Factorial of an integer. Read the number k
from console
0! = 1
k! = 1*2*3*…k
int main()
Lab Session 1 Abdellatif Tchantchane & Toth Tamas 4
{ const int size=4;
int array[size]={1,2,3,4};
add (array, size);
cout << array[1]<<endl;
return 0;
}
Q12. Write C++ functions for calculating the value each of the functions at some value of
x using the first 10 terms of the Taylor expansion. Display the error between the value
using their corresponding math functions and your calculated values.
Q15. Read N numbers (floats or integers) in an array by reading them from a text file.
- Print them to the console and write them in reverse order.
- Write whether the array is in ascending order or in descending order or neither.