Skip to main content

Posts

Swap two numbers in C using different methods

 1. Swap two numbers in C. #include<stdio.h> int main() {     int a, b;     scanf("%d%d", &a, &b);     int temp;     temp = *x;     *x = *y;     *y = temp;     printf("%d %d", a, b);     return 0; } 2. Swap two numbers in C using recursion method. #include<stdio.h> void swap(int *x, int *y) {     int temp;     temp = *x;     *x = *y;     *y = temp; } int main() {     int a, b;     scanf("%d%d", &a, &b);     swap(&a, &b);     printf("%d %d", a, b);     return 0; } 3. Swap two numbers in C without using any other variable. #include<stdio.h> int main() {     int a, b;     scanf("%d%d", &a, &b);     a = a ^ b;     b = a ^ b;     a = a ^ b;     printf("%d and %d", a, b);     return 0; }
Recent posts

Write a C program to print the following characters in a reverse way.

Write a C program to print the following characters in a reverse way. #include <stdio.h> int main () {     char i , j , k ;     printf ( "Enter the three character which have to reverse: " );     scanf ( " %c %c %c " , & i , & j , & k );     printf ( "The reverse of %c%c%c is %c%c%c " , i , j , k , k , j , i );     return 0 ; https://vdbaa.com/fullpage.php?section=General&pub=899148&ga=g }

Write a C program to compute the perimeter and area of a circle with a given radius.

Write a C program to compute the perimeter and area of a circle with a given radius. We all know, Area of circle is pi*radius*radius Perimeter of circle is 2*pi*radius So, according to upper formula we can write a C Programme that can calculate the area and perimeter of circle. #include<stdio.h> #define pi 3.141592 int main() {     float r, peri, area;     printf(“Enter the radius of Circle (in inches): “);     scanf(“%f”, &r);     peri = 2 * pi * r;     area = pi * r * r;     printf(“Perimeter of the Circle = %0.2f inches”, peri);     printf(“Area of the Circle = %0.2f square inches”, area); }