Posts

Showing posts with the label array

C Language | Array | Start your journey with C | Part 5

Image
Arrays in C : An array is collection of items of same datatype stored in a continuous block of memory under a variable name. Array declaration in C : We can declare an array by specifying the size with a variable or by directly initializing elements of the array or by both. all type of declaring example is show below : Array declaration by specifying size : // Array declaration by specifying size int var[10]; // With recent C versions, you can also // declare an array of user specified size int x = 10; int var[n]; Array declaration by initializing elements : // Array declaration by initializing elements int var[] = { 10, 20, 30, 40 } ; // Compiler creates an array of size 4. // above is same as "int var[4] = {10, 20, 30, 40}" An Example to show that array elements are stored at contiguous locations : #include<stdio.h> void main() { // an array of 10 integers. If var[0] is stored at /...

Find out Max and Min Array | C Program :

Image
Write a C Program to Print Max and Min of an Array : Code: #include<stdio.h> void main() { int max,min,a[20],i,n; printf("Enter size of array [max 20]:\n"); scanf("%d",&n); printf("Enter the elements:\n"); for(i=0;i<n;i++) scanf("%d",&a[i]); max=a[0]; min=a[0]; for(i=0;i<n;i++) { if(a[i]>max) max=a[i]; if(a[i]<min) min=a[i]; } printf("The max= %d and min= %d",max,min); } Output: