2. Write a C program using an online C compiler (or Dev C++) that implements the following:-
• Declare a 10-element floating-point array; give the array a suitable name.
• Declare an integer variable (of type int); call it i
• Upon declaration, populate the array with 10 floating-point numbers of your choice.
• Prompt the user to enter a value between 0 and 9
• Read a number from the keyboard into i
• Display the ith element of the array
#include<stdio.h>
int main(){
float point[10];
int i, k ;
printf("Populating the array\n");
for(k=0; k<10; k++){
printf("Element %d: ",(k+1));
scanf("%f", &point[k]);
}
printf("Enter a value between 0 and 9: ");
scanf("%d", &i);
printf("The ith element of the array is: %f", point[i]);
}
Comments
Leave a comment