Вы находитесь на странице: 1из 19

ICT REVIEWER

LESSON 1: RANDOM FUNCTION

Terms:
A. Random Function
to generate random numbers
B. Randomize();
To change random seed number generated by the computer

(basically kapag hindi mo to ginamit iisang number lang ang ididisplay


ng program mo sa random. purpose nito is makapag generate ng
ibat ibang number ng kusa yung program ng hindi mo pinapatay
yung computer mo)

Library:
#include<stdio.h>

Syntax:
variable name = random(no);
( yung number na ilalagay mo sa loob magdedetermine ng limit ng
numbers na pwedeng idisplay ng program mo)

Program Samples:
1. Create a program that prompts the user to generate a number from 0-9
Syntax:

int x;

randomize();

x=random(10);

p(%d,x);

(kaya 10 ang nakalagay diyan ay dahil may 10 numbers from 0-9 okay? okay.)

2. Create a program that prompts the user to generate TEN numbers from 0-9

Syntax:
int x,y;

for(y=1; y<=10; y++)

x=random(10);

p(%d,x);

3. Create a program that prompts the user to enter TEN ODD numbers from 1-
100

Syntax:

int x, y;

for(y=1; y<=10; y++)

x=random(50*2)+1;

p(%d,x);

(kids ituturo ko sa inyo paano nakuha yung 50*2+1 stuff sa loob ng random.
since malaking number ang 1-100 mas maganda kung ididivide mo muna siya
sa two)

diba ang nasa program is x=random(50*2)+1? nakukuha yan by doing this:


4. Create a program that will prompt the user to enter TEN EVEN
numbers from 0-100
SYNTAX:
int x, y;

for(y=1; y<=10; y++)

x=random(50)+1)*2;

p(%d,x);

}
5. Create a program that will prompt the user to enter TEN numbers
from -144 to 144 which are divisible by 12

SYNTAX:

int x, y;
for(y=1; y<=10; y++)

{
x=random(25)-12)*12;
p(%d,x);

}
6. Create a program that will prompt the user to enter 5 numbers from
5-500
a. Odd number
SYNTAX:

int x,y;
for(y=1; y<=5; y++)
{
x=random(200)+51)*2-1;
p(%d,x);

}
b. Even number

SYNTAX:
int x,y;
for(y=1; y<=5; y++)

x=random(201)+50)*2;

p(%d,x);

}
(paulit ulit lang naman yan ang magbabago lang is yung value sa loob
ng random na mafifigure out mo sa paggawa ng shortcut)

LESSON 2: ARRAYS
Terms:
A. Array
Special type of variable that holds a value
B. Element
Number inside the brackets

Syntax:
variable name[no];

Programs:

1. To prompt the user to arrange a set of numbers in ascending order:

SYNTAX:

int a,x,y,number[10];
main()

clrscr();

p("ENTER:");

for(x=0;x<10;x++)

s("%d",&number[x]);

for(x=0;x<10;x++)

for(y=x+1;y<10;y++)

if(number[x]>number[y])

a=number[x];

number[x]=number[y];

number[y]=a;

p("The numbers are: ");

for(x=0;x<10;x++)

p("%d",number[x]);

getche();
}

2. Trace the output:

SYNTAX:

int x[10]={1,2,3,4,5,6,7,8,9,10};

int a, sum=0;

for(a=0; a<=10; a++)

sum=x[a];

p(%d\t%d\n,a+1,sum);

OUTPUT:

1_1

2_3

3_6

4_10

5_15

6_21

7_28

8_36

9_45

10_55

LESSON 3: FUNCTIONS
Terms:
A. Function
program designed to perform specific task
o Call tinawag lang
o Call Pass tinawag at nagbigay ng value
o Call Pass Return tinawag, binigyan ng value at binalik

B. Local Variable
variable that is used ONLY in the function
C. Global Variable
variable that can be used inside and outside the function
D. Void
Describes a function that returns no value at all
(ginagamit lamang sa call)

(ginagamit to sa call pass)


E. Parameter
variable inside the ( )
F. Actual Parameter
expression used inside the ( )
G. Formal Parameter
an identifier that corresponds to actual heading in a function heading

CALL

1. To compute and display the area of a square (given ang side)

SYNTAX:

void square( )

int x=5, area;

area=x*x;

p(%d,area);

main( )

clrscr();
square();

getche();

return 0;

2. To compute and display the area of a square (the user will enter the value
of the squares side)

SYNTAX:

void square( )

int x, area;

p(please enter the value of your squares sides:);

s(%d,&x);

area=x*x;

p(%d,area);

main( )

clrscr();

square();

getche();

return 0;

3. To compute and display the area of a cirle (the user will enter the value of
the circles radius)

SYNTAX:

void circle ( )

{
float x, area, pi=3.14;

p(please enter your circles radius:);

s(%f,x);

area=x*x*pi;

p(%f,area);

main ( )

clrscr();

circle();

getche();

return 0;

4. To compute volume of sphere (the user will enter the radius)

void sphere ( )

float x, vol, pi=3.14;

p(please enter your spheres radius:);

s(%f,x);

vol = 4/3*pi*x*x*x;

p(%f,area);

main ( )

clrscr();

sphere();
getche();

return 0;

(paulit ulit lang yan papalitan lang yung gagamitin sa equation)

Area of square = x*x;

Area of rectangle = (x*y)(wag kalimutan maglagay ng y variable)

Area of circle = pi*x*x

Volume of Sphere = 4/3*pi*x*x*x

Volume of Cylinder = pi*r*r*h

CALL + PASS

5. T o prompt the user to enter N factorial


SYNTAX:

fact (int a)

{
int facto=1, n;

for(n=1; n<=a; n++)

facto=facto*n;
p(%d,facto);
}

main ( )
{
clrscr();
int x;

p(please enter chuchu);


s(%d,&x);

factorial(x);
getche();
return 0;

6. To prompt the user to enter distance formula

SYNTAX:

int dist (int a, int b, int c, int d)

{
int dis;

dis=sqrt((a-b)(a-b) + (c-d)(c-d));

p(%d,dis);
}

main ( )
{
clrscr();

int w, x, y z;

p(please enter the values of your 2nd and 1st x respectively:);

s(%d%d,&w,&x);
p(please enter the values of your 2nd and 1st y respectively:);

s(%d%d,&y,&z);
dist(w,x,y,z);
getche();
return 0;

CALL PASS RETURN


1. To prompt the user to enter a numbers exponent (x being the base
and y being the exponent)

SYNTAX:

int expo (int a, int b)


{

int exp=1, n;

for(n=1; n<=b; n++)

exp=exp*b;

return exp;
}
main()

{
clrscr();

int x,y, A;
p(please enter the values of your x and y respectively:);
s(%d%d,&x,&y);

A=expo(a, b);
p(%d,A);
getche();
return 0;

!
2. To compute the permutation:
()!

SYNTAX:

int perm(int a, int b)

int n, o, p=1, r=1, s, permu;

for(n=1; n<=a; n++)

p=p*n;

o=a-b;
for(s=1; s<=o; s++)

{
r=r*s;

}
permu=p/r;

return permu;

}
main ( )

{
clrscr();
int x, y, wtf;
p(enter the value of your x and y respectively:);
s(%d%d,&x,&y);

wtf=perm(x,y);
p(%d,wtf);

getche();
return 0;
}

!
3. To compute the combination:
()! !

SYNTAX:

int com(int a, int b)

{
int m; n, o, p=1, q=1, r=1, s, combi;

for(n=1; n<=a; n++)


{

p=p*n;
}

for(m=1; m<=b; m++)

{
q=q*m;

}
o=a-b;
for(s=1; s<=o; s++)
{
r=r*s;

}
combi=p/(q*r);

return combi;
}
main ( )

clrscr();

int x, y, wtf;

p(enter the value of your x and y respectively:);

s(%d%d,&x,&y);
wtf=perm(x,y);

p(%d,wtf);

getche();
return 0;

CALL + PASS + POINTERS

1. To find the highest number among 10 numbers that will be entered:


SYNTAX:

void high(int *x,int *z)


{
int a=*z;
if(*x>=a)

{
a=*x;

}
*z=a;
}

main()

int x,y,z;

p("Enter: \n");

for(y=1;y<=10;y++)
{

s("%d",&x);

if(y==1)
{

z=x;
}
high(&x,&z);

p("\nThe Highest is: \n%d",z);

}
2. Lowest number

SYNTAX:
void low(int *x,int *z)
{
int a=*z;

if(*x<=a)
{

a=*x;
}
*z=a;

main()

int x,y,z;

p("Enter: \n");
for(y=1;y<=10;y++)

s("%d",&x);
if(y==1)

{
z=x;
}

low(&x,&z);

p("\nThe Lowest is: \n%d",z);


}

3. Finding the hypotenuse


SYNTAX:
void hype(float *x, float *y, float *z)
{

*x=*x**x;
*y=*y**y;

*z=sqrt(*x+*y);
}
main()

float x, y, z;

p("Enter: \n");

s("%f%f",&x,&y);

hype(&x,&y,&z);
p("\nThe Hypotenuse is: \n%f",z);

getche();

Вам также может понравиться