Identify two errors in the program below and describe how to correct them.
#include <stdio.h>
int main()
{
char aWord[50];
printf("Enter a word and press enter: ");
scanf("%s", &aWord);
printf("The words is: %C\n", aWord);
}
List two examples of an algorithm
Define problem domain
Write the output of the following program
#include <stdio.h>
int main()
{
int number = 0;
while (number < 5)
{
if (number % 2 == 0)
{
printf("even\n");
}
else
{
printf("%d\n", number);
}
number = number + 1;
}
}
Write the output of the following program
#include <stdio.h>
int main()
{
int number = 1;
int previous1 = 1;
int previous2 = 0;
while (number < 7)
{
int current = previous1 + previous2;
printf("%d\n", current);
previous2 = previous1;
previous1 = current;
number = number + 1;
}
}
Identify the error in the following program and describe how you would correct
it:
#include <stdio.h>
int main()
{
int number = 0;
printf("The first ten integers starting at 0 are:\n");
while (number < 10)
{
printf("%d\n", number);
}
}
Identify the error in the following program and describe how you would correct
it:
#include <stdio.h>
int main()
{
int number = 0;
while (number < 0)
{
printf("Enter a non negative integer: ");
scanf("%d", &number);
}
printf("You entered: %d\n", number);
}
Write the output of the following program:
#include <stdio.h>
int main()
{
int number = 0;
while (number < 10)
{
if (number % 2 == 0 && number >= 4)
{
printf("%d\n", number);
}
number = number + 1;
}
}
Write the output of the following program:
#include <stdio.h>
int main()
{
int number = 0;
while (number < 10)
{
if (number % 2 == 0 || number >= 4)
{
printf("%d\n", number);
}
number = number + 1;
}
}
Write the output of the following program:
#include <stdio.h>
int main()
{
int numbers[5] = {4, 6, 8, 1, 5};
int currentIndex = 1;
int val = numbers[0];
while (currentIndex < 5)
{
if (numbers[currentIndex] > val)
{
val = numbers[currentIndex];
}
currentIndex = currentIndex + 1;
}
printf("%d\n", val);
}
Identify the errors in the following program and describe how to correct them
#include <stdio.h>
int main()
{
int numbers[5] = {1, 7, 3, 2, 7};
printf("Printing 5 values in the array:\n");
int currentIndex = 0;
while (currentIndex <= 5)
{
currentIndex += 1;
printf("%d\n", numbers[currentIndex]);
}
}