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();
}
#include <conio.h>
void main()
{
int a;
printf("Enter an integer\n");
scanf("%d", &a);
printf("The integer is: %d\n", a);
getch();
}
C program to print first hundred positive integers [1, 100] using a for loop:
#include <stdio.h>
#include <conio.h>
void main()
{
int c;
{
int c;
for (c = 1; c <= 100; c++)
printf("%d ", 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);
{
char n[500];
printf("Input an integer\n");
scanf("%s", n);
printf("%s", n);
getch();
}
}
No comments:
Post a Comment