Tuesday, May 27, 2025
c program to copy array elements to another | Array examples
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
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:-
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:-
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:-