Different ways to print integer in C

You are currently viewing Different ways to print integer in C

In this C programming article we will learn to print integer in different way. We can print an integer using printf().

We will take the input from user using scanf() and then we can print that int by printf() in C programming.

#include <stdio.h>
int main(){
  int x;        // variable declaration

  printf("Enter an integer here : ");
  scanf("%d", &x);      // taking input and store it to integer x

  printf("\nYou have entered the integer %d\n", x);     // printing integer

  return 0;
}

Output of this print integer program

1 printing integer in C programming, print integer

Print integer using loop in C

#include <stdio.h>
int main(){
  int i;       // variable declaration

  for (i = 1; i <= 100; i++)
    printf("%d ", i);        // printing integers

  return 0;
}

Output of this C program

2 printing integer in C programming, print integer

C program to store an integer in a string and print

#include <stdio.h>
int main (){

   char numbers[1000];

   printf("Input a large integer here : ");
   scanf("%s", numbers);       // taking string inpute

   printf("\nYou have entered the integer = %s\n", numbers);   // printing

   return 0;
}

See the output

You can print any integer using other methods too. So, try to write a program in your own.

Leave a Reply