Full list 'C' programs that are most searched by beginners

C programming

#1 C program to check if the number is even or odd.

#include<stdio.h> /*header files*/
int main()
{
            int number; /* declaring variables*/
            printf("Enter a number");
            scanf("%d",&number); /* ask the user to enter a number*/
            if(number%2==0)
            {
                        printf("\n The Entered number is even"); /* check if the number is even */
            }
            else
            {
                        printf("\n Entered number is odd");
            }
            return 0;
}

#2 C program to check if entered year is leap year or not

#include<stdio.h> /*header files*/
int main()
{
            int year; /* declaring variables*/
            printf("Enter a year");
            scanf("%d",&year); /* ask the user to enter a year*/
            if(year%100==0)
            {
                        if(year%400==0)
                        {
                                    printf("\n It is a leap year");
                        }
                        else
                        {
                                    printf("\n Not a leap year");
                        }
            }
            else if(year%4==0)
            {
                        printf("\n It is a leap year");
            }
            else
            {
                        printf("\n Not a leap year");
            }
            return 0;
            }

#3 C program to check if entered character is vowel or consonant

#include<stdio.h>
int main()
{
            char a; /* declare a variable as character*/
            printf("Enter a character");
            scanf("%c",&a); /* ask user to enter a character*/
            if(a=='a'||a=='e'||a=='i'||a=='o'||a=='u'||a=='A'||a=='E'||a=='I'||a=='O'||a=='U') /*check condition*/
            {
                        printf("\n It is a vowel");
            }
            else
            {
                        printf("\n It is a consonant");     /*The output*/
            }
           
            return 0;
           }

#4 C program to find sum of first n numbers.

#include<stdio.h>
int main()
{
int a,i,sum=0;
            printf("\nEnter a number to find the sum of first n numbers\n");
            scanf("%d",&a);
                        for(i=0;i<=a;i++)
            {
                        sum=sum+i;
            }
            printf("\n\tSum of first %d numbers is %d",a,sum);
            return 0;
}

#5 C program to find factorial of a number

#include<stdio.h>
int main()
{
            int a,i,fact;
            printf("\nEnter a number to find its factorial");
            scanf("%d",&a);
            fact=a;
            for(i=a-1;i>0;i--)
            {
                        fact=fact*i;
            }
            printf("\n\tFactorial of %d is %d",a,fact);
            return 0;
}

#6 C program to display Fibonacci series


#include<stdio.h>
int main()
{
 int n, first = 0, second = 1, next, i;

   printf("\nEnter the number of terms for Fibonacci series\n");
   scanf("%d",&n);

   printf("\tFirst %d terms of Fibonacci series are :-\n",n);

   for ( i = 0 ; i < n ; i++ )
   {
      if ( i <= 1 )
         next = i;
      else
      {
         next = first + second;
         first = second;
         second = next;
      }
      printf("%d\n",next);
   }

   return 0;

}

These were the list of C programs for beginners. If you liked the post, then why not share with your friends too? Click on below social buttons to share this post.
If you have any doubt then you can comment here. I am always there to reply.

SHARE ON:

    Blogger Comment

0 comments:

Post a Comment

Comment Below. Because I love to hear from YOU