19 December 2023

C Program to Find the Length of a String

C program uses an array of characters (char str[100]) to store the input string. It uses fgets to read the string from the user, ensuring that it doesn’t overflow the array. The length of the string is then calculated using a while loop that iterates until it encounters the null character (‘\0’) or a newline character (‘\n’). The null character indicates the end of the string in C. Finally, the program prints the length of the string to the console. Method 1 : #include<stdio.h>void main(){int i=0;char input[20];printf(“Enter any String :”);gets(input);while(input[i]!=’\0′){i++;}printf(“Length of given string: %d”,i);} Output : Method 2 : #include<stdio.h>#include<conio.h>#include<string.h>void main(){char input[80];int i;printf(“Enter the string: “);gets(input);i=strlen(input);printf(“The length of the string is : %d”,i);} Output :

C Program to Find the Length of a String Read More »

C Program to Reverse a Given Number

This c program takes an integer as input, stores the original number in a separate variable, and then reverses the digits of the number using a while loop. The reversed number is then displayed on the screen along with the original number. Program : #include<stdio.h>#include<conio.h>main(){int n,r=0;printf(“Enter a number to reverse : “);scanf(“%d”,&n);while(n!=0){r=r*10;r=r+n%10;n=n/10;}printf(“Reverse of Entered Number is = %d\n”,r);} Output :

C Program to Reverse a Given Number Read More »

C Program to Display Fibonacci Series in a Given Range

The Fibonacci series is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. Here’s a simple C program to display the Fibonacci series up to a specified number of terms Program : #include<stdio.h>#include<conio.h>void main(){int a,b,c,i,n;a=0;b=1;printf(“\nEnter n for how many times generate series : “);scanf(“%d”,&n);printf(“\nFibonacci Series : \n”);printf(“%d %d “,a,b);for(i=0;i<=n-3;i++){c=a+b;a=b;b=c;printf(“%d “,c);}getch();} Output :

C Program to Display Fibonacci Series in a Given Range Read More »

C Program to Check a Given Year is a Leap Year or not

Here’s a simple C program to check whether a given year is a leap year or not. This program prompts the user to enter a year, and then it checks whether the entered year is a leap year or not. The logic for checking leap years is as follows: Then it is a leap year. Otherwise, it is not a leap year. The program displays the result accordingly. Program : #include<stdio.h>#include<conio.h>int main(){int year;printf(“Enter a year to check if it is a leap year : “);scanf(“%d”,&year);if(year%400==0){printf(“%d is a leap year.\n”,year);}else if(year%100==0){printf(“%d is not a leap year.\n”,year);}else if(year%4==0){printf(“%d is a leap year.\n”,year);}else{printf(“%d is not a leap year.\n”,year);}} Output :

C Program to Check a Given Year is a Leap Year or not Read More »

Shopping Basket
Select the fields to be shown. Others will be hidden. Drag and drop to rearrange the order.
  • Image
  • SKU
  • Rating
  • Price
  • Stock
  • Availability
  • Add to cart
  • Description
  • Content
  • Weight
  • Dimensions
  • Additional information
Click outside to hide the comparison bar
Compare
Verified by MonsterInsights