Write a program to display all array elements.
using function
Recursion recursion
using function
- #include <stdio.h>
- int input(int *arr, int n)
- {
- int i;
- for(i=0; i<n; i++) {
- scanf("%d", &arr[i]);
- }
- }
- int display(int *arr, int n)
- {
- int i;
- for(i=0; i<n; i++) {
- printf("%5d", arr[i]);
- }
- }
- int main()
- {
- int arr[100], i, n;
- printf("Enter the size of array: ");
- scanf("%d", &n);
- printf("Enter %d elements in the array : ", n);
- input(arr, n);
- printf("\nElements in array are : ");
- display(arr, n);
- return 0;
- }
Recursion recursion
- #include <stdio.h>
- int input(int *arr,int i, int n)
- {
- if(i<n) {
- scanf("%d", &arr[i]);
- input(arr, i+1, n);
- }
- }
- int display(int *arr,int i,int n)
- {
- if(i<n) {
- printf("%d ", arr[i]);
- display(arr,i+1,n);
- }
- }
- int main()
- {
- int arr[100],i,n;
- printf("Enter the size of array: ");
- scanf("%d", &n);
- printf("Enter %d elements in the array : ", n);
- input(arr,0,n);
- printf("\nElements in array are: ");
- display(arr, 0, n);
- return 0;
- }
একটি মন্তব্য পোস্ট করুন