En Course Variables Input Output
En Course Variables Input Output
Mohamed MESSABIHI
[email protected]
University of Tlemcen
Department of Computer Science
https://sites.google.com/site/informatiquemessabihi/
Variable
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Naming Variables
In most programming languages, there are some constraints and
conventions to follow when naming variables:
• You can only use lowercase and uppercase letters and numbers
(abcABC012);
• Spaces are not allowed. Instead, you can use the underscore
character _. It is the only character different from letters and
numbers that is allowed;
Example
Which variable names are correct: age, mail, name, score, my-book,
phone_number, prénom, main.
Some Good Practices for Naming Your Variables
• If there are multiple words in the variable name, capitalize the first
letter of each new word. For example: bookTitle or
lastChangedParameter
• If there are multiple words in the variable name, capitalize the first
letter of each new word. For example: bookTitle or
lastChangedParameter
• If there are multiple words in the variable name, capitalize the first
letter of each new word. For example: bookTitle or
lastChangedParameter
• If there are multiple words in the variable name, capitalize the first
letter of each new word. For example: bookTitle or
lastChangedParameter
Example:
int main ()
{
int age ;
double salary ;
unsigned int sum , studentNumber , coefficient ;
return 0;
}
Declaring a Variable
You must declare variables at the beginning of functions. Just do the
following:
1. Specify the type of the variable you want to create;
2. Insert a space;
3. Specify the name you want to give to the variable;
4. Finally, don’t forget the semicolon.
Example:
int main ()
{
int age ;
double salary ;
unsigned int sum , studentNumber , coefficient ;
return 0;
}
Declaring a Variable
You must declare variables at the beginning of functions. Just do the
following:
1. Specify the type of the variable you want to create;
2. Insert a space;
3. Specify the name you want to give to the variable;
4. Finally, don’t forget the semicolon.
Example:
int main ()
{
int age ;
double salary ;
unsigned int sum , studentNumber , coefficient ;
return 0;
}
Declaring a Variable
You must declare variables at the beginning of functions. Just do the
following:
1. Specify the type of the variable you want to create;
2. Insert a space;
3. Specify the name you want to give to the variable;
4. Finally, don’t forget the semicolon.
Example:
int main ()
{
int age ;
double salary ;
unsigned int sum , studentNumber , coefficient ;
return 0;
}
Declaring a Variable
You must declare variables at the beginning of functions. Just do the
following:
1. Specify the type of the variable you want to create;
2. Insert a space;
3. Specify the name you want to give to the variable;
4. Finally, don’t forget the semicolon.
Example:
int main ()
{
int age ;
double salary ;
unsigned int sum , studentNumber , coefficient ;
return 0;
}
Assigning a Value to a Variable
Simply specify the variable name, then an equal sign (=), and finally the
value you want to put there.
Example:
int main ()
{
int studen tNumbe rs ;
stu dentNu mbers = 240;
return 0;
}
Initializing a Variable
• When you declare a variable, what value does it have at the
beginning?
• Initializing a variable means combining the declaration and
assignment of that variable in the same statement
• The advantage is that you are sure that this variable contains a
correct value, not just anything.
Example:
int main ()
{
int studen tNumbe rs = 240;
return 0;
}
Initializing a Variable
• When you declare a variable, what value does it have at the
beginning?
• Initializing a variable means combining the declaration and
assignment of that variable in the same statement
• The advantage is that you are sure that this variable contains a
correct value, not just anything.
Example:
int main ()
{
int studen tNumbe rs = 240;
return 0;
}
Initializing a Variable
• When you declare a variable, what value does it have at the
beginning?
• Initializing a variable means combining the declaration and
assignment of that variable in the same statement
• The advantage is that you are sure that this variable contains a
correct value, not just anything.
Example:
int main ()
{
int studen tNumbe rs = 240;
return 0;
}
Initializing a Variable
• When you declare a variable, what value does it have at the
beginning?
• Initializing a variable means combining the declaration and
assignment of that variable in the same statement
• The advantage is that you are sure that this variable contains a
correct value, not just anything.
Example:
int main ()
{
int studen tNumbe rs = 240;
return 0;
}
Displaying a Variable
Example:
int main ()
{
int studen tNumbe rs = 240;
printf ( " Il y a % d etudiants inscrits . " ,
stud entNum bers ) ;
...
Example:
int main ()
{
int studen tNumbe rs = 240;
printf ( " Il y a % d etudiants inscrits . " ,
stud entNum bers ) ;
...
Example:
int main ()
{
int studen tNumbe rs = 240;
double average = 14.5 ;
return 0;
}
Ask the user to enter a value of a variable
• We use another ready-made function called scanf.
• This function is similar to printf. You must specify a format to
indicate what the user needs to enter (int, float, etc.)
• Then you must specify the name of the variable that will receive the
number.
Example:
int main ()
{
int age = 0;
scanf ( " % d " , & age ) ;
return 0;
}
Example:
int main ()
{
int age = 0;
scanf ( " % d " , & age ) ;
return 0;
}
Example:
int main ()
{
int age = 0;
scanf ( " % d " , & age ) ;
return 0;
}
Example:
int main ()
{
int age = 0;
scanf ( " % d " , & age ) ;
return 0;
}
Example:
int main ()
{
int age = 0;
scanf ( " % d " , & age ) ;
return 0;
}
Example:
int main ()
{
int age = 0;
scanf ( " % d " , & age ) ;
return 0;
}
A simple program that asks the user’s age and then displays it:
Example:
int main ()
{
int age = 0; // We initialize the variable to 0
return 0;
}
Simple Addition Calculator Program
Example:
int main ()
{
int result = 0 , number1 = 0 , number2 = 0;
return 0;
}