Write a program in C to interchange the value of two variables by using the concept of call by reference method. In the call by reference method addresses of argument are passed from main function to the function definition and these addresses are collected or stored in pointer variables. If we update the value of variables in function definition will be reflected throughout the program. Program: - #include<stdio.h> #include<conio.h> void swap(int *a, int *b) { int t; t=*a; *a=*b; *b=t; } void main() { int x,y; clrscr(); printf("\n enter the first number="); scanf("%d",&x); printf("\n enter the second number="); scanf("%d",&y); swap(&x,&y); printf("\n x= %d", x); printf("\n y= %d", y); getch(); } Output: - Enter the first number= Enter the second number= X= Y=
Write a program to print counting from one to ten using if go to statement. Today we are simply going to discuss about the use of if go to statement. If go to statement is used to transfer the control of execution to the specify label. Syntax: - goto label name; Program: - #include<stdio.h> #include<conio.h> void main() { int a=1; clrscr(); x:if(a<=10) { printf("\n %d",a); a++; goto x; } getch(); } Output: - 1 2 3 4 5 6 7 8 9 10