how array is declared and define . write the program to input the array of integer and display it.
Answers
Answered by
1
An array is a collection of fixed number of values of a single type. For example: if you want to store 100 integers in sequence, you can create an array for it.
int data[100];
The size and type of arrays cannot be changed after its declaration.
Arrays are of two types:
One-dimensional arrays
Multidimensional arrays (will be discussed in next chapter)
#include <stdio.h>
int main()
{ int avg = 0; int sum =0; int x=0;
/* Array- declaration – length 4*/
int num[4]; /* We are using a for loop to traverse through the array * while storing the entered values in the array */
for (x=0; x<4;x++)
{ printf("Enter number %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<4;x++)
{ sum = sum+num[x];
}
avg = sum/4;
printf("Average of entered number is: %d", avg);
return 0;
}
int data[100];
The size and type of arrays cannot be changed after its declaration.
Arrays are of two types:
One-dimensional arrays
Multidimensional arrays (will be discussed in next chapter)
#include <stdio.h>
int main()
{ int avg = 0; int sum =0; int x=0;
/* Array- declaration – length 4*/
int num[4]; /* We are using a for loop to traverse through the array * while storing the entered values in the array */
for (x=0; x<4;x++)
{ printf("Enter number %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<4;x++)
{ sum = sum+num[x];
}
avg = sum/4;
printf("Average of entered number is: %d", avg);
return 0;
}
abhay1951:
i have computer science in my 12
Answered by
1
Through these I hope u can able to write program
Attachments:
Similar questions
Math,
6 months ago
Physics,
6 months ago
Political Science,
1 year ago
Geography,
1 year ago
Hindi,
1 year ago