227k views
0 votes
Write a C program to declare two integers and one float variables then initialize them to 10, 15, and 12.6. It then prints these values on the screen

User Torge
by
5.0k points

2 Answers

1 vote

Final answer:

A C program has been provided that declares two integer variables and a float variable, initializes them with the given values, and prints them out. The program uses standard input/output headers and the printf function.

Step-by-step explanation:

The student has asked to write a C program that declares two integer variables and one float variable, initializes them with the values 10, 15, and 12.6 respectively, and then prints these values on the screen. Here is a simple program that accomplishes this task:

#include

int main() {
int num1 = 10; // Declare and initialize the first integer variable
int num2 = 15; // Declare and initialize the second integer variable
float num3 = 12.6; // Declare and initialize the float variable

printf("Integer 1: %d\\", num1); // Print the first integer
printf("Integer 2: %d\\", num2); // Print the second integer
printf("Float: %f\\", num3); // Print the float

return 0;
}
When run, this program will display the values of the variables on your screen.

User Rafael Mora
by
5.4k points
6 votes

Answer:

pretty simple, notice, I used '1f' so the float would print only 1 significant number after. Sure you can modify it to make it more readable and not just numbers on the screen, it's up to you

Step-by-step explanation:

#include <stdio.h>

int main()

{

int n1 = 10;

int n2 = 15;

float f1 = 12.6;

printf("%d %d %.1f", n1, n2, f1);

return 0;

}

User Abatishchev
by
6.2k points