Decimal to hex conversion using function
Program:
#include<stdio.h>
void dec2hex(int);
int main()
{
int dec;
printf("Enter Positive Integer Number: ");
scanf("%d",&dec);
dec2hex(dec);
return 0;
}
void dec2hex(int m)
{
int i=0,j;
char hex[10],store[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
while(m>0)
{
hex[i]=store[m%16];
m=m/16;
i++;
}
for(j=i-1;j>=0;j--)
{
printf("%c",hex[j]);
}
}
Output:
#include<stdio.h>
void dec2hex(int);
int main()
{
int dec;
printf("Enter Positive Integer Number: ");
scanf("%d",&dec);
dec2hex(dec);
return 0;
}
void dec2hex(int m)
{
int i=0,j;
char hex[10],store[16]={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'};
while(m>0)
{
hex[i]=store[m%16];
m=m/16;
i++;
}
for(j=i-1;j>=0;j--)
{
printf("%c",hex[j]);
}
}
Output:
Exchange values using call by reference
Program:
#include<stdio.h>
void exch(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
printf("Inside Function::\n");
printf("a=%d b=%d\n",*a,*b);
}
int main()
{
int x,y;
printf("Enter value of x and y: \n");
scanf("%d%d",&x,&y);
exch(&x,&y);
printf("From main Function::\n");
printf("x=%d y=%d\n",x,y);
return 0;
}
Output:
#include<stdio.h>
void exch(int *a,int *b)
{
int temp;
temp=*a;
*a=*b;
*b=temp;
printf("Inside Function::\n");
printf("a=%d b=%d\n",*a,*b);
}
int main()
{
int x,y;
printf("Enter value of x and y: \n");
scanf("%d%d",&x,&y);
exch(&x,&y);
printf("From main Function::\n");
printf("x=%d y=%d\n",x,y);
return 0;
}
Exchange values using call by value
Program:
#include<stdio.h>
void exch(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("Inside Function::\n");
printf("a=%d b=%d\n",a,b);
}
int main()
{
int x,y;
printf("Enter value of x and y: \n");
scanf("%d%d",&x,&y);
exch(x,y);
printf("From main Function::\n");
printf("x=%d y=%d\n",x,y);
return 0;
}
Output:
#include<stdio.h>
void exch(int a,int b)
{
int temp;
temp=a;
a=b;
b=temp;
printf("Inside Function::\n");
printf("a=%d b=%d\n",a,b);
}
int main()
{
int x,y;
printf("Enter value of x and y: \n");
scanf("%d%d",&x,&y);
exch(x,y);
printf("From main Function::\n");
printf("x=%d y=%d\n",x,y);
return 0;
}
Subscribe to:
Posts (Atom)
x^y using recursion
Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...
-
Program: #include<stdio.h> int main() { int a[4][4],n,i,j; printf("Enter value of n: "); /*rows and cols*/ sca...
-
Program: #include<stdio.h> int power(int a,int b); int main() { int x,y,ans; printf("Enter x and y:\n "); scanf(...
-
Program: #include<stdio.h> int main() { int a[4][4],b[4][4],c[4][4],m,n,p,q,i,j; printf("Enter no. of rows in matrix A: ...




