Basic

Write a C program to print an integer

Write a C program to print an integer

In this tutorial, we will discuss a simple concept of Write a C program to print an integer – entered by user

In this post, we are going to learn about how to print a integer number entered by user in C programming language

C program to print an integer

The value is stored in a variable num using scanf() function and it is displayed on the screen usint printf() function

Program 1

Program 1

#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num; //variable declaration
    printf("Enter an integer: \n");
    //printf() displays the formatted output

    scanf("%d",&num);
    //scanf() reads the formatted input

    printf("you entered  %d",num);
    getch();
    return 0;
}

When the above code is executed, it produces the following results

Enter an integer
56
you entered 56

 

In the C program, the user can enter a value using scanf() function and the value stored in a variable named as num. then, the value prints using printf() function.

 

In this program, printf() function provides a piece of information to the user to entering an integer value

printf("Enter an integer: \n");

The scanf() function reads an integer data from the user and stores in variable num

scanf("%d",&num);

Finally, the value stored in the variable num is displayed on the screen  by using printf() function

printf("you entered %d",num);

Recommended post

Write a Java program to print an integer

Write a Cpp program to print an integer

Write a Python program to print an integer

 

Suggested for you

C data types

C variable

C input output

 

Write a Java program to print an integer
Write a Cpp program to print an integer
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

Recent Posts

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago