Programming basics
Programming basics
Output text.
Write a statement that prints the following on a single output line (without a newline):
Ready, Set, Go!
#include <stdio.h>
int main(void) {
printf("Ready, Set, Go!");
return 0;
}
Write code that prints the following. End each output line with a newline.
A4
E8
#include <stdio.h>
int main(void) {
printf("A4\n");
printf("E8\n");
return 0;
}
Output variable.
Write a statement that outputs variable userNum. End with a newline.
#include <stdio.h>
int main(void) {
int userNum;
userNum = 15; // Program will be tested with values: 15, 40.
printf("%d\n", userNum);
return 0;
}
Write a statement that outputs variable numPens as follows. End with a newline.
There are 10 pens.
#include <stdio.h>
int main(void) {
int numPens;
numPens = 10; // Program will be tested with values: 10, 33.
printf("There are %d pens.\n", numPens); //%d tells the program to print the value of numPens
return 0;
}
Read multiple user inputs.
Write two scanf statements to get input values into birthMonth and birthYear. Then write a statement to output the month, a slash, and the year. End with newline.
#include <stdio.h>
int main(void) {
int birthMonth;
int birthYear;
scanf("%d", &birthMonth);
scanf("%d", &birthYear);
printf("%d/%d\n", birthMonth, birthYear);
return 0;
}
Contact Me
thebookdale@gmail.com