Friday, October 28, 2011

if else statement condition

Condition - is the state of an expression or a variable; for example, when a result can be either true or
                false, or not equal.
if else statement – this is a control statement that executes a block of code.
                Syntax:
                                if (condition)
                                                statement1;
                                else
                                                statement2;

scanf(); used to read information from the keyboard
scanf(“%f”)  float, scanf(“%c”) character & symbol
clrscr(); -is used to clear the text mode window or to clean the output screen before running a program.

=============================================================================
This program will input 2 numbers, using the ”if else statement”  you can use this following
operators ( +, -, /, *)

//Sample Program1:
#include<stdio.h>
#include<conio.h>

main()
{
int invalid_operator=0;
char oprtor;
float num1, num2, result;
printf(Enter two numbers and an operator?\n");
printf("number1 operator number2\n");
scanf("%f %c %f",&num1,&oprtor,&num2);
                 if(oprtor=='*')
                                                result=num1 *num2;
                 else if (oprtor=='/')
                                                result=num1/num2;
                 else if (oprtor=='+')
                                                result=num1+num2;
                 else if (oprtor=='-')
                                                result=num1-num2;
                 else
                                invalid_operator=1;
                                if(invalid_operator!=1)
                                printf("%f %c %f is %f\n",num1,oprtor,num2, result);
                                else printf("invalid operator");
getche();
return 0;
}

Sample output:

Enter two numbers and an operator
number1 operator number2
4.0000 + 2.0000 is 6.0000
Enter two numbers and an operator
number1 operator number2
4.0000 * 2.0000 is 8.0000

Variable Declaration


Variable – refers to the named area in memory that stores a value or string assigned to that variable.

Ways to declare variable:
Global variable – outside of all functions, including the main() function
Local variable – inside a function; variables may only be used by statements that are in the same
 functions
Formal parameters
Data type – a set of data that specifies the possible range values of the set, the operations that
can be performed on the values, and the way in which values are stored in memory.
clrscr(); -is used to clear the text mode window or to clean the output screen before running a
program.

Data type
Control String
Description
Example
Char
“%c”
used for outputting letter or symbol
‘w’, ‘y’
Char
“%s”
used for outputting 2 or
more letters or symbols
and alphanumeric
‘Melo’, ‘P103’,
‘prof_melo’
Int
“%d”
used for outputting
 whole numbers
8, 12, -5, 12854
Float
“%f”
used for outputting number
 w/ decimal places
8.12, 16.09,
-23.812
Double
“%f”
used for outputting larger
number w/ or without decimal places
81256381225,
1276812.83
                                                                                                                                       
Operator – is a symbol that tells the compiler to perform specific mathematical or logical manipulations
+
Addition
-
Subtraction
*
Multiplication
/
Division
%
Modulus of remainder
Div
Integer division
Mode
Integer remainder
++/--
Increment and decrement

Relational operators – are used to determine the relationship of one quantity to another.
< 
Less than
<=
Less that or equal to
> 
Greater than
>=
Greater than or equal to
==
Equal to
!=
Not equal to
=
Assignment operators

Logical operators – are used to show the ways through which these relationships can be connected.
&&
AND
||
OR
!
NOT

==========================================
This program will compute the general average.

#include<stdio.h>
#include<conio.h>
main()
{
int pgrade, mgrade, sfgrade, fgrade, gaverage;
float avrage;

printf("\nEnter your Grade");
printf("\nPrelim Grade  => ");scanf("%d",&pgrade);
printf("Midterm Grade => ");scanf("%d",&mgrade);
printf("S_final Grade => ");scanf("%d",&sfgrade);
printf("Final Grade   => ");scanf("%d",&fgrade);
 gaverage=pgrade+mgrade+sfgrade+fgrade
 avrage=gaverage/4;
printf("\nGeneral Average => %.2f",avrage);                         //%.2f numbers w/ 2 decimal places
getche();
return 0;
}

Sample output:

Enter your Grade
Prelim Grade    => 89
Midterm Grade => 89
S_final Grade   => 89
Final Grade      => 89
General Average =>  89

Thursday, October 27, 2011

Parts of Computer System

Computer system in contemporary usage refers to a desktop system, including the computer itself ("The CPU" or "The Box") and all the peripheral devices needed to operate it, usually including:


Monitor
A monitor displays information in visual form, using text and graphics. The portion of the monitor that displays the information is called the screen. Like a television screen, a computer screen can show still or moving pictures.
There are two basic types of monitors: CRT (cathode ray tube) monitors and LCD (liquid crystal display) monitors.
//