Labdoc 2
Labdoc 2
Q1) This basic program demonstrates the declaration and initialization of variables of different data
types?
Program:
/*Author:G.Radhika
30-09-2024
declaration and initialization of variables */
#include <stdio.h>
int main() {
int a = 10; // Integer variable
float b = 20.5; // Float variable
char c = 'A'; // Character variable
return 0;
}
Output:
Integer: 10
Float: 20.50
Character: A
Q2) This program takes input from the user and stores the values in variables?
Program:
/*Author:G.Radhika
27-09-2024
input from the user and stores the values in variables */
#include <stdio.h>
int main() {
int num;
float decimal;
char character;
printf("You entered:\n");
printf("Integer: %d\n", num);
printf("Float: %.2f\n", decimal);
printf("Character: %c\n", character);
return 0;
}
Output:
Enter an integer: 12
Enter a float: 3.45
Enter a character: A
You entered:
Integer: 12
Float: 3.45
Character: A
Q3) This program swaps the values of two variables using a temporary variable?
Program:
/*Author:G.Radhika
30-09-2024
swaps the values of two variables */
#include <stdio.h>
int main() {
int x = 5, y = 10, temp;
return 0;
}
Output:
Before swapping: x = 5, y = 10
After swapping: x = 10, y = 5
Q4)unformatted functions?
Program:
/*Author:G.Radhika
30-09-2024
Example program for unformatted functions */
#include <stdio.h>
#include <conio.h>
int main() {
char ch;
char str[100];
printf("Press any key (hidden with getch()): ");
ch = getch();
printf("\nYou pressed (hidden): %c\n", ch);
return 0;
}
Output:
Press any key (hidden with getch()):
You pressed (hidden): f
Press any key (displayed with getche()): w
You pressed (with echo): w