counter

Free Hit Counter
Showing posts with label functions. Show all posts
Showing posts with label functions. Show all posts

To swap two values by functions


Q:
Function to show call by value


#include
#include
swap (int, int);
main()
{
int a, b;
printf("\nEnter value of a & b: ");
scanf("%d %d", &a, &b);
swap(a, b);
printf("\a=%d\n\b=%d", a, b);
getch();
}
swap (int a, int b)
{
int n;
n= a;
a = b;
b =n;
}

To print Hello between two lines using functions


Q:
---------
hello
---------





#include
#include

int printline(int);
void main()
{
int n,i;
clrscr();
scanf("%d",&n);
printline(n);
printf("\nhello\n");
printline(n);
getch();
}
int printline(int n)
{
int i;
for(i=0;i<=n;i++) { printf("_"); } return n; }