basic

Write a C program to print an integer

Write a C program to print an integer

problem – How to write a C program to print an integer?

In this tutorial, we discuss the simple concept of C program to print an integer

input-output

In this article, we are going to learn how to write a C program to print an integer

The following shows two different ways to How to write a C program to print an integer and there is an example given to each

The first Example is done by declared and initialized the variable

The second Example is done through the user entered the value of the variables

C code to print an integer

Program 1

//C program to print an integer
#include <stdio.h>
#include <stdlib.h>

int main()
{
    int num;//variable declaration
    num=67; //initialization
    printf("You declared: %d\n",num);
    getch();
    return 0;
}

When the above code is executed it produces the following output

You declared: 67;

In this program,

  • Integer variable num is declared
  • Integer variable num is initialized
  • Then, the program has Displayed the output (value of variable num ) using  printf() function

C code print an integer(Entered by user)

Program 2

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

int main()
{
    int num;//variable declaration
   
    printf("Enter the integer to display: ");
    scanf("%d",&num);
    printf("You entered: %d \n",num);
    getch();
    return 0;
}

When the above code is executed it produces the following output

Enter the integer to display: 125
You ebtered: 125

Method

  1. The program requires input from the user
  2. Then the user enters the input value
  3. The program will read the input using scanf() and stores in the num variable
  4. Then, the program Display the value which  is in variable num using printf() function

 

Similar post

C++ program to print an integer

Java program to print an integer

Python program to print an integer

 

Suggested post

Operator C language

Hello world program in C language

Data type in C language

 

Karmehavannan

Recent Posts

Subtract two numbers using method overriding

Subtract two numbers using method overriding   Program 1

4 weeks ago

PHP Star triangle Pattern program

PHP Star triangle Pattern program Here's a simple Java program that demonstrates how to print…

4 weeks ago

Using function or method to Write temperature conversion : Fahrenheit into Celsius

Using Function or Method to Write to temperature conversion: Fahrenheit into Celsius In this article,…

1 year ago

Function or method:temperature conversion from Fahrenheit into Celsius – Entered by user

Function or method of temperature conversion from Fahrenheit into Celsius In this article, we will…

1 year ago

Write temperature conversion program: Fahrenheit into Celsius

Write temperature conversion program: from Fahrenheit to Celsius In this article, we will discuss the…

1 year ago

How to write a program to convert Fahrenheit into Celsius

How to write a program to convert Fahrenheit into Celsius In this article, we will…

1 year ago

This website uses cookies.