palindrome numbers in a given range


#include<stdio.h>
#include<conio.h>
void main(){
   int num, rem, reverse, temp, start, end;

   printf("Enter the lower Number");
   scanf("%d",&start);

   printf("Enter the upper Number");
   scanf("%d",&end);

   printf("Palindrome numbers between %d and %d are: ",start,end);
   for(num=start;num<=end;num++){
      temp=num;
      reverse=0;
      while(temp){
         rem=temp%10;
         temp=temp/10;
         reverse=reverse*10+rem;
      }
      if(num==reverse)
         printf("%d ",num);
   }
   getch();
}

check Armstrong number



#include<stdio.h>
#include<conio.h>
void main()
{
int num,temp,sum=0,rem;

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

   temp= num;

   while (num != 0)
   {
      rem = num % 10;
      sum = sum + (rem*rem*rem);
      num = num / 10;
   }

   if(temp == sum)
      printf("\n%d is an Armstrong Number",temp);
   else
      printf("\n%d is not an Armstrong Number",temp);
   getch();
}

Reverse number using Recursion



#include<stdio.h>
#include<conio.h>
void main()
{
int num,reverse_number;
   printf("\nEnter any number:");
   scanf("%d",&num);
   reverse_number=reverse_function(num);
   printf("\nAfter reverse the no is :%d",reverse_number);
   getch();
}
int sum=0,rem;
reverse_function(int num){
   if(num){
      rem=num%10;
      sum=sum*10+rem;
      reverse_function(num/10);
   }
   else
      return sum;
   return sum;
}


Fibonacci Series

#include<stdio.h>
#include<conio.h>
int main()
{
    int count, first = 0, second = 1, next, i;
 
    
    printf("Enter the number of terms:\n");
    scanf("%d",&count);
 
    printf("First %d terms of Fibonacci series:\n",count);
    for ( i = 0 ; i < count ; i++ )
    {
       if ( i <= 1 )
          next = i;
       else
       {
          next = first + second;
          first = second;
          second = next;
       }
       printf("%d\n",next);
    }
 
    getch();
}

Find ASCII value of a Character



#include<stdio.h>
#include<conio.h>
void main()
{
    char ch;
    printf("Enter any character:");
    scanf("%c", &ch);
    printf("ASCII value of character %c is: %d", ch, ch);
    getch();
}

check if a number is palindrome or not


#include<stdio.h>
#include<conio.h>
void main()
{
   int num, reverse=0, remainder,temp;
   printf("Enter an integer: ");
   scanf("%d", &num);

   temp=num;
   while(temp!=0)
   {
      remainder=temp%10;
      reverse=reverse*10+remainder;
      temp/=10;
   } 
 
   if(reverse==num) 
      printf("%d is a palindrome number",num);
   else
      printf("%d is not a palindrome number",num);
   getch();
}

find the size of data types in C

#include<stdio.h>
#include<conio.h>
void main()
{

    printf("Size of char: %ld byte\n",sizeof(char));
    printf("Size of int: %ld bytes\n",sizeof(int));
    printf("Size of float: %ld bytes\n",sizeof(float));
    printf("Size of double: %ld bytes", sizeof(double));
    getch();
}

check Leap Year

#include<stdio.h>
#include<conio.h>
void main()
{
int y;

    printf("Enter year: ");
    scanf("%d",&y);

    if(y % 4 == 0)
    {
    	
        if( y % 100 == 0)
        {
            if ( y % 400 == 0)
                printf("%d is a Leap Year", y);
            else
                printf("%d is not a Leap Year", y);
        }
        else
            printf("%d is a Leap Year", y );
    }
    else
        printf("%d is not a Leap Year", y);

    getch();
}

convert uppercase string to lowercase string
                                
#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(){
   
   char str[25];
   int i;
   printf("Enter the string: ");
   scanf("%s",str);
 
   for(i=0;i<=strlen(str);i++){
      if(str[i]>=65&&str[i]<=90)
         str[i]=str[i]+32;
   }
   printf("\nLower Case String is: %s",str);
  getch();
}

convert lowercase string to uppercase

#include<stdio.h>
#include<conio.h>
#include<string.h>

void main()
{
   char str[25];
   int i;

   printf("Enter the string:");
   scanf("%s",str);

   for(i=0;i<=strlen(str);i++){
      if(str[i]>=97&&str[i]<=122)
         str[i]=str[i]-32;
   }
   printf("\nUpper Case String is: %s",str);
   getch();
}

Sorting of a Set of Strings in Ascending alphabetical order

#include<stdio.h>
#include<conio.h>
#include<string.h>
void main(){
   int i,j,count;
   char str[25][25],temp[25];
   puts("How many strings u are going to enter ? ");
   scanf("%d",&count);

   puts("Enter Strings one by one ");
   for(i=0;i<=count;i++)
      gets(str[i]);
   for(i=0;i<=count;i++)
      for(j=i+1;j<=count;j++){
         if(strcmp(str[i],str[j])>0){
            strcpy(temp,str[i]);
            strcpy(str[i],str[j]);
            strcpy(str[j],temp);
         }
      }
   printf("Order of Sorted Strings:");
   for(i=0;i<=count;i++)
      puts(str[i]);
   
   getch();
}

find the length of a String without using function strlen()

#include<stdio.h>
#include<conio.h>
#include <stdio.h>
void main()
{
    char str[100],i;
    printf("Enter a string: \n");
    scanf("%s",str);
    for(i=0; str[i]!='\0'; ++i);
       printf("\nLength of input string: %d",i);
    
  getch();
}

concatenate two strings without using strcat

#include<stdio.h>
#include<conio.h>
#include<stdio.h&ht;
void main()
{
   char str1[50], str2[50], i, j;
   printf("\nEnter first string: ");
   scanf("%s",str1);
   printf("\nEnter second string: ");
   scanf("%s",str2);
   
   for(i=0; str1[i]!='\0'; ++i); 
 
   for(j=0; str2[j]!='\0'; ++j, ++i)
   {
      str1[i]=str2[j];
   }
   str1[i]='\0';
   printf("\nOutput: %s",str1);
   
   getch();
}

arrange numbers in ascending order

#include<stdio.h>
#include<conio.h>
void sort_numbers_ascending(int number[], int count)
{
   int temp, i, j, k;
   for (j = 0; j < count; ++j)
   {
      for (k = j + 1; k < count; ++k)
      {
         if (number[j] > number[k])
         {
            temp = number[j];
            number[j] = number[k];
            number[k] = temp;
         }
      }
   }
   printf("Numbers in ascending order:\n");
   for (i = 0; i < count; ++i)
      printf("%d\n", number[i]);
}
void main()
{
   int i, count, number[20];
 
   printf("How many numbers you are gonna enter:");
   scanf("%d", &count);
   printf("\nEnter the numbers one by one:");
   
   for (i = 0; i < count; ++i)
      scanf("%d", &number[i]);
 
   sort_numbers_ascending(number, count);
getch();
}

find largest element of an Array

#include<stdio.h>
#include<conio.h>

int largest_element(int arr[], int num)
{
    int i, max_element;
    max_element = arr[0];
    for (i = 1; i < num; i++)         
        if (arr[i] > max_element)
            max_element = arr[i];
 
    return max_element;
}
 
void main()
{
    int arr[] = {1, 24, 145, 20, 8, -101, 300};
    int n = sizeof(arr)/sizeof(arr[0]);
    printf("Largest element of array is %d", largest_element(arr, n));
    getch();
}

display its own source code using __FILE__

#include<stdio.h>
#include<conio.h>
void main() {
    FILE *fp;
    char c;
    fp = fopen(Rain.c,"r");
    do {
         c = getc(fp);
         putchar(c);
    }
    while(c != EOF);
    fclose(fp);
    getch();
}

Copy String Without Using strcpy()

#include<stdio.h>
#include<conio.h>
void main()
{
    char s1[100], s2[100], i;

    printf("Enter string s1: ");
    scanf("%s",s1);

    for(i = 0; s1[i] != '\0'; ++i)
    {
        s2[i] = s1[i];
    }

    s2[i] = '\0';
    printf("String s2: %s", s2);

    getch();
}

Remove all Characters in a String Except Alphabet

#include<stdio.h>
#include<conio.h>
void main()
{
    char line[150];
    int i, j;
    printf("Enter a string: ");
    gets(line);

    for(i = 0; line[i] != '\0'; ++i)
    {
        while (!( (line[i] >= 'a' && line[i] <= 'z') || (line[i] >= 'A' && line[i] <= 'Z') || line[i] == '\0') )
        {
            for(j = i; line[j] != '\0'; ++j)
            {
                line[j] = line[j+1];
            }
            line[j] = '\0';
        }
    }
    printf("Output String: ");
    puts(line);
    getch();
}

count the number of vowels, consonants and so on

#include<stdio.h>
#include<conio.h>
int main()
{
    char ch[150];
    int i, vowels, consonants, digits, spaces;

    vowels =  consonants = digits = spaces = 0;

    printf("Enter a ch of string: ");
    scanf("%[^\n]", ch);

    for(i=0; ch[i]!='\0'; ++i)
    {
        if(ch[i]=='a' || ch[i]=='e' || ch[i]=='i' ||
           ch[i]=='o' || ch[i]=='u' || ch[i]=='A' ||
           ch[i]=='E' || ch[i]=='I' || ch[i]=='O' ||
           ch[i]=='U')
        {
            ++vowels;
        }
        else if((ch[i]>='a'&& ch[i]<='z') || (ch[i]>='A'&& ch[i]<='Z'))
        {
            ++consonants;
        }
        else if(ch[i]>='0' && ch[i]<='9')
        {
            ++digits;
        }
        else if (ch[i]==' ')
        {
            ++spaces;
        }
    }

    printf("Vowels: %d",vowels);
    printf("\nConsonants: %d",consonants);
    printf("\nDigits: %d",digits);
    printf("\nWhite spaces: %d", spaces);

   getch();
}

Factors of a Positive Integer

#include<stdio.h>
#include<conio.h>
void main()
{
    int x,i;

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

    printf("Factors of %d are: ", x);
    for(i=1; i <= x; ++i)
    {
        if (x%i == 0)
        {
            printf("%d ",i);
        }
    }

    getch();
}

Count Number of Digits in an Integer

#include<stdio.h>
#include<conio.h>
void main()
{
    long long n;
    int count = 0;

    printf("Enter an integer: ");
    scanf("%lld", &n);

    while(n != 0)
    {
        // n = n/10
        n /= 10;
        ++count;
    }

    printf("Number of digits: %d", count);
getch();
}

Check Whether a Character is an Alphabet or not

#include<stdio.h>
#include<conio.h>
void main()
{
    char c;
    printf("Enter a character: ");
    scanf("%c",&c);

    if( (c>='a' && c<='z') || (c>='A' && c<='Z'))
        printf("%c is an alphabet.",c);
    else
        printf("%c is not an alphabet.",c);

    getch();
}