PPS Experiential Learning
PPS Experiential Learning
void main() {
int num1, num2;
int sum, difference, product, quotient, remainder;
clrscr();
getch();
}
#include <math.h>
void main() {
double a, b, x, y, k, t;
double expr1, expr2, expr3, expr4;
expr1 = (a * x + b) / (a * x - b);
expr2 = 2.5 * log(x) + cos(320 * M_PI / 180) + fabs(pow(x, 2) + pow(y, 2));
expr3 = a * pow(x, 5) + b * pow(x, 3) + k;
expr4 = a * exp(k * t);
#include <stdio.h>
#include <math.h>
void main() {
double a, b, c, discriminant, root1, root2, realPart, imaginaryPart;
printf("Enter coefficients a, b and c: ");
scanf("%lf %lf %lf", &a, &b, &c);
if (discriminant > 0) {
root1 = (-b + sqrt(discriminant)) / (2*a);
root2 = (-b - sqrt(discriminant)) / (2*a);
printf("Roots are real and different.\n");
printf("Root 1 = %.2lf\n", root1);
printf("Root 2 = %.2lf\n", root2);
} else if (discriminant == 0) {
root1 = -b / (2*a);
printf("Roots are real and the same.\n");
printf("Root 1 = Root 2 = %.2lf\n", root1);
} else {
realPart = -b / (2*a);
imaginaryPart = sqrt(-discriminant) / (2*a);
printf("Roots are complex and different.\n");
printf("Root 1 = %.2lf + %.2lfi\n", realPart, imaginaryPart);
printf("Root 2 = %.2lf - %.2lfi\n", realPart, imaginaryPart);
}
}
b) In a town, the percentage of men is 52. The percentage of total literacy is 48 and
the total percentage of literate men is 35 of the total population. Write a C
program to find the total number of illiterate men and women if the population
of the town is 7000.
#include <stdio.h>
int main() {
int total_population = 7000;
int total_men = (52 * total_population) / 100;
int total_literacy = (48 * total_population) / 100;
int literate_men = (35 * total_population) / 100;
int illiterate_men = total_men - literate_men;
int illiterate_women = total_population - total_men - (total_literacy -
literate_men);
return 0;
}
#include <stdio.h>
int main() {
int old_reading, new_reading, units_consumed;
double bill_amount;
return 0;
}
b) An insurance company computes the premium amount based on the following;
i. If a person's health is excellent and the person is between 25 and 35 years of
age and lives in a city, and is a male then the premium is Rs.4 per thousand
and the policy amount cannot exceed Rs.2 lakhs.
ii. If a person satisfies all the above conditions and is female then thepremium
is Rs.3 per thousand and the policy amount cannot exceed Rs.1 lakh.
iii. If a person's health is poor and the person is between 25 and 35 years of
age and lives in a village and is a male then premium is Rs.6 per thousand
and the policy cannot exceed Rs. 10000.
iv. In all other cases the person is not insured.
Write a C program to determine whether the person should be insured or
not, his/her premium rate and maximum amount for which he/she can be insured.
#include <stdio.h>
int main() {
char health, gender, location;
int age;
double premium_rate;
double max_policy_amount;
return 0;
}
c) Write a C Program to find the grade for a student using a Switch case. The userneeds to
enter a subject score (varies from 0 to 100)and then display the grade as described below
#include <stdio.h>
int main() {
int score;
char grade;
return 0;
}
int main() {
int n, i;
int t1 = 0, t2 = 1, nextTerm;
return 0;
}
#include <stdio.h>
int main() {
int n, sum = 0, remainder;
while (n != 0) {
remainder = n % 10;
sum += remainder;
n /= 10;
}
return 0;
}
c) Write a C program to read two numbers x and n, and then compute the sum of
the geometric progression: 1+x+x2+x3+………….+xn. Show appropriate error
message for n<0. (Example: if n is 3 and x is 5, then the sum is: 1+5+25+125)
#include <stdio.h>
#include <math.h>
int main() {
int x, n, i;
double sum = 0.0;
if (n < 0) {
printf("Error: n must be non-negative.\n");
} else {
for (i = 0; i <= n; i++) {
sum += pow(x, i);
}
printf("Sum of the geometric progression: %.2lf\n", sum);
}
return 0;
1
1 2 1
1 2 3 2 1
1 2 3 4 3 2 1
1 2 3 4 5 4 3 2 1
void main() {
int i, j, n, space;
}
5. a) Write a C program to find both the largest and smallest numbers in a list of
integers.
#include <stdio.h>
int main() {
int n, i;
int largest, smallest;
int arr[n];
printf("Enter %d integers: ", n);
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
return 0;
#include <stdio.h>
void addMatrices(int row, int col, int a[row][col], int b[row][col], int result[row][col]) {
for (int i = 0; i < row; i++) {
for (int j = 0; j < col; j++) {
result[i][j] = a[i][j] + b[i][j];
}
}
}
void multiplyMatrices(int row1, int col1, int a[row1][col1], int row2, int col2, int
b[row2][col2], int result[row1][col2]) {
for (int i = 0; i < row1; i++) {
for (int j = 0; j < col2; j++) {
result[i][j] = 0;
for (int k = 0; k < col1; k++) {
result[i][j] += a[i][k] * b[k][j];
}
}
}
}
int main() {
int row1, col1, row2, col2;
printf("Enter rows and columns for the first matrix: ");
scanf("%d %d", &row1, &col1);
printf("Enter rows and columns for the second matrix: ");
scanf("%d %d", &row2, &col2);
if (col1 != row2) {
printf("Matrix multiplication not possible.\n");
return 1;
}
printf("Sum of matrices:\n");
for (int i = 0; i < row1; i++) {
for (int j = 0; j < col1; j++) {
printf("%d ", sum[i][j]);
}
printf("\n");
}
printf("Product of matrices:\n");
for (int i = 0; i < row1; i++) {
for (int j = 0; j < col2; j++) {
printf("%d ", product[i][j]);
}
printf("\n");
}
return 0;
}
int main() {
char mainStr[100], subStr[50];
int position, lenMain, lenSub;
lenMain = strlen(mainStr);
lenSub = strlen(subStr);
return 0;
b) Write a C program to count the lines, words and characters in a given text.
#include <stdio.h>
int main() {
char ch;
int characters = 0, words = 0, lines = 0;
int inWord = 0;
if (ch == '\n') {
lines++;
}
}
return 0;
7. a) Write a C program to generate all the prime numbers between 1 and n, where nis
a value entered by the user. Define a separate function to generate prime
numbers.
#include <stdio.h>
int isPrime(int n) {
if (n <= 1) return 0;
for (int i = 2; i <= n / 2; i++) {
if (n % i == 0) return 0;
}
return 1;
}
int main() {
int n;
printf("Enter a number: ");
scanf("%d", &n);
return 0;
i)
#include <stdio.h>
int factorial(int n) {
if (n == 0)
return 1;
else
return n * factorial(n - 1);
}
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
printf("Factorial of %d = %d\n", num, factorial(num));
return 0;
}
ii)
#include <stdio.h>
int main() {
int num1, num2;
printf("Enter two numbers: ");
scanf("%d %d", &num1, &num2);
printf("GCD of %d and %d is %d\n", num1, num2, gcd(num1, num2));
return 0;
}
8. a) Write a C program to print the elements of an array in reverse order using pointers.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
return 0;
b) Write a C program to count the number of vowels and consonants in a string using
pointers.
#include <stdio.h>
#include <ctype.h>
int main() {
char str[100];
char *ptr;
int vowels = 0, consonants = 0;
ptr = str;
return 0;
}
c) Write a C program to store n elements in an array and print the elements in sorted
order using pointers.
#include <stdio.h>
int main() {
int n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
int arr[n];
printf("Enter %d elements:\n", n);
for (int i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sortArray(arr, n);
printf("Sorted array:\n");
for (int i = 0; i < n; i++) {
printf("%d ", arr[i]);
}
return 0;
#include <stdio.h>
typedef struct {
float real;
float imag;
} Complex;
int main() {
Complex c1, c2, sum, product;
return 0;
}
typedef struct {
int empNo;
char name[50];
float basicPay;
int doj[3]; // Date of Joining as [day, month, year]
} Employee;
int main() {
int n = 10;
Employee emp[n];
storeEmployeeDetails(emp, n);
reviseBasicPay(emp, n);
printEmployeesWith20YearsService(emp, n);
return 0;
}
10 a) Write a C program to reverse the first n characters of a given text file.
#include <stdio.h>
int main() {
FILE *file;
char filename[100];
int n;
char buffer[100];
fread(buffer, sizeof(char), n, file);
reverseString(buffer, n);
fseek(file, 0, SEEK_SET);
fwrite(buffer, sizeof(char), n, file);
fclose(file);
printf("First %d characters reversed in the file %s.\n", n, filename);
return 0;
}
b) Write a C program to merge two files into a new file.
#include <stdio.h>
int main() {
FILE *file1, *file2, *file3;
char filename1[100], filename2[100], filename3[100];
char ch;
fclose(file1);
fclose(file2);
fclose(file3);
return 0;
}