To write a C Program to perform the basic left shift operation for 44 integer number with 3 shifts.
- Start the program.
- Assign values of a and b as 44 and 3.
- Use left shift operator (<<) and shift the value of a three times.
- Display the result.
- Stop the program.
#include <stdio.h>
int main()
{
int num = 44;
printf("Num value = %d\n",num);
int result;
result = num << 3;
printf("After left shift : %d\n", result);
return 0;
}
Thus the program to perform the basic left shift operation for 44 integer number with 3 shifts has been executed successfully.
Write a C Program to check whether the two numbers are equal or not using simple if statement.
- Start the program.
- Read two numbers.
- If first number is equal to second number, display both are equal.
- Otherwise display both are not equal.
- Stop the program.
#include <stdio.h>
int main()
{
int a, b;
printf("Enter two numbers: ");
scanf("%d %d", &a, &b);
if (a == b)
printf("Both numbers are equal.\n");
else
printf("Numbers are not equal.\n");
return 0;
}
Thus the program to check whether the two numbers are equal or not using simple if statement has been executed successfully
Write a C Program to convert the given string into lowercase.
- Start the program.
- Read a string variable.
- Using tolower( ) function convert the given string into its lowercase.
- Display the result.
- Stop the program.
#include <stdio.h>
#include <string.h>
#include <ctype.h>
int main()
{
char str[100];
int i;
printf("Enter a string: ");
gets(str);
for (i = 0; str[i] != '\0'; i++)
{
str[i] = tolower(str[i]);
}
printf("String in lowercase: %s\n", str);
return 0;
}
Thus the program to convert the given string into lowercase has been executed successfully
Write a C Program to count the total number of words in a given string using do While loop.
- Start the program.
- Read a string variable.
- Using for loop, inspect the string character by character.
- Whenever a space is encountered increment count by 1.
- Display the result.
- Stop the program.
#include <stdio.h>
#include <string.h>
int main() {
char str[200];
int i = 0, count = 0;
printf("Enter a string: ");
fgets(str, sizeof(str), stdin);
str[strcspn(str, "\n")] = '\0';
if(str[0] != '\0')
count = 1;
do {
if(str[i] == ' ' && str[i+1] != '\0' && str[i+1] != ' ')
count++;
i++;
} while(str[i] != '\0');
printf("Total number of words = %d\n", count);
return 0;
}
Thus the program to count the total number of words in a given string using do While loop has been executed successfully
write a Program to compare two strings without using strcmp().
Step 1: Start the program.
Step 2: Declare two character arrays c1 and c2 of size 100 to store the strings. Also, declare an integer variable
flag and initialize it to 0, and i for indexing.
Step 3: Read the first string c1 using scanf("%[^\n]", c1); — this reads input until a newline is encountered
(i.e., can include spaces).
Step 4: Read the second string c2 using scanf("%s", c2); — this reads input until a space or newline (i.e., no
spaces in the second string).
Step 5: Start comparing characters of both strings from index i = 0.
Step 6: Repeat the following while neither c1[i] nor c2[i] is '\0' (i.e., end of string):
• If c1[i] is not equal to c2[i], set flag = 1.
• Increment i by 1.
Step 7: After the loop, check the value of flag:
• If flag == 0, print "strings are same".
• Otherwise, print "strings are not same".
Step 8: End the program.
#include <stdio.h>
int main()
{
char c1[100], c2[100];
int i = 0, flag = 0;
printf("Enter the first string: ");
scanf(" %[^\n]", c1);
printf("Enter the second string: ");
scanf("%s", c2);
while(c1[i] != '\0' && c2[i] != '\0')
{
if(c1[i] != c2[i])
{
flag = 1;
break;
}
i++;
}
if(c1[i] != '\0' || c2[i] != '\0')
flag = 1;
if(flag == 0)
printf("Strings are same\n");
else
printf("Strings are not same\n");
return 0;
}
Thus the C Program to compare two strings without using strcmp() has been executed successfully.




