Print out a “Greetings!” message.
#include <stdio.h> int main() { printf("Greetings!\n"); return 0; }
Create a program that converts meters to feet.
#include <stdio.h> int main() { float meters; printf("Enter a measurement in meters: "); scanf("%f", &meters); float feet = meters * 3.28084; printf("%f meters is equal to %f feet.\n", meters, feet); return 0; }
Program a temperature conversion tool.
#include <stdio.h>
int main() {
float temperature;
char unit;
printf("Enter a temperature: ");
scanf("%f %c", &temperature, &unit);
if (unit == 'C') {
float fahrenheit = temperature * 9 / 5 + 32;
printf("%f degrees Celsius is equal to %f degrees Fahrenheit.\n", temperature, fahrenheit);
} else if (unit == 'F') {
float celsius = (temperature - 32) * 5 / 9;
printf("%f degrees Fahrenheit is equal to %f degrees Celsius.\n", temperature, celsius);
} else {
printf("Invalid unit.\n");
}
return 0;
}
Create a program that calculates the area of a circle.
#include <stdio.h>
int main() {
float radius;
printf("Enter the radius of a circle: ");
scanf("%f", &radius);
float area = 3.14159 * radius * radius;
printf("The area of the circle is %f.\n", area);
return 0;
}
Create a program that calculates the volume of a sphere.
#include <stdio.h>
int main() {
float radius;
printf("Enter the radius of a sphere: ");
scanf("%f", &radius);
float volume = 4 / 3 * 3.14159 * radius * radius * radius;
printf("The volume of the sphere is %f.\n", volume);
return 0;
}
Create a program that determines whether a number is prime.
#include <stdio.h>
int main() {
int number;
printf("Enter a number: ");
scanf("%d", &number);
int isPrime = 1;
for (int i = 2; i <= number / 2; i++) {
if (number % i == 0) {
isPrime = 0;
break;
}
}
if (isPrime) {
printf("%d is a prime number.\n", number);
} else {
printf("%d is not a prime number.\n", number);
}
return 0;
}