147k views
2 votes
write a C program that declares an integer variable called "favorite_number". The program should then prompt the user to enter their favorite number, and use scanf to read the user's input into favorite_number. Finally, the program should print a message that includes the user's input.

User BlueBear
by
6.8k points

2 Answers

3 votes

CODE

#include <stdio.h>

int main() {

int favorite_number;

printf("Enter your favorite number: ");

scanf("%d", &favorite_number);

printf("The chosen number is %d.", favorite_number);

return 0;

}

DISPLAY

Enter your favorite number: 19

The chosen number is 19.

EXPLANATION

Declare the variable favorite_number as an integer type.

Using printf and scanf, ask the user to input their favorite number.

Print the number on the screen.

Return an integer value.

User Kissinger
by
7.3k points
4 votes

Answer:

// here is code in C.

// headers

#include <stdio.h>

// main function

int main(void) {

// variable declaration

int favorite_number;

// ask user to enter favorite number

printf("enter your favorite number : ");

// read the number

scanf("%d",&favorite_number);

// print the message

printf("your favorite number is: %d",favorite_number);

return 0;

}

Step-by-step explanation:

Declare a variable "favorite_number" of integer type.Ask user to enter favorite number and assign it to favorite_number.Then print the message which include the favorite number.

Output:

enter your favorite number : 77

your favorite number is: 77

User Adrian Godong
by
7.1k points