Posts

Pointer Solution

  Pointer 4. Write a program to swap any two number using call by reference. #include <stdio.h> void swap(int *a, int *b); int main() { int x, y; printf("Enter two integers: "); scanf("%d %d", &x, &y); printf("Before swapping: x = %d, y = %d\n", x, y); swap(&x, &y); printf("After swapping: x = %d, y = %d\n", x, y); return 0; } void swap(int *a, int *b) { int temp; temp = *a; *a = *b; *b = temp; } Output Enter two integers: 2   7 Before swapping: x = 2, y = 7 After swapping: x = 7, y = 2   To run program please click me. 3. Write a program to swap two integer numbers using pointer.   #include <stdio.h> void swap(int *a, int *b); int main() {     int x, y;     printf("Enter two integers: ");     scanf("%d %d", &x, &y);      printf("Before swapping: x = %d, y = %d\n", x, y);   ...

Structure and Union Solution

  Structure and Union   1. Write a program to read records of 3 employees and then display information using structure array. #include <stdio.h> struct Employee {     char name[20];     int age;     float salary; }; int main() {     struct Employee emp[3];     int i;     for(i = 0; i < 3; i++) {         printf("Enter name, age, and salary of employee %d: ", i + 1);         scanf("%s %d %f", emp[i].name, &emp[i].age, &emp[i].salary);     }     printf("Employee Records:\n");     for(i = 0; i < 3; i++) {         printf("Name: %s\n", emp[i].name);         printf("Age: %d\n", emp[i].age);         printf("Salary:...