Solution using functions without passing arguments
Solution using functions and by passing arguments
Solution : Without using function
Program/Source Code
Program to take input for 10 elements using an array. Further display all the elements.
For better understanding of the above program one should have knowledge of
* for loop
* while loop
* do while loop
* Arrays
Problem In Hand
Problem In Hand
To take input for 10 elements using an array further display all the elements
Process and Solution Of Problem
* Using a for loop(any loop can be used) we take input for 10 elements
* again we use for loop to display all the elements
Program/Source Code
#include <stdio.h> int main() { int a[10],i; /* input */ for(i=0;i<10;i++) { printf("Enter %d element ",i); scanf("%d",&a[i]); } /* display */ for(i=0;i<10;i++) { printf("%d\n",a[i]); } return 0; }
Program Explanation
* As we have to take input for 10 elements we declare an array of size 10.
* memory locations are created from 0 to 9 i.e. a[0] to a[9].
* Now using a for loop we take input for elements
* further we use for loop again to dislay the elements
Output:
Enter 0 element 10
Enter 1 element 20
Enter 2 element 30
Enter 3 element 40
Enter 4 element 50
Enter 5 element 60
Enter 6 element 70
Enter 7 element 80
Enter 8 element 90
Enter 9 element 100
10
20
30
40
50
60
70
80
90
100
Solution : Using function Without Passing Arguments
Program/Source Code
For better understanding of the above program one should have knowledge of
* for loop
* while loop
* do while loop
* Function
* Arrays
#include <stdio.h>
void check()
{
int a[10],i;
/* input */
for(i=0;i<10;i++)
{
printf("Enter %d element ",i);
scanf("%d",&a[i]);
}
/* display */
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
}
int main()
{
check();
return 0;
}
Output:
#include <stdio.h> void check() { int a[10],i; /* input */ for(i=0;i<10;i++) { printf("Enter %d element ",i); scanf("%d",&a[i]); } /* display */ for(i=0;i<10;i++) { printf("%d\n",a[i]); } } int main() { check(); return 0; }
Output:
Enter 0 element 25
Enter 1 element 63
Enter 2 element 45
Enter 3 element 2
Enter 4 element 95
Enter 5 element 6
Enter 6 element 3
Enter 7 element 25
Enter 8 element 6
Enter 9 element 25
25
63
45
2
95
6
3
25
6
25
Solution : Using function Passing Arguments
Program/Source Code
For better understanding of the above program one should have knowledge of
* for loop
* while loop
* do while loop
* Function
* Arrays
#include <stdio.h>
void input(int a[],int n)
{
int i;
for(i=0;i<10;i++)
{
printf("Enter %d element ",i);
scanf("%d",&a[i]);
}
}
void show(int a[],int n)
{
int i;
for(i=0;i<10;i++)
{
printf("%d\n",a[i]);
}
}
int main()
{
int a[10];
input(a,110);
show(a,10);
return 0;
}
Output:
#include <stdio.h> void input(int a[],int n) { int i; for(i=0;i<10;i++) { printf("Enter %d element ",i); scanf("%d",&a[i]); } } void show(int a[],int n) { int i; for(i=0;i<10;i++) { printf("%d\n",a[i]); } } int main() { int a[10]; input(a,110); show(a,10); return 0; }
Output:
Enter 0 element 2
Enter 1 element 3
Enter 2 element 6
Enter 3 element 5
Enter 4 element 9
Enter 5 element 6
Enter 6 element 3
Enter 7 element 5
Enter 8 element 2
Enter 9 element 3
2
3
6
5
9
6
3
5
2
3
You May Also Like:
C Program to Check Number is multiple of 7 or not
C Program to Find Factorial of Number Using Loop
C Program to Print Fibonacci Series
C Program to check character is an alphabet or not
C Language Program for Prime Number
Next : Program to take input for 10 elements using an array, display all the elements also calculate and print sum of all the elements.
Programming Solutions @ rajeshshukla
Tutorials | Technical Questions | Interview Questions |
---|---|---|
C Programming C++ Programming Class 11 (Python) Class 12 (Python) |
C Language C++ Programming Python |
C Interview Questions C++ Interview Questions C Programs C++ Programs |