* Write a program create 6 elements integer array to store with user input.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[6],i;
clrscr();
printf("Enter 6 array elements are:\n");
for(i=0;i<6;i++)
scanf("%d",&a[i]);
printf("Array elements are:\n");
for(i=0;i<6;i++)
printf("%d\t",a[i]);
getch();
}
|
Output:-
* Write a program create 6 elements integer array and display sum of the array elements.
#include<stdio.h> #include<conio.h> void main() { int a[6],i,sum; clrscr(); printf("Enter a 6 array elements:\n"); for(i=0;i<6;i++) scanf("%d",&a[i]); sum=0; for(i=0;i<6;i++) sum=sum+a[i]; printf("sum of array elements=%d",sum); getch(); } |
Output:-
* Write a program to display even numbers & odd numbers in to an existing array.
#include<stdio.h> #include<conio.h> void main() { int a[50],i,n,even=0,odd=0; clrscr(); printf("Enter no of array elements are:\n"); scanf("%d",&n); printf("The %d array elements are:",n); for(i=0;i<6;i++) { scanf("%d",&a[i]); if(a[i]%2==0) even++; else odd++; } printf("Total even no's are:%d\n",even); printf("Total odd no's are:%d\n",odd); getch(); } |
Output:-
* Write a program create 6 elements integer array and display maximum of the array element.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[6],i,max;
clrscr();
printf("The 6 array elements are:");
for(i=0;i<6;i++)
{
scanf("%d",&a[i]);
}
max=a[0];
for(i=0;i<6;i++)
{
if(a[i]>max)
max=a[i];
}
printf("The maximum array value is:%d",max);
getch();
}
|
Output:-
* Write a program create 6 elements integer array and display minimum of the array element.
#include<stdio.h>
#include<conio.h>
void main()
{
int a[6],i,min;
clrscr();
printf("The 6 array elements are:");
for(i=0;i<6;i++)
{
scanf("%d",&a[i]);
}
min=a[0];
for(i=0;i<6;i++)
{
if(a[i]<min)
min=a[i];
}
printf("The minimum array value is:%d",min);
getch();
}
|
Output:-
________________________________________
_______________________________________________________________________________
Post a Comment