alloc qsn 1,2
- Write a program to dynamically create an array of size 6 capable of storing 6 integers.
- Use the array in Problem 1 to store 6 integers entered by the user
#include<stdlib.h>
int main() {
// Write C code here
float*ptr;
ptr=(float*) malloc( 6 *sizeof(float));
for (int i = 0 ; i<6;i++){
printf("Enter value of element %d : ", i+1);
scanf("%f",&ptr[i]);
}
//realloc
//ptr=realloc(ptr , 10*sizeof(float));
//
//for (int i = 0 ; i<10;i++){
// printf("Enter value of element %d : ", i+1);
// scanf("%f",&ptr[i]);
//}
for (int i = 0 ; i<6;i++){
printf("%0.3f\n",ptr[i]);
}
return 0;
}
Comments
Post a Comment