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