PPS Practicals
PPS Practicals
return 0;
}
Output:
Age: 30
Salary: 60000.500000
Pi: 3.141593
Initial: J
Name: John Doe
Is Employed: 1
#include <stdio.h>
void main()
{
int a;
float b;
double c;
char d;
printf("Size of int=%lu bytes\n",sizeof(a));
printf("Size of float=%lu bytes\n",sizeof(b));
printf("Size of double=%lu bytes\n",sizeof(c));
printf("Size of char=%lu byte\n",sizeof(d));
}
Output:
#include <stdio.h>
int main()
{
int a = 9,b = 4, c, result;
Output:
a+b = 13
a-b = 5
a*b = 36
a/b = 2
Remainder when a divided by b = 1
9 == 4 is 0
9 == 1 is 0
9 > 4 is 1
9 > 1 is 1
9 < 4 is 0
9 < 1 is 0
9 != 4 is 1
9 != 1 is 1
9 >= 4 is 1
9 >= 1 is 1
9 <= 4 is 0
9 <= 1 is 0
(a == b) && (c > b) is 0
(a == b) && (c < b) is 0
(a == b) || (c < b) is 1
(a != b) || (c < b) is 1
!(a != b) is 0
!(a == b) is 1
Experiment no. 3
c program to demonstrate the use of conditional expression and explain the order of evaluation
#include <stdio.h>
void main() {
int a = 10;
int b = 20;
int max;
Output:
The maximum value is: 20
Result: 6, x: 6, y: 10
Explanation:
The condition (x++ < y) is evaluated. Because x is 5 and y is 10, the condition is
true. x is incremented to 6 as a side effect of the post-increment operator ++.
Since the condition is true, the expression x (which is now 6) is evaluated, and its value
is assigned to result. y++ is not evaluated.
The output shows result is 6, x is 6, and y remains 10, demonstrating that y++ was not
executed.
Experiment no. 4
c program to demonstrate the use of assignment operator and evaluate expressions
involving them
#include <stdio.h>
void main() {
int a = 10;
int b = 5;
int c;
c = a;
printf("c = a: c = %d\n", c);
a -= b; // a = a - b
printf("a -= b: a = %d\n", a);
a %= b; // a = a % b
printf("a %%= b: a = %d\n", a);
a |= b; // a = a | b
printf("a |= b: a = %d\n", a);
a <<= 1; // a = a << 1
printf("a <<= 1: a = %d\n", a);
a >>= 1; // a = a >> 1
printf("a >>= 1: a = %d\n", a);
}
Output:
c = a: c = 10
a += b: a = 15
a -= b: a = 10
a %= b: a = 0
a &= b: a = 0
a |= b: a = 5
a ^= b: a = 0
a <<= 1: a = 0
a >>= 1: a = 0
Experiment no. 5
Program to demonstrate if-else statement
#include <stdio.h>
void main() {
int number;
printf("Enter an integer: ");
scanf("%d", &number);
if (number > 0) {
printf("%d is a positive number.\n", number);
} else if (number < 0){
printf("%d is a negative number.\n", number);
} else {
printf("The number is zero.\n");
}
}
Enter an integer: 6
6 is a positive number.
case '-':
printf("%.1lf - %.1lf = %.1lf",n1, n2, n1-n2);
break;
case '*':
printf("%.1lf * %.1lf = %.1lf",n1, n2, n1*n2);
break;
case '/':
printf("%.1lf / %.1lf = %.1lf",n1, n2, n1/n2);
break;
printf("Loop finished.\n");
}
Output:
Value of i: 1
Value of i: 2
Value of i: 3
Value of i: 4
Value of i: 5
Loop finished.
printf("Sum = %.2lf",sum);
}
Output:
Enter a number: 2
Enter a number: 5.3
Enter a number: 9
Enter a number: -84
Enter a number: 0
Sum = -67.70
Program to demonstrate for loop
#include <stdio.h>
int main() {
int i;
return 0;
}
Output:
Iteration number: 1
Iteration number: 2
Iteration number: 3
Iteration number: 4
Iteration number: 5
Iteration number: 6
Iteration number: 7
Iteration number: 8
Iteration number: 9
Iteration number: 10
Experiment no. 6
c program to find factorial of a number
#include <stdio.h>
int main() {
int n, i;
unsigned long long fact = 1;
printf("Enter an integer: ");
scanf("%d", &n);
Output:
Enter an integer: 5
Factorial of 5 = 120
Experiment no. 7
c program to print fibonacci series
#include <stdio.h>
void main() {
int i, n;
Output:
Enter the number of terms: 9
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21
Experiment no. 8
Write a c program to initialize and display elements of a one-dimensional array
#include <stdio.h>
void main() {
// Initialize a one-dimensional integer array
int numbers[] = {10, 20, 30, 40, 50};
Output:
Elements of the array are:
Element at index 0: 10
Element at index 1: 20
Element at index 2: 30
Element at index 3: 40
Element at index 4: 50
Experiment no. 9
Write a c program to demonstrate the use of pointers to access elements of array
#include <stdio.h>
void main() {
int arr[] = {10, 20, 30, 40, 50};
int *ptr;
int i;
return 0;
}
Output:
struct Student {
char name[50]; // Student's name (maximum 49 characters + null
terminator)
int rollNumber; // Roll number
float marks; // Marks (e.g., total marks, GPA)
int age; // Age
char address[100]; // Address
};
void main() {
struct Student student1; // Create a variable of type Student
}
Enter student name: abc
Enter roll number: 11
Enter marks: 95.63
Enter age: 17
Enter address: zyz
Student Details:
Name: abc
Roll Number: 11
Marks: 95.63
Age: 17
Address: zyz
Experiment no 12
Program to read data from text file and write the results to another file
#include <stdio.h>
#include <stdlib.h>
int main() {
FILE *inputFile, *outputFile;
char ch;
char inputFileName[100], outputFileName[100];
fclose(inputFile);
fclose(outputFile);
}
Output:
Enter the name of the input file: abc
Enter the name of the output file: xyz
Error opening input file: No such file or directory