Review: Variables (a)
Instructions: Think about each question and write the answer in your notebook.
General Questions
1. Which of these numbers is an integer variable? 5.4, 9.7888, 432, or 32 5/8
2. You can store any number from -32,768 to +32,768 if your computer stores integers in how many bytes of memory?
3. What is the format specifier for integers?
4. What function do we use to assign a variable to viewer input?
5. What symbol do we use to assign a variable?
Integer Variables
1. Fix the errors in this C source code. There are 4 errors.
|
include <stdio.c> void main( ) { int year = 1948; printf("\nThe UN adopted the Universal Declaration of Human Rights in %d.\n", year)
|
2. Fix the errors in this C source code. There are 3 errors.
|
#include <stdio.h> void ( ) int articles = 30; printf("\nThe Universal Declaration of Human Rights contains %d Articles.\n", parts); }
|
3. Fix the errors in this C source code. There are 2 errors.
|
#include <stdin.h> void main { int year = 1920; printf("\nIn %d the 19th Amendment was ratified, granting women the right to vote.\n", year); }
|
4. Fix the errors in this C source code. There are 3 errors.
|
#include <stdio.h>
void main( )
{
int year = 1960;
print("\nNigeria achieved independence in %i.\n", date);
}
|
Working with Viewer Input
1. Fix the errors in this C source code. There are 4 errors.
|
#include <stdio.h>
void main( )
{
printf("\nHow old are you? ");
scan("%d", age);
printf("\nYou are % years old.\n", age);
}
|
2. Fix the errors in this C source code. There are three errors.
|
#include <stdio.h>
void main( )
{
int sisters;
printf("\nHow many sisters do you have?);
scanf("d", &sisters);
printf("\nYou have %d sisters.\n");
}
|
Arithmetic Operators
1. Fix the errors in this C source code. There are 2 errors.
|
#include <stdio.h>
void main( )
{
int current;
int time;
printf("\nWhat is the current year? ");
scanf("%d", ¤t);
time = year - 1957;
printf("\nThe West African nation of Gambia acheived independence %d years ago.", time)
}
|
2. Fix the errors in this C source code. There are 3 errors.
|
#include <stdio.h>
void main( )
{
int beginning = 1403;
int end = 1911;
int emperors = 24;
printf("\n24 emperors ruled China from the Forbidden City between %d and %d.", beginning);
average = (end - begin) / emperors;
printf("\nEmperors ruled for an average of %d years.", average);
}
|