-
Notifications
You must be signed in to change notification settings - Fork 0
/
1.5calloc.c
49 lines (41 loc) · 912 Bytes
/
1.5calloc.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
//yeh multiipal block bnata hai
//syntax=(void*)calloc(number of blocks,size of each in bytes);
//syntax=ptr=(datatype*)calloc(n,size in bytes);
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
int n,*ptr,sum=0,i;
int *p; //for print values
printf("Enter The size of array");
scanf("%d",&n);
ptr=(int*)calloc(n,sizeof(int));
p=ptr; //get first block address of dynamic array
//Check array created or not
if(ptr==NULL)
{
printf("Out Of memory");
exit(0);
}
//Enter values from user
printf("enter the elements of array");
for(i=1;i<=n;i++)
{
scanf("%d",ptr); //store value to first block address
sum=sum+*ptr; //sum of each value
ptr++; //increment value for next block
}
//print values
printf("elements are:");
for(i=1;i<=n;i++)
{
printf("%d\n", *p);
p++;
}
//finally print addition of sum
printf("addition is %d",sum);
return 0;
//by Navjot Singh Prince:)
}