0% found this document useful (0 votes)
5 views

Math Sheet

Uploaded by

maryamamr865
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

Math Sheet

Uploaded by

maryamamr865
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

Assuit Math sheet

<Given three numbers L, rand M Print the product of all numbers from L to R module M>

long long l, r, m;

cin >> l >> r >> m;

long long result = 1;

for (long long i = l; i <= r; i++) {

result = (result * (i % m)) % m;

cout << result << "\n";

----------------------------------------

<Given three points on the Cartesian plane. Determine if 1 straight can pa >

float x1 , x2 , x3 , y1 , y2 , y3 ;

cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 ;

double ans = (x2 -x1) * (y3- y1) -(y2 -y1)* (x3 - x1) ;

if (ans == 0) {

cout << "YES" ;

else {

cout << "NO" ;

----------------------------------------

<Given two lines L1 and Determine whether they are parallel or not>

float x1 , x2 , x3 , x4, y1 , y2 , y3, y4 ;

cin >> x1 >> y1 >> x2 >> y2 >> x3 >> y3 >> x4 >> y4;

double ans = ((x2-x1)*(y3-y4)) - ((y2-y1)*(x3-x4)) ;

if (ans == 0 ) {

cout << "YES" ;

}
else {

cout << "NO" ;

--------------------------------------

<Given 2 Cartesian points (X1, Y1) and (X2, Y2). Print the distance between the two points>

float x1 ,x2 , y1 ,y2;

cin >> x1 >> y1 >> x2 >> y2 ;

double a = (x2-x1)*(x2-x1) + (y2-y1)*(y2-y1) ;

cout << fixed << setprecision(9) << sqrt(a) ;

--------------------------------------

<3 sides determine if valid triangle and if print its area>

float a[3] ;

cin >> a[0] >> a[1] >> a[2] ;

a[3] = 1500 ;

sort (a, a+3) ;

if ( a[0]+a[1] > a[2] ) {

cout << "Valid" << "\n";

float s = (a[0]+a[1] + a[2]) / 2 ;

float area = s * (s-a[1]) * (s-a[0]) * (s-a[2]) ;

cout << fixed << setprecision(9) << sqrt (area) ;}

else {

cout << "Invalid" ;

----------------------------------------

< Given a cartesian point (X,Y) donates a circle center,

a number R donates radius of the circle and a number N donates number of points coordinates

. For each point determine whether it belongs to the circle or not>

double x1 , y1 , r , t ;

cin >> x1 >> y1 >> r >> t ;


while (t--) {

double x2 , y2 ;

cin >> x2 >> y2 ;

double distance = (x2 - x1)*(x2 - x1) + (y2 - y1)*(y2 - y1);

distance = sqrt (distance) ;

if (distance > r ) {

cout << "NO" << "\n" ;

else {

cout << "YES" << "\n" ;

----------------------------------------

<Given a number N. Print the prime factors of N in the following form: (P1)x * (P2)y...>

int n ;

cin >> n ;

for (int i = 2 ; i*i<=n ;i++ ) {

while (n%i==0) {

n= n/i ;

freq[i] ++; }

if (n!=1) {

freq[n] ++;

bool tm = 0;

for (int i = 2 ; i<20000000 ; i++) {

if (freq[i]>0) {

if (tm==1) {

cout <<"*"<< "(" << i << "^" << freq[i] << ")" ;
}

else {cout << "(" << i << "^" << freq[i] << ")" ;

tm = 1 ;

}}}

---------------------------------------

<Given a number N Print first N rows of pascal triangle.>

int n ; cin >> n ;

for (int i = 1 ;i<=n; i++ ) {

int cof = 1 ;

for (int j = 1 ; j<=i ;j++) {

cout << cof << " " ;

cof = cof*(i-j) /j ;

cout << "\n" ;

---------------------------------------

<Given two numbers and S that donate radius of a circle and side length of a square.

Determine which shape holds the other or it's complex to be determined.>

double r , s ;

cin >> r >> s ;

double r2 = s/2 ; // raduis of square

double arear = log (r*r * 3.14 ) ;

double arear2 = log (r2*r2 * 3.14 ) ;

double areas =log ( s*s ) ;

double diff = areas - arear2 ;

double dia = s*sqrt(2) ;

if ( arear > arear2 && r2 < r && areas < arear && dia<=r*2 ) {

cout << "Circle" ; }


else if (r <= r2) {

cout << "Square" ;}

else cout << "Complex" ;

---------------------------------------------

<Given a rectangle represented by four distinct points: (x1,y1),(x2,y2),(x3,y3)

and (x4,y4)

,With two sides parallel to the Y-axis and the other two parallel to the X-axis and N

points, for each point check whether it belongs to the rectangle or not.>

int x[5] , y[5] ;

for (int i = 1 ; i<=4 ;i++ ) {

cin >> x[i] >> y[i] ;

sort (y+1 , y+5) ;

sort (x+1 , x+5 ) ;

int q ;

cin>> q ;

while (q--) {

int a , b; cin >> a>> b ;

if (a <=x[4] && a>=x[1] && b<=y[4] && b>=y[1]) {

cout << "YES" << "\n" ;

else {

cout << "NO" << "\n" ;

------------------------------------------------

<Given four cartesian points (X1, Y1), (X2, Y2), (X3, Y3) and (X4, Y4) that

donate two endpoints ofa diameter of


circle A and circle B respectively. Determine whether these two circles intersect or not.>

double x1 , y1 , x2 , y2 ;

cin >> x1 >> y1 >> x2 >> y2 ;

double c1x1 = (x1+x2) /2 ;

double c1y1 = (y1+y2) /2 ;

double rc1 = sqrt (((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) ) / 2 ;

cin >> x1 >> y1 >> x2 >> y2 ;

double c2x2 = (x1+x2) /2 ;

double c2y2 = (y1+y2) /2 ;

double rc2 = sqrt (((x2-x1)*(x2-x1)) + ((y2-y1)*(y2-y1)) ) / 2 ;

double tcd = sqrt (((c2x2-c1x1)*(c2x2-c1x1)) + ((c2y2-c1y1)*(c2y2-c1y1)) ) ;

if (rc1 + rc2 >= tcd) {

cout << "YES" ;

else {

cout << "NO" ;

-------------------------------------------------------------------

<Given a number N Print the number of digits of N! (factorial N)>

int n ;

cin >> n ;

double d = 0 ;

for (int i = 2 ; i<=n ;i++) {

d += log10(i) ;

cout << "Number of digits of " << n << "! is " << floor(d) +1 ;

----------------------------------------------

<Given two numbers Aand B Print NCR and NPR of A and B A≥B >

NCR is the Combination. NPR is the Permutation.


long long a,b; cin >> a >> b;

long long facta=1,factb=1,factab=1;

long long ab=a-b;

for (int i=2; i<=a; i++)

if(i<=ab)

factab*=i; }

if(i<=b)

factb*=i; }

facta*=i; }

long long ncr=facta/(factb*factab);

long long npr=facta/factab;

cout << ncr << " " << npr;

----------------------------------------------------

<Given 2 numbers A and B print 3 lines summation of all numbers between A and B (inclusive).
summation of even numbers between A and B (inclusive).summation of odd numbers between
A and B (inclusive)>
long long a,b;
cin >> a >> b;
long long mn=min(a,b),mx=max(a,b);
a=mn; b=mx;
long long sum=((b*(b+1))/2)-((a*(a-1))/2);
a--;
long long even=((b/2)*((b/2)+1))-((a/2)*((a/2)+1));
long long odd=sum-even;
cout << sum << "\n"<< even << "\n" odd;

You might also like