C Programs
C Programs
#include <stdio.h>
int main()
{
int a, b, *p, *q, sum;
p = &a;
q = &b;
sum = *p + *q;
return 0;
}
int main()
{
int fno, sno, sum;
if(*ptr1>*ptr2)
{
printf("\n\n %d is the maximum number.\n\n",*ptr1);
}
else
{
printf("\n\n %d is the maximum number.\n\n",*ptr2);
}
4. Write a program in C to store n elements in an array and print the elements using
pointer.
#include <stdio.h>
int main()
{
int arr1[25], i,n,*ptr;
printf(" Input the number of elements to store in the array :");
scanf("%d",&n);
ptr=arr1;
6. Write a program in C to find the factorial of a given number using pointers (call by
reference)
#include <stdio.h>
void findFact(int,int*);
int main()
{
int fact;
int num1;
printf(" Input a number : ");
scanf("%d",&num1);
findFact(num1,&fact);
printf(" The Factorial of %d is : %d \n\n",num1,fact);
}
*f =1;
for(i=1;i<=n;i++)
*f=*f*i;
}
7. Write a program in C to sort an array using Pointer.
#include <stdio.h>
void main()
{
int a[20],i,j,tmp,n,*p;
printf(" Enter number of elements\n");
scanf("%d",&n);
#include <stdio.h>
int main()
{
int arr1[25], i,n,*ptr;
printf(" Input the number of elements to store in the array :");
scanf("%d",&n);
struct complex {
float real;
float imag;
} ;
int main() {
struct complex n1, n2, n3;