Make a reverse half piramid using numbers

5 5 5 5 5 4 4 4 4 3 3 3 2 2 1



Program : -

#include<stdio.h> #include<conio.h> int main() { int i,j,rows; printf("Enter the number of rows :"); scanf("%d",&rows); for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { printf("%d ",i); } printf("\n"); } getch(); }

Output : -


Enter the number of rows :5

5 5 5 5 5 4 4 4 4 3 3 3 2 2 1

C Program to print inverted half pyramid using number

1 2 3 4 5 1 2 3 4 1 2 3 1 2 1




Program : -

#include<stdio.h> #include<conio.h> int main() { int i,j,rows; printf("Enter the number of rows :"); scanf("%d",&rows); for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { printf("%d ",j); } printf("\n"); } getch(); }

Output : -


Enter the number of rows :5

1 2 3 4 5 1 2 3 4 1 2 3 1 2 1

Write a C Program to print inverted half pyramid using Number

* * * * * * * * * * * * * * *



Program : -



#include<stdio.h> #include<conio.h> void main() { int i,j,rows; printf("Enter the number of rows : "); scanf("%d",&rows); for(i=rows;i>=1;--i) { for(j=1;j<=i;++j) { printf("* "); } printf("\n"); } getch(); }



Output : -

Enter the number of rows : 5
* * * * * * * * * * * * * * *

Make a alphabet pattern

A B B
C C C D D D D E E E E E


Program : -


#include<stdio.h> #include<conio.h> void main() { int i,j; char input,temp='A'; printf("Enter uppercase character you want in triangle at last row: "); scanf("%c",&input); for(i=1;i<=(input-'A'+1);++i) { for(j=1;j<=i;++j) printf("%c",temp); ++temp; printf("\n"); } getch(); }


Output : -

Enter uppercase character you want in triangle at last row: E
A B B C C C D D D D E E E E E

Make a half piramid of numbers


1 1 2 1 2 3 1 2 3 4 1 2 3 4 5


Program : -




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

    printf("Enter the number of rows :");
    scanf("%d",&rows);

    for(i=1;i<=rows;++i)
    {
        for(j=1;j<=i;++j)
        {
           printf("%d ",j);
        }
        printf("\n");
    }

    getch();
}

Output : -

Enter the number of rows :5
1 1 2 1 2 3 1 2 3 4 1 2 3 4 5

Make half piramid using *





*
* *
* * *
* * * *
* * * * *



Program : -



#include<stdio.h> 
#include<conio.h> 
int main()
{
    int i,j,rows;
    printf("Enter the number of rows: ");
    scanf("%d",&rows);
    for(i=1;i<=rows;++i)
    {
        for(j=1;j<=i;++j)
        {
           printf("* ");
        }
        printf("\n");
    }
    getch();
}
 
 
Output :-
 
Enter the number of rows: 5
 
*
* *
* * *
* * * *
* * * * *  

Display characters from a to z using loop

Program : -




#include<stdio.h>
#include<conio.h>
void main()
{
    char c;
    for(c='A'; c<='Z'; ++c)
       printf("%c ",c);
    getch();
}



Output : -

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Search array element from array

C Program to search array element from array : -



Program : -


#include<stdio.h>
#include<conio.h>
#include<string.h>
 void main()
 {
    int a[10],i,no,temp=0;
    clrscr();
    puts("Enter the 10 array element :");
    for(i=0;i<10;i++)
    {
        scanf("%d",&a[i]);
    }
    puts("Enter any no. to check :");
    scanf("%d",&no);
    for(i=0;i<10;i++)
    {
        if(no==a[i])
        {
            temp=1;
            puts("The no is exist");
            break;
        }
    }
    if(temp==0)
    {
        puts("The no is not exist");
    }
    getch();
 }



Output 1 : -

Enter the 10 array element : 1 2 3 4 5 6 7 8 9 10
Enter any no. to check : 5
The no is exist


Output 2 : -

Enter the 10 array element : 1 2 3 4 5 6 7 8 9 10
Enter any no. to check : 11
The no is not exist

Multiplay two array

C Program to Multiplay two array : -

Program : -

#include<stdio.h>
#include<conio.h>
#include<string.h>
 void main()
 {
    int a[5],b[5],c[5],i;
    clrscr();
    puts("Enter the first array element :");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }

    puts("Enter the second array element :");
    for(i=0;i<5;i++)
    {
        scanf("%d",&b[i]);
    }

    puts("The third array element is :");
    for(i=0;i<5;i++)
    {
        c[i]=a[i]*b[i];
        printf("%d  ",c[i]);
    }
    getch();
 }

 

Output : -

Enter first array element : 1 2 3 4 5

Enter second array element : 5 4 3 2 1

The third array element is : 5 8 9 8 5 

Add two array

C Program to Add two array : -

Program : -

 

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

void main()
 { 
    int a[5],b[5],c[5],i,j;
    clrscr();
    puts("Enter the first array element :");
    for(i=0;i<5;i++)
    {
        scanf("%d",&a[i]);
    }

    puts("Enter the second array element :");
    for(i=0;i<5;i++)
    {
        scanf("%d",&b[i]);
    }

    puts("The third array element is :");
    for(i=0;i<5;i++)
    {
        c[i]=a[i]+b[i];
        printf("%d  ",c[i]);
    }
    getch();
 }
 

Output : -

Enter the firat array element : 1 2 3 4 5

Enter the second array element : 5 4 3 2 1

The third array element is : 6 6 6 6 6 

Display fibonacci series

C Program to Display Fibonacci Series : -


Program : -



#include<stdio.h>
#include<conio.h>
int main()
{
  int count, n, t1=0, t2=1, display=0;
  printf("Enter number of terms: ");
  scanf("%d",&n);
  printf("Fibonacci Series: %d %d", t1, t2); /* Displaying first two terms */
  count=2;    /* count=2 because first two terms are already displayed. */
  while (count<n)  
  {
      display=t1+t2;
      t1=t2;
      t2=display;
      ++count;
      printf(" %d",display);
  }
  getch();
}


Output : -

Enter number of terms: 10
Fibonacci Series: 0 1 1 2 3 5 8 13 21 34

C program to Generate Multiplication Table

Program : -

#include<stdio.h>
#include<conio.h>
void main()
{
    int n, i;
    printf("Enter an integer to find multiplication table: ");
    scanf("%d",&n);
    for(i=1;i<=10;++i)
    {
        printf("%d * %d = %d\n", n, i, n*i);
    }
    getch();
}



Output : -

Enter an integer to find multiplication table: 9 9 * 1 = 9 9 * 2 = 18 9 * 3 = 27 9 * 4 = 36 9 * 5 = 45 9 * 6 = 54 9 * 7 = 63 9 * 8 = 72 9 * 9 = 81 9 * 10 = 90





C Program to Find Factorial of a Number

Program : -


#include<stdio.h>
#include<conio.h>
int main()
{
    int n, count;
    unsigned long long int factorial=1;         
    printf("Enter an integer: ");
    scanf("%d",&n);
    if ( n< 0)
        printf("Error!!! Factorial of negative number doesn't exist.");
    else
    {
       for(count=1;count<=n;++count)    /* for loop terminates if count>n */
       {
          factorial*=count;              /* factorial=factorial*count */
       }
    printf("Factorial = %lu",factorial);
    }
    getch();
}




Output 1 : -

Enter an integer: -5
Error!!! Factorial of negative number doesn't exist.

Output 2 : -

Enter an integer: 10
Factorial = 3628800



C Program to Find the Largest Number Among Three Numbers

Program : -


#include<stdio.h>
#include<conio.h>
void main()
{
      float a, b, c;
      printf("Enter three numbers: ");
      scanf("%f %f %f", &a, &b, &c);
      if (a>=b)
      {
          if(a>=c)
            printf("Largest number = %.2f",a);
          else
            printf("Largest number = %.2f",c);
      }
      else
      {
          if(b>=c)
            printf("Largest number = %.2f",b);
          else
            printf("Largest number = %.2f",c);
      }
      getch();
}



Output : -


Enter three numbers: 12.2 13.452 10.193 Largest number = 13.45




C Program to Check Whether a Number is Even or Odd

Program : -

#include<stdio.h>
#include<conio.h>
void main()
{
      int num;
      printf("Enter an integer you want to check: ");
      scanf("%d",&num);
      if((num%2)==0)                                     /* Checking whether remainder is 0 or not. */
           printf("%d is even.",num);
      else
           printf("%d is odd.",num);
      getch();
}



Output 1 : -

Enter an integer you want to check: 25
25 is odd.


Output 2 : -

Enter an integer you want to check: 12
12 is even.


C Program to Check Whether a Character is an Alphabet or not


Program : -

#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(); }

Output 1 : -

Enter a character: * * is not an alphabet

Output 2 : -

Enter a character: K K is an alphabet











Click Here To See All C Program

Write a program to find ASCII value of any character

Program : -


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

void main()
{
        char c;
        printf("Enter a character :");
        scanf("%c",&c);
        printf("ASCII value of  %c is %d",c,c);
        getch();
}



Output : -

Enter a character :G
ASCII value of G is 71

write a program to insert an element of array

Program : -

#include <stdio.h> 
#include<conio.h> 
void main()
{
   int array[100], position, c, n, value;
 
   printf("Enter number of elements in array\n");
   scanf("%d", &n);
 
   printf("Enter %d elements\n", n);
 
   for (c = 0; c < n; c++
      scanf("%d", &array[c]);
 
   printf("Enter the location where you wish to insert an element\n");
   scanf("%d", &position);
 
   printf("Enter the value to insert\n");
   scanf("%d", &value);
 
   for (c = n - 1; c >= position - 1; c--)
      array[c+1] = array[c];
 
   array[position-1] = value;
 
   printf("Resultant array is\n");
 
   for (c = 0; c <= n; c++)
      printf("%d\n", array[c]);
 
   getch();
}
 
 
 
 
 
Output : - 

Enter number of elements in array
5
Enter 5 element
1
2
3
4
6
Enter the location where you wish to insert an element
5
Enter the value to insert
5
Resultant array is
1
2
3
4
5

Write a program to make a array of 10 number

Program : -


#include<stdio.h>
#include<conio.h>
void main()
{
         int a[10],i=0;
       
        printf("Enter your 10 array element :");
        for(i=0;i<10;i++)
       {
            saanf("%d",&a[i]);
       }

        printf("Your array element is :");

        for(i=0;i<10;i++)
       {
            printf("%d ",a[i]);
       }

       getch();
}



Output :-



Enter your array element :  8 9 7 6 5 9 4 2 3 1

Your array element is : 8 9 7 6 5 9 4 2 3 1


Write a program to make calculator using switch case

Program :- 


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

void mian()
{
     clrscr();
     float a,b,d;
     char c;
     printf("Enter your expression :");
     scanf("%f %c %d",&a,&c,&b);
     switch(c)
     {
      case '+' : d=a+b;
                   printf("Sum = %f",d); 
                   break;
       case '-' : d=a-b;
                   printf("Sub = %f",d); 
                   break;
      case '*' : d=a*b;
                   printf("Mul = %f",d); 
                   break;
       case '/' : d=a/b;
                   printf("Div = %f",d); 
                   break;

     }
     getch();
}



Output :-


Enter your expression :2+3
Sum = 5
------------------------------------

Enter your expression :3-2
Sub = 1
------------------------------------

Enter your expression :2*3
Mul = 6
------------------------------------

Enter your expression :6/2
Div = 3

C program to perform addition

Program :-

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;                                //create a,b&c variable of int data type
printf("Enter value of A :");
scanf("%d",&a);                  // Read value of a from user
printf("Enter value of B;");
scanf("%d",&b);                  // Read value of b from user
c=a+b;                                 // Store the value of a+b in c
printf("Sum = %d",c);        // Print sum
getch();
}
Output :-
Enter the value of A :20
Enter the value of B :30
Sum = 50