Professional Documents
Culture Documents
Test2 Pci
Test2 Pci
Test2 Pci
#include<stdio.h>
int fact(int n);
void main()
{
int a,fa;
printf("Enter a number: ");
scanf("%d",&a);
fa=fact(a);
printf("Factorial is= %d",fa);
getch;
}
int fact(int n)
{
if (n==1)
return n;
else
return n*fact(n-1);;
}
Q7. Write a syntax of pow() with example and use of math.h header file
Math.h:-
The math.h header defines various mathematical functions and one macro.
All the functions available in this library take double as an argument and
return double as the result.
Function:- pow(), sqrt() etc
Pointer :-
#include <stdio.h>
#include <conio.h>
void main()
{
int arr1[2][2],arr2[2][2],arr3[2][2],i,j;
clrscr();
printf("\nENTER VALUES FOR MATRIX 1:\n");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
scanf("%d",&arr1[i][j]);
}
}
printf("\nENTER VALUES FOR MATRIX B:\n");
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
scanf("%d",&arr2[i][j]);
}
}
Printf(“\n addition of two matrix=\n”);
for(i=0;i<=1;i++)
{
for(j=0;j<=1;j++)
{
arr3[i][j]= arr1[i][j]+ arr2[i][j];
printf(“%d\t”,arr3[i][j]);
}
Printf(“\n”);
}
getch();
}
10. Compare between array and string
Q11. Write a program to swap two integer number using pointer
#include<stdio.h>
void swap(int *a, int *b);
void main()
{
int x, y;
printf(“enter two number”);
scanf(“%d%d”,&x,&y);
swap(&x,&y);
printf(“after swap a=%d”,x);
printf(“after swap b=%d”,y);
getch();
}
void swap(int *a,int *b)
{
int *c;
*c=*a;
*a=*b;
*b=*c;
}
#include<stdio.h>
int fact(int n);
void main()
{
int a,fa;
printf("Enter a number: ");
scanf("%d",&a);
fa=fact(a);
printf("Factorial is= %d",fa);
getch;
}
int fact(int n)
{
if (n==1)
return n;
else
return n*fact(n-1);;
}
Q13. Write a program to perform add, sub,multi, divide operation using function
#include<stdio.h>
#include<conio.h>
void arith(void);
void main()
{
clrscr();
arith();
getch();
}
void arith(void)
{
int a,b,c,d,e;
float f;
printf(“enter two number”);
scanf(“%d%d”,&a,&b);
c=a+b;
d=a-b;
e=a*b;
f=a/b;
printf(“\nadd=%d”,c);
printf(“\nsub=%d”,d);
printf(“\nmulti=%d”,e);
printf(“\ndivide=%f”,f);
}