# C TUTORIAL
# C PROGRAMS
Pointers Examples
➤ Pointer Basic Examples
➤ Dynamic Memory Allocation
➤ Read Write Array with Pointer
➤ Sum Avg of Array with Pointer
➤ Sort Array with Pointer
➤ Search in Array using Pointer
➤ Sum of N Numbers
➤ Largest Number by DMA
Others
➤ C Program Without Main()
➤ Hello World Without ;
➤ Process & Parent Process ID
➤ C Program Without Header File
➤ void main(), main() vs int main()
➤ fork() function in C
➤ Why gets function is dangerous
➤ Undefined reference to sqrt
# C PROGRAMS
Pointers Examples
➤ Pointer Basic Examples
➤ Dynamic Memory Allocation
➤ Read Write Array with Pointer
➤ Sum Avg of Array with Pointer
➤ Sort Array with Pointer
➤ Search in Array using Pointer
➤ Sum of N Numbers
➤ Largest Number by DMA
Others
➤ C Program Without Main()
➤ Hello World Without ;
➤ Process & Parent Process ID
➤ C Program Without Header File
➤ void main(), main() vs int main()
➤ fork() function in C
➤ Why gets function is dangerous
➤ Undefined reference to sqrt
We will write a C program to find largest number using dynamic memory allocation – calloc(). calloc() function is defined under <stdlib.h>
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i, num;
float *data;
printf("Enter total number of elements(1 to 100): ");
scanf("%d",&num);
// allocates the memory for 'num' elements
data=(float*)calloc(num,sizeof(float));
if(data==NULL)
{
printf("Error! Memory not Allocated.");
exit(0);
}
printf("\n");
// store the number entered by the User
for(i=0;i<num;i++)
{
printf("Enter element %d:",i+1);
scanf("%f",data+i);
}
// store largest number at address data
for(i=0;i<num;i++)
{
if( *data < *(data+i))
*data = *(data+i);
}
printf("Largest Element = %.2f",*data);
return 0;
}
Output:-
Enter total number of elements(1 to 100): 5
Enter element 1:10.2
Enter element 2:23
Enter element 3:23.3
Enter element 4:24
Enter element 5:32
Largest Element = 32.00
If you enjoyed this post, share it with your friends. Do you want to share more information about the topic discussed above or do you find anything incorrect? Let us know in the comments. Thank you!
Similar C programs