Ict Reviewer: Lesson 1: Random Function
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
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;
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;
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)
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:
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;
for(x=0;x<10;x++)
p("%d",number[x]);
getche();
}
SYNTAX:
int x[10]={1,2,3,4,5,6,7,8,9,10};
int a, sum=0;
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)
CALL
SYNTAX:
void square( )
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;
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;
s(%f,x);
area=x*x*pi;
p(%f,area);
main ( )
clrscr();
circle();
getche();
return 0;
void sphere ( )
s(%f,x);
vol = 4/3*pi*x*x*x;
p(%f,area);
main ( )
clrscr();
sphere();
getche();
return 0;
CALL + PASS
fact (int a)
{
int facto=1, n;
facto=facto*n;
p(%d,facto);
}
main ( )
{
clrscr();
int x;
factorial(x);
getche();
return 0;
SYNTAX:
{
int dis;
dis=sqrt((a-b)(a-b) + (c-d)(c-d));
p(%d,dis);
}
main ( )
{
clrscr();
int w, x, y z;
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;
SYNTAX:
int exp=1, 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:
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 m; n, o, p=1, q=1, r=1, s, combi;
p=p*n;
}
{
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;
s(%d%d,&x,&y);
wtf=perm(x,y);
p(%d,wtf);
getche();
return 0;
{
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);
}
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);
*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();