source file name: Memory3.C #include <stdio.h> #include <stdlib.h> int main() { int* ptr; int n, i; // clrscr(); n = 6; printf("Enter number of elements: %d\n", n); ptr = (int*)calloc(n, sizeof(int)); if (ptr == NULL) { printf("Memory not allocated.\n"); exit…
Read more9) Write a C program that display memory allocation of input numbers using malloc(), calloc() and free().
source file name: Memory2.C #include <stdio.h> #include <stdlib.h> int main() { int *ptr, *ptr1; int n, i; clrscr(); printf("Enter number of elements:\n"); scanf("%d",&n); printf("\n memory allocted elements are %d\n ", n); ptr = (int*)malloc(n * sizeof…
Read more8) Write a C program that display and calculate the sum of n numbers by using dynamic memory allocation.
source file name: Memory1.C #include<stdio.h> #include<stdlib.h> void main() { int nos,i,sum=0; int *ptr; clrscr(); printf("Enter the number of elements : "); scanf("%d",&nos); ptr=(int *)malloc(nos*sizeof(int)); if (ptr==NULL) { printf("Memory no…
Read more7) Write a program to calculate the area and circumference of the circle using pointer radius variable.
source file name: Areaptr.C void main() { int rad; int *radptr; float acir,cc; //clrscr(); printf("\n enter radius of circle"); scanf("%d",&rad); radptr=&rad; acir=3.1429**radptr**radptr; cc=2*3.1429**radptr; printf("\n Area =%f and Circumference of Circle= %f ",acir,cc); getch(…
Read more6) Write a program to finds given number is Prime No. or not. The number is supplied at the command line.
source file name: Primecmd.C // command line program main method have 2 parameters void main(int a, char *b[]) { void prime(int); // prototype of function int n; //clrscr(); n=atoi(b[1]); printf("\n given no : %d ",n); prime(n); getch(); } void prime(int n) { int d=2; while(d<n) { if(n%d==0) { printf(&…
Read more5) Write a program to calculate factorial value of a number. The number is supplied at the command line.
source file name: FactCmdLine.C // This command line program have main method which uses 2 parameters void main(int a, char *b[]) { void fact(int); // prototype of function int n; //clrscr(); n=atoi(b[1]); printf("\n given no : %d ",n); //scanf("%d", &n); fact(n); getch(); } void fact(in…
Read more4) Write a program that displays each array element multiplied by 5 , by using pointer pass the entire array to function.
source file name: ArrMultiPtr.C void multiptr(int *p) { int n,res,i; for(i=1;i<=6;i++) { n=*p; res=n*5; printf(" %d ",res); p++; } } void main() { int *ptr; int i; int A[]={10,250,-50,400,100,-60}; clrscr(); printf("\n given array numbers: \n "); for(i=0;i<6;i++) printf(" %d ",A[i]…
Read more3) Write a program that will interchange two values. Use call by value and call by reference functions.
source file name: SwapPtr.C void swap1(int a, int b) // call by value function { int t=a; a=b; b=t; printf("\n inside swap1 function values are X=%d and Y=%d", a,b); } void swap2(int *a, int *b) // call by pointer function { int t=*a; *a=*b; *b=t; printf("\n inside swap2 function values are C=%d and D=…
Read more2) Write a C program that displays array numbers in forward and reverse direction using pointer.
source file name: Pointer1.C #include<stdio.h> int main() { int *p; int A[5]={10,20,-30,40,-450}; int i; //clrscr(); printf("\n Array in forword direction: "); p=&A[0]; for(i=0;i<5;i++) { printf("%d ",*p); p++; } p=&A[4]; printf("\n Reverce direc…
Read more1) Write a C program that displays memory addresses and values in forward and reverse direction.
source file name: Pointer2.C #inlcude<stdio.h> int main() { int i; int *p; int n=100; clrscr(); p=&n; printf("forward direction"); for(i=1;i<=5;i++) { printf(" \n address=%u value=%d",p,*p); p++; } printf("\n reverse direction"); p=&n; for…
Read more