NAME-UDAY
ROLL NO-1324044
PROGRAM-13
WRITE A PROGRAM TO PERFORM ON STRINGS -
1] ALGORITHM-
Step1] start
Step2] input the elements
Step3] initialize the given information
Step4] print output
Step5] stop
2] flow chart- START
Input elements
processings
Apply the conditions
end
3] SOURCE CODE-
#include <stdio.h>
#include <ctype.h> // For the tolower() funcƟon
int main() {
char str[100];
int vowelCount = 0;
// Accept the string from the user
prinƞ("Enter a string: ");
fgets(str, sizeof(str), stdin); //
for (int i = 0; str[i] != '\0'; i++) {
char ch = tolower(str[i]);l
if (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u') {
vowelCount++;
}
printf("Number of vowels in the string: %d\n", vowelCount); // Output
return 0
}
OUTPUT-
NAME-UDAY
ROLL NO.1324044
PROGRAM NO.13 B
STATEMENT:
c.) Write a program to concaƟnate two string.
ALGORITHM:
1. Start
2. Declare two variables to hold the strings: str1 and str2.
3. Input the first string.
4. Input the second string.
5. Remove extra newline characters (if present) from both strings to clean the input.
6. Concatenate the second string to the first string:
o Use the strcat funcƟon to append (str2) to the end of (str1).
7. Output the concatenated string:
o Show the final result of the concatenaƟon (str1 aŌer appending str2).
8. stop
2] flow chart- START
Input elements
processings
Apply the conditions
end
SOURCE CODE-
#include <stdio.h>
#include <string.h>
int main() {
char str1[100], str2[50];
prinƞ("Enter the first string: "); // Input the string
fgets(str1, sizeof(str1), stdin);
str1[strcspn(str1, "\n")] = '\0'; // Remove the newline character from the input
prinƞ("Enter the second string: ");
fgets(str2, sizeof(str2), stdin);
str2[strcspn(str2, "\n")] = '\0'; // Remove the newline character from the input
// Concatenate str2 to str1
strcat(str1, str2);
// Output the concatenated string
prinƞ("The concatenated string is: %s\n", str1);
return 0;
}
OUTPUT-
NAME-UDAY
ROLL NO.1324044
PROGRAM NO.14
Statement:
Write a program to swap two integers using call by value and call by reference methods of
passing arguments to a function.
Algorithm:
1. Start
2. Input Values: Tell the user to enter two integers, x and y.
3. Display Original Values: Print the original values of x and y before performing any swap.
4. Swap Using Call by Value:
5. Display Values AŌer Call by Value: Print the values of x and y aŌer the call to
6. Swap Using Call by Reference: Call the funcƟon swapByReference(&x, &y)
7. STOP
2] flow chart- START
Input elements
processings
Apply the conditions
end
OUTPUT-
#include<stdio.h>
void change(int num) {
printf("Before adding value inside function num=%d \n",num);
num=num+100;
printf("After adding value inside function num=%d \n", num);
int main() {
int x=100;
printf("Before function call x=%d \n", x);
change(x);//passing value in function
printf("After function call x=%d \n", x);
return 0;
OUTPUT-
NAME-UDAY
ROLL NO.1324044
PROGRAM NO.15
15] Write a program to calculate the sum of first 20 natural numbers using
recursive function.
Algorithm:
1. Start: Begin the process of calculating the sum of the first 20 natural numbers (for
this problem, n=20n = 20n=20).
2. Define the Recursive Function:
Input: A number 20(natural number).
3. Recursive Calls: The function will repeatedly call itself with a smaller value of natural
(i.e., n−1n - 1n−1) unit it reaches the base case where n=1n = 1n=1.
4. Return the Sum: Once the base case is reached, the sum is calculated as the
recursion "unwinds", with each call returning the value of the sum.
5. Output: over the recursion completes, the sum of the first 20 natural numbers is
printed.
6. stop
2] flow chart- START
Call sum (n)
Add n to result
Return sum(n)
end
SOURCE CODE-
#include <stdio.h>
int main() {
int n, i, sum = 0;
printf("Enter a positive integer: ");
scanf("%d", &n);
for (i = 1; i <= n; ++i) {
sum += i;
}
printf("Sum = %d", sum);
return 0;
OUTPUT-