alloc q3

 

  1. Solve problem 1 using calloc().


#include<stdlib.h>


int main() {

    // Write C code here

    float*ptr;

    ptr=(float*) calloc( 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

Popular posts from this blog

Sum of Even Numbers till N

Find the Runner-Up Score!

Print All Substrings