0% found this document useful (0 votes)
12 views33 pages

EContent 2 2025 09 12 10 30 08 PPS1 Manualpdf 2025 07 24 10 06 48

PPT

Uploaded by

dabhibhagirath21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
12 views33 pages

EContent 2 2025 09 12 10 30 08 PPS1 Manualpdf 2025 07 24 10 06 48

PPT

Uploaded by

dabhibhagirath21
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 33

Semester 1st

Lab Manual
Programming for Problem Solving-I
2BTES101

Name: ___________________________________________________

Enrolment: ________________________________________________

Class: ____________________ Division: ________________________

School: ___________________________________________________
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

CERTIFICATE

This is to certify that the practical work satisfactorily


carried out and hence recorded in this manual is the confide
work of Mr. /Miss_________________________________
student of Computer Engineering Semester 1 st in the
Programming for Problem Solving-I (2BTES101) Laboratory of
Dr. Subhash University during the academic year 2023-24.

Submission Date: ……………

Subject in Charge HOD

Institute Seal

1
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Index
Sr. Practical AIM Date Sign
No.
1 Write a program to calculate simple interest (i =
(p*r*n)/100)
2 Write a program that accepts centigrade and converts
it into Fahrenheit (f=1.8*c +32)
3 Write a program to demonstrate the use of Arithmetic
operators by getting two numbers from the user
4 Write a program that accepts a number from the
keyboard and find weather the number is
ODD or EVEN using Conditional operators
5 Write a program to demonstrate the use of increment
and decrement operators.
6 Write a program to demonstrate the use of shorthand
operators
7 Write a program to demonstrate the use of sizeof() of
operator.
8 Write a program that accepts three numbers from the
user and print the maximum of them
9 Demonstrate the use of the GOTO statement
10 Write a c program to prepare a pay slip using the
following data. Da = 10% of basic, Hra = 7.50% of basic,
Ma = 300, Pf = 12.50% of basic, Gross = basic + Da +
Hra + Ma, Nt = Gross – Pf
11 Write a program to read marks from the keyboard and
your program should display an equivalent grade
according to the following table (if-else ladder)
12 Write a C program to find factorial of a given number
13 Write a program that do sum=1+3+5+.......N terms Print
value of Sum.
14 Write a program to accept one number from the user.
i) Display reverse of that number. ii) Find if it is
Armstrong or not.
15 Write a C program to display different Patterns
16 Write a program to accept 5 numbers in an array and
display it
17 Write a program to accept 9 numbers in form of a
matrix and display it in matrix form.
18 Write a program to accept 5 numbers in array and find
the maximum and minimum values of it.
19 Write a C program to find 1+1/2+1/3+1/4+....+1/n
20 Write a program to count a number of vowels in a
given string.

2
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 1: Write a program to calculate simple interest


(i = (p*r*n)/100)

#include <stdio.h>
int main() {
int n;
float p, r, I;
printf("\n Enter Amount :");
scanf("%f", & p);
printf("\n Enter No of Years :");
scanf("%d", & n);
printf("\n Enter Rate :");
scanf("%f", & r);
I = (p * r * n) / 100;
printf("\n Interest = %.2f", I);
return 0;
}
OUTPUT

EVALUATION:
Observation & Timely
Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

3
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 2: Write a program that accepts centigrade and converts it into


Fahrenheit (f=1.8*c +32).
#include <stdio.h>

int main() {
float F, C;
printf("Enter Temperature in Celsius : ");
scanf("%f", & C);
F = (C * 1.8) + 32;
printf("\n %.2f Celsius = %.2f Fahrenheit", C, F);
return 0;
}

OUTPUT

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

4
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 3: Write a program to demonstrate the use of Arithmetic operators


by getting two numbers from the user

#include <stdio.h>
int main() {
// Declare variables to store the two numbers
float num1, num2;

// Prompt the user to enter the first number


printf("Enter the first number: ");
scanf("%f", &num1);

// Prompt the user to enter the second number


printf("Enter the second number: ");
scanf("%f", &num2);

// Perform arithmetic operations and display the results


printf("Addition: %.2f + %.2f = %.2f\n", num1, num2, num1 + num2);
printf("Subtraction: %.2f - %.2f = %.2f\n", num1, num2, num1 - num2);
printf("Multiplication: %.2f * %.2f = %.2f\n", num1, num2, num1 * num2);
printf("Division: %.2f / %.2f = %.2f\n", num1, num2, num1 / num2);

// Check for division by zero


if (num2 != 0) {
printf("Division: %.2f / %.2f = %.2f\n", num1, num2, num1 / num2);
} else {
printf("Division by zero is not allowed.\n");
}

return 0;
}
OUTPUT
Enter the first number: 10
Enter the second number: 5
Addition: 10.00 + 5.00 = 15.00
Subtraction: 10.00 - 5.00 = 5.00
Multiplication: 10.00 * 5.00 = 50.00
Division: 10.00 / 5.00 = 2.00

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

5
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 4: Write a program that accepts a number from the keyboard and
find weather the number is ODD or EVEN using Conditional operators
#include <stdio.h>

int main() {
// Declare variable to store the number
int number;

// Prompt the user to enter a number


printf("Enter a number: ");
scanf("%d", &number);

// Use conditional operator to check if the number is odd or even


(number % 2 == 0) ? printf("%d is EVEN\n", number) : printf("%d is ODD\n",
number);

return 0;
}
OUTPUT
Enter a number: 4
4 is EVEN

Enter a number: 7
7 is ODD

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

6
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 5: Write a program to demonstrate the use of increment and


decrement operators
#include <stdio.h>

int main() {
// Declare variables
int num;

// Initialize the variable


num = 10;
printf("Initial value of num: %d\n", num);

// Demonstrate post-increment
printf("Value of num after post-increment (num++): %d\n", num++);
printf("Value of num after post-increment operation: %d\n", num);

// Demonstrate pre-increment
printf("Value of num after pre-increment (++num): %d\n", ++num);

// Demonstrate post-decrement
printf("Value of num after post-decrement (num--): %d\n", num--);
printf("Value of num after post-decrement operation: %d\n", num);

// Demonstrate pre-decrement
printf("Value of num after pre-decrement (--num): %d\n", --num);

return 0;
}

7
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

OUTPUT
Initial value of num: 10
Value of num after post-increment (num++): 10
Value of num after post-increment operation: 11
Value of num after pre-increment (++num): 12
Value of num after post-decrement (num--): 12
Value of num after post-decrement operation: 11
Value of num after pre-decrement (--num): 10

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

8
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 6: Write a program to demonstrate the use of shorthand operators


#include <stdio.h>

int main() {
// Declare and initialize variables
int num = 10;

// Display the initial value


printf("Initial value of num: %d\n", num);

// Demonstrate shorthand addition (+=)


num += 5;
printf("After num += 5: %d\n", num);

// Demonstrate shorthand subtraction (-=)


num -= 3;
printf("After num -= 3: %d\n", num);

// Demonstrate shorthand multiplication (*=)


num *= 2;
printf("After num *= 2: %d\n", num);

// Demonstrate shorthand division (/=)


num /= 4;
printf("After num /= 4: %d\n", num);

// Demonstrate shorthand modulus (%=)


num %= 3;
printf("After num %%= 3: %d\n", num);

return 0;
}

9
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

OUTPUT
Initial value of num: 10
After num += 5: 15
After num -= 3: 12
After num *= 2: 24
After num /= 4: 6
After num %= 3: 0

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

10
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 7: Write a program to demonstrate the use of sizeof() of operator


#include <stdio.h>

int main() {
// Declare variables of different types
char c;
int i;
float f;
double d;
long l;
long long ll;
short s;

// Display the size of each type using sizeof()


printf("Size of char: %lu byte(s)\n", sizeof(c));
printf("Size of int: %lu byte(s)\n", sizeof(i));
printf("Size of float: %lu byte(s)\n", sizeof(f));
printf("Size of double: %lu byte(s)\n", sizeof(d));
printf("Size of long: %lu byte(s)\n", sizeof(l));
printf("Size of long long: %lu byte(s)\n", sizeof(ll));
printf("Size of short: %lu byte(s)\n", sizeof(s));

// Demonstrate sizeof() with data types directly


printf("Size of char: %lu byte(s)\n", sizeof(char));
printf("Size of int: %lu byte(s)\n", sizeof(int));
printf("Size of float: %lu byte(s)\n", sizeof(float));
printf("Size of double: %lu byte(s)\n", sizeof(double));
printf("Size of long: %lu byte(s)\n", sizeof(long));
printf("Size of long long: %lu byte(s)\n", sizeof(long long));
printf("Size of short: %lu byte(s)\n", sizeof(short));

return 0;
}

OUTPUT

Size of char: 1 byte(s)


Size of int: 4 byte(s)
Size of float: 4 byte(s)
Size of double: 8 byte(s)
Size of long: 8 byte(s)
Size of long long: 8 byte(s)
Size of short: 2 byte(s)
Size of char: 1 byte(s)
Size of int: 4 byte(s)

11
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Size of float: 4 byte(s)


Size of double: 8 byte(s)
Size of long: 8 byte(s)
Size of long long: 8 byte(s)
Size of short: 2 byte(s)

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

12
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 8: Write a program that accepts three numbers from the user and
print the maximum of them.
#include <stdio.h>

int main() {
// Declare variables to store the three numbers
int num1, num2, num3;

// Prompt the user to enter the first number


printf("Enter the first number: ");
scanf("%d", &num1);

// Prompt the user to enter the second number


printf("Enter the second number: ");
scanf("%d", &num2);

// Prompt the user to enter the third number


printf("Enter the third number: ");
scanf("%d", &num3);

// Determine the maximum number using if-else statements


int max = num1; // Assume num1 is the maximum initially
if (num2 > max) {
max = num2;
}
if (num3 > max) {
max = num3;
}

// Print the maximum number


printf("The maximum of the three numbers is: %d\n", max);

return 0;
}

13
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

OUTPUT
Enter the first number: 5
Enter the second number: 8
Enter the third number: 3
The maximum of the three numbers is: 8

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

14
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 9: Demonstrate the use of the GOTO statement


#include <stdio.h>

int main() {
int num;

// Prompt the user to enter a number


printf("Enter a number (negative to exit): ");
scanf("%d", &num);

// If the number is negative, jump to the end


if (num < 0) {
goto end;
}

printf("You entered: %d\n", num);

// Ask for another number


printf("Enter another number (negative to exit): ");
scanf("%d", &num);

// If the number is negative, jump to the end


if (num < 0) {
goto end;
}

printf("You entered: %d\n", num);

// Label to jump to for exiting


end:
printf("Exiting the program.\n");

return 0;
}

OUTPUT
Enter a number (negative to exit): 5
You entered: 5
Enter another number (negative to exit): 8
You entered: 8
Exiting the program.

15
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

16
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 10: Write a c program to prepare a pay slip using the following
data.
Da = 10% of basic, Hra = 7.50% of basic, Ma = 300,
Pf = 12.50% of basic, Gross = basic + Da + Hra + Ma, Nt = Gross – Pf
#include<stdio.h>

int main() {
float basic;
printf("\n Enter Basic Salary :");
scanf("%f", & basic);
printf("\n===================================");
printf("\n SALARY SLIP");
printf("\n===================================");
printf("\n Basic : %.2f", basic);
printf("\n DA : %.2f", basic * 0.10);
printf("\n HRA : %.2f", basic * 0.075);
printf("\n MA : %.2f", 300.00);
printf("\n===================================");
printf("\n GROSS : %.2f", basic + (basic * 0.10) + (basic * 0.075) + 300.00);
printf("\n===================================");
printf("\n PF : %.2f", basic * 0.125);
printf("\n===================================");
printf("\n NET : %.2f", (basic + (basic * 0.10) + (basic * 0.075) + 300.00) -
(basic * 0.125));
printf("\n===================================");
return 0;
}

17
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

OUTPUT

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

18
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 11: Write a program to read marks from the keyboard and your
program should display an equivalent grade according to the following table
(if-else ladder)
Marks Grade
100 - 80 Distinction
79 - 60 First Class
59 - 40 Second Class
< 40 Fail

#include<stdio.h>

int main() {
int marks;
printf("\n Enter Marks between 0-100 :");
scanf("%d", & marks);
if (marks > 100 || marks < 0) {
printf("\n Your Input is out of Range");
} else if (marks >= 80) {
printf("\n You got Distinction");
} else if (marks >= 60) {
printf("\n You got First Class");
} else if (marks >= 40) {
printf("\n You got Second Class");
} else {
printf("\n You got Fail");
}
return 0;
}

OUTPUT

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

19
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 12: Write a C program to find factorial of a given number.


#include <stdio.h>

// Function to calculate factorial


unsigned long long factorial(int n) {
if (n == 0 || n == 1) {
return 1;
}
return n * factorial(n - 1);
}

int main() {
int num;
unsigned long long result;

// Prompt the user to enter a number


printf("Enter a number to find its factorial: ");
scanf("%d", &num);

// Check for negative input


if (num < 0) {
printf("Factorial of a negative number is not defined.\n");
} else {
// Calculate factorial
result = factorial(num);
// Print the result
printf("Factorial of %d is %u\n", num, result);
}

return 0;
}
OUTPUT
Enter a number to find its factorial: 5
Factorial of 5 is 120

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

20
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 13: Write a program that do sum=1+3+5+.......N terms Print value of


Sum.
#include <stdio.h>

int main() {
int N, sum = 0;

// Prompt the user to enter the number of terms


printf("Enter the number of terms: ");
scanf("%d", &N);

// Calculate the sum of the series 1 + 3 + 5 + ... up to N terms


for (int i = 0; i < N; i++) {
sum += (2 * i + 1);
}

// Print the value of the sum


printf("Sum of the series up to %d terms is: %d\n", N, sum);

return 0;
}
OUTPUT
Enter the number of terms: 5
Sum of the series up to 5 terms is: 25

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

21
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 14: Write a program to accept one number from the user. i) Display
reverse of that number. ii)Find if it is Armstrong or not.
#include <stdio.h>
#include <math.h>

// Function to calculate the number of digits in a number


int countDigits(int num) {
int count = 0;
while (num != 0) {
num /= 10;
count++;
}
return count;
}

// Function to check if a number is an Armstrong number


int isArmstrong(int num) {
int sum = 0, temp = num, remainder, n;
n = countDigits(num);

while (temp != 0) {
remainder = temp % 10;
sum += pow(remainder, n);
temp /= 10;
}

return (sum == num);


}

// Function to reverse a number


int reverseNumber(int num) {
int reversed = 0, remainder;

while (num != 0) {
remainder = num % 10;
reversed = reversed * 10 + remainder;
num /= 10;
}

return reversed;
}

int main() {
int num;

22
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

// Prompt the user to enter a number


printf("Enter a number: ");
scanf("%d", &num);

// Reverse the number


int reversed = reverseNumber(num);
printf("Reverse of the number: %d\n", reversed);

// Check if the number is an Armstrong number


if (isArmstrong(num)) {
printf("%d is an Armstrong number.\n", num);
} else {
printf("%d is not an Armstrong number.\n", num);
}

return 0;
}
OUTPUT
Enter a number: 153
Reverse of the number: 351
153 is an Armstrong number.

Enter a number: 123


Reverse of the number: 321
123 is not an Armstrong number.

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

23
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 15: Write a C program to display different Patterns.


#include <stdio.h>

// Function to display right-angled triangle pattern


void rightAngledTriangle(int rows) {
for (int i = 1; i <= rows; i++) {
for (int j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
}

// Function to display inverted right-angled triangle pattern


void invertedRightAngledTriangle(int rows) {
for (int i = rows; i >= 1; i--) {
for (int j = 1; j <= i; j++) {
printf("* ");
}
printf("\n");
}
}

// Function to display pyramid pattern


void pyramid(int rows) {
for (int i = 1; i <= rows; i++) {
// Print spaces
for (int j = i; j < rows; j++) {
printf(" ");
}
// Print stars
for (int k = 1; k <= (2*i-1); k++) {
printf("* ");
}
printf("\n");
}
}

int main() {
int rows;

// Get the number of rows for the patterns from the user
printf("Enter the number of rows: ");
scanf("%d", &rows);

24
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

printf("\nRight-angled Triangle Pattern:\n");


rightAngledTriangle(rows);

printf("\nInverted Right-angled Triangle Pattern:\n");


invertedRightAngledTriangle(rows);

printf("\nPyramid Pattern:\n");
pyramid(rows);

return 0;
}

OUTPUT:
Enter the number of rows: 5

Right-angled Triangle Pattern:


*
**
***
****
*****

Inverted Right-angled Triangle Pattern:


*****
****
***
**
*

Pyramid Pattern:
*
***
*****
*******
*********
EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

25
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 16: Write a program to accept 5 numbers in an array and display it.
#include <stdio.h>

int main() {
// Declare an array to store 5 numbers
int numbers[5];

// Prompt the user to enter 5 numbers


printf("Enter 5 numbers:\n");
for (int i = 0; i < 5; i++) {
printf("Number %d: ", i + 1);
scanf("%d", &numbers[i]);
}

// Display the numbers


printf("The numbers you entered are:\n");
for (int i = 0; i < 5; i++) {
printf("%d ", numbers[i]);
}
printf("\n");

return 0;
}
OUTPUT
Enter 5 numbers:
Number 1: 10
Number 2: 20
Number 3: 30
Number 4: 40
Number 5: 50
The numbers you entered are:
10 20 30 40 50

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

26
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 17: Write a program to accept 9 numbers in form of a matrix and


display it in matrix form.
#include <stdio.h>

#define ROWS 3
#define COLS 3

int main() {
// Declare a 2D array (matrix) to store 9 numbers
int matrix[ROWS][COLS];

// Prompt the user to enter 9 numbers for the matrix


printf("Enter 9 numbers for the matrix (3x3):\n");
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
printf("Enter element at position [%d][%d]: ", i + 1, j + 1);
scanf("%d", &matrix[i][j]);
}
}

// Display the matrix


printf("\nThe matrix you entered is:\n");
for (int i = 0; i < ROWS; i++) {
for (int j = 0; j < COLS; j++) {
printf("%d\t", matrix[i][j]);
}
printf("\n");
}

return 0;
}
OUTPUT
Enter 9 numbers for the matrix (3x3):
Enter element at position [1][1]: 1
Enter element at position [1][2]: 2
Enter element at position [1][3]: 3
Enter element at position [2][1]: 4
Enter element at position [2][2]: 5
Enter element at position [2][3]: 6
Enter element at position [3][1]: 7
Enter element at position [3][2]: 8
Enter element at position [3][3]: 9

27
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

The matrix you entered is:


1 2 3
4 5 6
7 8 9

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

28
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 18: Write a program to accept 5 numbers in array and find the
maximum and minimum values of it.
#include <stdio.h>

#define SIZE 5

int main() {
int numbers[SIZE];
int max, min;

// Prompt the user to enter 5 numbers


printf("Enter 5 numbers:\n");
for (int i = 0; i < SIZE; i++) {
printf("Number %d: ", i + 1);
scanf("%d", &numbers[i]);
}

// Initialize max and min with the first element of the array
max = min = numbers[0];

// Find maximum and minimum values in the array


for (int i = 1; i < SIZE; i++) {
if (numbers[i] > max) {
max = numbers[i];
}
if (numbers[i] < min) {
min = numbers[i];
}
}

// Display the maximum and minimum values


printf("\nMaximum value: %d\n", max);
printf("Minimum value: %d\n", min);

return 0;
}
OUTPUT
Enter 5 numbers:
Number 1: 10
Number 2: 5
Number 3: 8
Number 4: 15
Number 5: 3

Maximum value: 15

29
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Minimum value: 3

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

30
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 19: Write a C program to find 1+1/2+1/3+1/4+....+1/n


#include <stdio.h>

int main() {
int n;
double sum = 0.0;

// Prompt the user to enter a positive integer


printf("Enter a positive integer: ");
scanf("%d", &n);

// Check if the input is valid


if (n <= 0) {
printf("Please enter a positive integer greater than 0.\n");
return 1; // Exit the program with an error code
}

// Calculate the sum of the series


for (int i = 1; i <= n; i++) {
sum += 1.0 / i;
}

// Display the result


printf("Sum of the series 1 + 1/2 + 1/3 + ... + 1/%d is: %.6f\n", n, sum);

return 0;
}
OUTPUT
Enter a positive integer: 5
Sum of the series 1 + 1/2 + 1/3 + ... + 1/5 is: 2.283334

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

31
Programming for Problem Solving-I [2BTES101] Dr. Subhash University

Practical 20: Write a program to count a number of vowels in a given string.


#include <stdio.h>
#include <ctype.h>

int main() {
char str[100];
int count = 0;

// Prompt the user to enter a string


printf("Enter a string: ");
fgets(str, sizeof(str), stdin);

// Iterate through each character in the string


for (int i = 0; str[i] != '\0'; i++) {
// Convert the character to lowercase to make the comparison case-
insensitive
char ch = tolower(str[i]);

// Check if the character is a vowel


if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
count++;
}
}

// Display the result


printf("Number of vowels in the string: %d\n", count);

return 0;
}
OUTPUT
Enter a string: Hello, World!
Number of vowels in the string: 3

EVALUATION:

Observation & Timely


Viva Total
Implementation Completion
4 2 4 10

Sign: Date:

32

You might also like