Print an intezer in C

Print an integer in C language:

A user inputs an integer, and we print it. Input is done using scanf function, and the number is printed on screen using printf.




C program to print an integer

#include <stdio.h>
#include <conio.h> 
void main()
{
  int a;

  printf("Enter an integer\n");
  scanf("%d", &a);

  printf("The integer is: %d\n", a);

  getch();
}

Output :-


C program to print first hundred positive integers [1, 100] using a for loop:

#include <stdio.h>
#include <conio.h>

void main()
{
  int c;
  for (= 1; c <= 100; c++)
    printf("%d ", c);
  getch();
}

C program to store an intezer as array

#include <stdio.h>
#include <conio.h>
void main()
{
   char n[500];
   
   printf("Input an integer\n");
   scanf("%s", n);
   
   printf("%s", n);
   getch();
}


Output :-

No comments:

Post a Comment