624 words - 3 pages

ngNicholas, 07-015

Turbo C++ Algorithms & Coding 1. Finding the absolute value of an integer Algorithm (single alternative control flow) Absolute Value ( ) Coding #include void main () { { 1. input n; int n; 2. if (n43) 5. print : Second Class; 6. else if (mark > 32) 7. print : Third Class; 8.else 9. print: Fail; } 3. Determining the roots of quadric equation Algorithm

Quadric Equation ( ) { 1. input a, b, c ; 2. d= b*b- 4*c*a ; 3. if (d 59) printf("first class"); else if (mark>44) printf("Second class"); else if (mark>32) printf("third class"); else printf("fail"); } Coding

#include #include void main() { float a,b,c,x1,x2,d; scanf ("%f%f%f",& a,& b,& c); d=(b*b-4*c*a); if (d79) 3. print : A+; 4. else if (n >74) 5. print : A; 6. else if (n > 69) 7. print : A-; 8. else if (n >64) 9. print: ...view middle of the document...

Finding whether a number is even or odd: Algorithm (double alternative control flow) Even Odd ( ) Coding #include void main () { { 1. input n; int n; 2. if (n MOD 2=0) scanf("%d", & n); 3. print : n is even; if (n %2==0) 4. else printf("even number"); 5. print : n is odd; else } printf("odd number"); } 6. Finding the area of a Circle by inputting the radius Algorithm (sequential control flow) Circle Area ( ) { 1. input r; 2. a= 3.14 * r * r ; 3. print : the area is = a ; } Coding #include void main () { float r, a; printf("enter radius"); scanf ("%f", & r); a= 3.14* r* r; printf("the area is=%f", a); }

Nicholas, 07-015

7. Finding the area of a Triangle by inputting base and height Algorithm (sequential control flow) Circle Triangle ( ) { 1. input b, h; 2. a= (0.5)* b * h ; 3. print : the area is = a ; } Coding #include void main () { float b, h, a; printf("enter base"); scanf ("%f", & b); printf("enter height"); scanf ("%f", & h); a= (0.5)*b*h; printf("the area is=%f", a); }

8. Finding the Interest of a sum of money Algorithm (sequential control flow) Simple Interest ( ) { 1. input p, r, y; 2. i= p* r* y; 3. print : the interest is = i ; } Coding #include void main () { float r,i; int p, y; printf("enter principal amount"); scanf ("%d", & p); printf("enter rate of interest"); scanf ("%f", & r); printf("enter year"); scanf ("%d", & y); i= p*r*y; printf("the interest is=%f", i); }

9. Finding whether a number is positive or negative Algorithm (Double alternative control flow) Positive Negative( ) { 1. input n; 2. if (n< 0) 3. print : the number is negative ; 4. else 5. print : the number is positive; } Coding #include void main () { float n; printf("enter the number"); scanf ("%f", & n); if (n< 0) printf("the number is negative"); else printf("the number is positive"); }

Tap into the world’s largest open writing community