-->
Showing posts with label 1D Array. Show all posts
Showing posts with label 1D Array. Show all posts

Tuesday, May 27, 2025

c program to copy array elements to another | Array examples

Array programs in C


/* program to copy one array elements to another

*/
#include<stdio.h>
int main()
{
int a[5];
int b[5];
int i;
for(i=0;i<=4;i++)
{
printf("enter elment for %d location",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
b[i]=a[i];
}
printf("the copied elements are:\n");
for(i=0;i<=4;i++)
{
printf(" %d ",b[i]);
}
return 0;
}

Output:-

C program to copy array elements to another array



Tuesday, May 20, 2025

c program to print maximum and minimum value | Array examples

 C array programs

//array program to input 5 numbers and to print maximum and minimum value

#include<stdio.h>
#define size 5
int main()
{
int a[size];//array declaration with size 5
int i,max,min;
for(i=0;i<=4;i++)
{
printf(" enter value for location=%d\n",i+1);
scanf("%d",&a[i]);//inputs
}
max=a[0];//assigning first value to max and min
min=a[0];
for(i=0;i<=4;i++)
{
if(max<a[i])//comparing and changing the old value
{
max=a[i];
}
if(min>a[i])//comparing and assigning new value
{
min=a[i];
}
}
printf("the max value=%d and minimum value is %d",max,min);//printing
return 0;
}

Output:-



C program to copy one array element to another | Array examples

Array programs in C

C program to copy one array elements to another 

/* program to copy one array element to another
*/

#include<stdio.h>
int main()
{
int a[5];
int b[5];
int i;
for(i=0;i<=4;i++)
{
printf("enter elment for %d location",i+1);
scanf("%d",&a[i]);
}
for(i=0;i<=4;i++)
{
b[i]=a[i];
}
printf("the copied elements are:\n");
for(i=0;i<=4;i++)
{
printf(" %d ",b[i]);
}
return 0;
}


Output:-

c program to copy elements to another array



Monday, May 19, 2025

C Program to Input elements and to find average value using array-1D array concept

 

C program to input elements and to find average 


//array input and printing average value

#include<stdio.h>

int main()

{

int a[5];//array declaration

int i,sum=0;//variable declaration

float average;//float to store average

for(i=0;i<=4;i++)

{

printf(" enter value for location=%d\n",i+1);

scanf("%d",&a[i]);//input for given array

sum+=a[i]; //finding sum

}

average=(float)sum/5; //type casting and storing average in variable

printf("the average value is=%f",average);//printng result

return 0;

}

Output:-

C program to find average of five elements using array



second method:

//array input and printing average value. Here, we will use define for size.

#include<stdio.h>
#define size 5
int main()
{
int a[size];//array declaration with size as an index value. It takes the value from define
int i,sum=0;//variable declaration
float average;//float to store average
for(i=0;i<=4;i++)
{
printf(" enter value for location=%d\n",i+1);
scanf("%d",&a[i]);//input for given array
sum+=a[i]; //finding sum
}
average=(float)sum/5; //type casting and storing average in variable
printf("the average value is=%f",average);//printng result
return 0;
}





Sunday, May 18, 2025

C Program – 1D Array Input and Output with Simple Examples

array input in C program 


// 1Dimensional (1D) array input


#include<stdio.h>
int main()
{
int a[5];//array declaration of size 5
int i;
for(i=0;i<=4;i++)//loop
{
printf(" enter value for location=%d\n",i+1);//message display
scanf("%d",&a[i]);//input
}
for(i=0;i<=4;i++)
{
printf("%d\t",a[i]);//printing the values
}
return 0;
}


Output:-