Skip to content
Menu
Code for Java c
  • Home
  • Java
    • Java Examples
    • Java tutorials
  • C
    • C tutorials
    • C Examples
  • C++
    • C++ Tutorials
    • C++ Examples
  • Python
    • Python Tutorials
    • Python Examples
  • About
    • About me
    • contact us
    • disclaimer
    • Privacy Policy
Code for Java c
C++ Program to fill an array of characters from user

C program :How to take user input for integer array

Posted on November 27, 2021November 27, 2021

Table of Contents

  • C program :How to take user input for integer array
    • Code to input integer of an array
      • Code to input integer for an array using for loop
      • Code to input integer for an array using while loop
      • Code to input integer for an array using do-while loop
    • Related

C program :How to take user input for integer array

In this article, we will discuss the concept of C program :How to take user input for integer array

In this post, we are going to learn how to write a program to  input  integer in an array from user e   using for, while and do-while  loop

Code to input integer of an array

Code to input integer for an array using for loop

In this code, we are going to learn how to input integer in an integer array using for loop in C language

Program 1

#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1000 //Maximum size of the array

int main()
{
    int arr[MAX_SIZE];//Declare an array of MAX_SIZE
    int i,N;
    printf("Enter size of array\n");//Read size of the array
    scanf("%d",&N);

    printf("Enter %d elements in the array\n",N);
    //Read elements of the array
    for(i=0; i<N; i++){
            printf("Enter arr[%d] element in the array: ",i);
        scanf("%d",&arr[i]);
    }
    printf("\nEntered elements of an array\n");
    //print given elements of the array
    for(i=0; i<N; i++){
        printf("%d\n",arr[i]);
    }
    getch();
    return 0;
}

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

Enter size of array
5

Enter 5 elements in the array
Enter arr[0] element in the array: 13
Enter arr[1] element in the array: 43
Enter arr[2] element in the array: 56
Enter arr[3] element in the array: 76
Enter arr[4] element in the array: 78

Entered elements of an array
13
43
56
76
78

 

Code to input integer for an array using while loop

In this code, we are going to learn how to input integer in an integer array using while loop in C language

Program 2

#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1000 //Maximum size of the array

int main()
{
    int arr[MAX_SIZE];//Declare an array of MAX_SIZE
    int i,N;
    printf("Enter size of array\n");//Read size of the array
    scanf("%d",&N);

    printf("Enter %d elements in the array\n",N);
    //Read elements of the array
    i=0;
    while(i<N){
            printf("Enter arr[%d] element in the array: ",i);
        scanf("%d",&arr[i]);
         i++;
    }
    printf("\nEntered elements of an array\n");
    //print given elements of the array
    i=0;
    while(i<N){
        printf("%d\n",arr[i]);
         i++;
    }
    getch();
    return 0;
}

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

Enter size of array
6

Enter 6 elements in the array
Enter arr[0] element in the array: 134
Enter arr[1] element in the array: 567
Enter arr[2] element in the array: 789
Enter arr[3] element in the array: 980
Enter arr[4] element in the array: 654
Enter arr[5] element in the array: 345

Entered elements of an array
134
567
789
980
654
345

 

Code to input integer for an array using do-while loop

In this code, we are going to learn how to input integer in an integer array using do-while loop in C language

Program 3

#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 1000 //Maximum size of the array

int main()
{
    int arr[MAX_SIZE];//Declare an array of MAX_SIZE
    int i,N;
    printf("Enter size of array\n");//Read size of the array
    scanf("%d",&N);

    printf("Enter %d elements in the array\n",N);
    //Read elements of the array
    i=0;
    do{
            printf("Enter arr[%d] element in the array: ",i);
        scanf("%d",&arr[i]);
         i++;
    }while(i<N);
    printf("\nEntered elements of an array\n");
    //print given elements of the array
    i=0;
   do{
        printf("%d\n",arr[i]);
         i++;
    } while(i<N);
    getch();
    return 0;
}

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

Enter size of array
4

Enter 4 elements in the array
Enter arr[0] element in the array: 2345
Enter arr[1] element in the array: 6789
Enter arr[2] element in the array: 9876
Enter arr[3] element in the array: 7654

Entered elements of an array
2345
6789
9876
7654


Suggested for you

For loop in C language

while loop in c language

do-while loop in c language

Operator in C language

One dimensional array in C language

 

For loop in C++ language

while loop in C++ language

Do while loop in C++ language

Operator in C++ language

One dimensional array in C++ language

 

For loop in Java language

While loop in Java language

Do-while loop in Java language

Operator in Java language

Variable in Java language

Data type in Java language

class and main method in Java

One dimensional array in Java

 

Similar post

Java program to read and print array elements using for loop

Java program to read and print array elements using while loop

Java program to read and print array elements using Do-while loop

C code to take and print array elements using for loop

C code to take and print array elements using while loop

C code to take and print array elements using do-while loop

C++ program to read and print array elements using for loop

C++ program to read and print array elements using while loop

C++ program to read and print array elements using do-while loop

 

 

 

 

 

 

Related

Recent Posts

  • Multiply two numbers in Java using scanner| 5 different ways
  • 5 different ways to Divide two numbers in Java using scanner
  • Learn 8 Ways to Subtract Two Numbers Using Methods in Java
  • 10 ways to subtract two numbers in Java
  • Java Code Examples – Multiply Two Numbers in 5 Easy Ways
  • How to Divide two numbers in Java| 5 different ways

tag

Addition (8) Array (38) C++ language (91) C language (98) c sharp (23) Division (8) Function (29) if else (32) Java language (108) JavaScript (5) loops (138) Multiply (8) Oop (2) patterns (66) PHP (13) Python Language (38) Subtraction (9) temperature (20)

Archives

Categories

Address

Global information technology

Puloly south, PointPedro

Jaffna

Srilanka

©2026 Code for Java c | Powered by SuperbThemes