How to find the number of days in a month in C.
C Program to Print Number of Days in a Month using Switch Case Statement
How to find the number of days in a month in C.
C Hello World Program
Printing "Hello World" program is one of the simplest programs in C programming languages. It become the traditional first program that many people write while learning a new programming language. Hello world program helps in understanding basic syntax of C programming language and C program structure to novice programmers.
C Program to Display Current Date and Time
In this program, to get current time and print it in human readable string after converting it into local time we are using two functions defined in time.h header file time() and ctime().
C Program to Divide a String into Two Equal Strings
Here is a C program to divide a string in two equal sub strings. Given a string of length L, we have to split this string into two equal sub-strings.
- If L is even, then length of the sub-strings will be L/2 and L/2.
- If L is off, the length of sub-strings will be L/2 and (L/2)+1
Input : "Internet" Output : "Inte" and "rnet"
Let inputString be the string entered by user and leftHalf and rightHalf are two output sub-strings.
- Find length of the string using strlen function. Let it be L.
- Find the mid index of input string. (mid = L/2)
- Copy characters of inputString from index 0 to mid to leftHalf.
- Copy characters of inputString from index mid+1 to L-1 to rightHalf.
C program to split a string into two equal strings
In this program, we will first read a string as input from user using gets function. Then we find the length of input string(L) using strlen function of string.h header file. Now, we will create two sub-strings as explained above and print it on screen.
#include<stdio.h> #include<string.h> int main() { char inputString[100], leftHalf[100], rightHalf[100]; int length, mid, i, k; printf("Enter a string\n"); gets(inputString); length = strlen(inputString); mid = length/2; for(i = 0; i < mid; i++) { leftHalf[i]= inputString[i]; } leftHalf[i] = '\0'; for(i = mid, k = 0; i <= length; i++, k++) { rightHalf[k]= inputString[i]; } printf("Left half : %s\n",leftHalf); printf("Right half : %s\n",rightHalf); return 0; }Output
Enter a string TECHCRASHCOURSE Left half : TECHCRA Right half : SHCOURSE
Related Topics
C program to print triangle, pyramid, geometrical shapes and star patterns
Pattern printing programs in C are not just about creating visually appealing shapes and designs on the console. They serve a much greater purpose, especially for beginners learning the basics of programming. In this article, we'll dive into some standard patterns, advantages of pattern printing programs, their importance for beginners, and some tips for writing them effectively.
C program to print right triangle pyramid pattern of multiplication tables
Here is a C program to print right triangle pattern of multiplication table. Here is a sample right triangle pattern of multiplication table.
C Program to Print Binary Rectangular Pattern Of 0 and 1
Here is a C program to print binary rectangle pattern where all boundary elements are 0 and all inner elements are 1. The C Program to Print Binary Rectangular Pattern of 0 and 1 is a fascinating exercise that combines the concepts of binary numbers and pattern printing in C programming.
C Program to Print Binary Numbers Right Triangle Pyramid Pattern
Here is a C program to print right triangle of binary number. This C Program to Print Binary Numbers Right Triangle Pyramid Pattern is an educational exercise that introduces beginners to the concept of binary numbers and patterns in programming. For a binary number right triangle of 6 rows, program's output should be:
C Program to Print Triangle Pattern of Prime Numbers
Here is a C program to print right triangle pattern of prime numbers. The C Program to Print Triangle Pattern of Prime Numbers is a challenging exercise that combines the concepts of prime numbers and patterns in programming. Here is a prime number pyramid or triangle pattern of four rows:
C Program to Print Triangle Pattern Having Same Number In a Row
Here is a C program to print right triangle having same number in a row. For a right triangle of 6 rows, program's output should be:
C Program to Print Palindrome Triangle Pattern
Here is a C program to print palindrome triangle pattern of n rows. This C Program to Print Palindrome Triangle Pattern is an intriguing exercise that combines the concepts of palindromes and patterns in programming. Exploring the Palindrome Triangle Pattern Program in C offers you a unique opportunity to enhance your understanding of palindromes, pattern recognition, nested loops, algorithmic thinking, and string manipulation concepts. It equips you with valuable skills that are essential for your growth as a programmer.
Palindrome triangle pattern of 5 rows:
C Program to Print Natural Numbers in Right Triangle Pattern
Here is a C program to print natural numbers right angled triangle. This C Program to print Natural Numbers in Right Triangle Pattern is an educational exercise that introduces beginners to the concept of patterns in programming.For a right triangle of 4 rows. Program's output should be:
C Program to Print Hollow Pyramid Star Pattern
Write a C program to print hollow pyramid star pattern. Hollow pyramid star pattern program's output should be:
C Program to Print Heart Star Pattern
Here is a C program to print a heart shape star pattern using for loop. Heart star pattern program's output should be:
C Program to Print Hut Star Pattern
Here is a C program to print a Hut star pattern. Hut star pattern program's output should be:
C Program to Print Hollow Diamond Star Pattern
Here is a C program to print hollow diamond star pattern. Hollow Diamond star pattern program's output should be:
C Program to Print Diamond Star Pattern
Here is a C program to print diamond star pattern using for loop. Diamond star pattern program's output should be:
C Program to Print Rhombus Star Pattern
Here is a C program to print rhombus star pattern using for loop. The Rhombus Star Pattern Printing Program in C is a fascinating exercise that introduces beginners to geometric patterns and shapes. For a rhombus star pattern of 6 rows. Program's output should be:
C Program to Print Reverse Pyramid Star Pattern
Here is a C program to print inverted triangle star pattern till n rows using loops. This pattern is also known as inverted pyramid star pattern. For an reversed equilateral triangle pyramid star pattern of 5 rows. Program's output should be:
C Program to Print Pyramid Star Pattern
Here is a C program to print an equilateral triangle star pattern of n rows using loops.