Wednesday, March 27, 2019

Print Inverted half pyramid or Triangle using numbers in C Programming or C Language



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

Source Code:
#include <stdio.h>
int main()
{
    int i, j, rows;

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

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

    return 0;
}

Tuesday, March 26, 2019

Print Pattern inverted half pyramid or inverted Triangle using * in C Programming or C Language


Output: 

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

Source Code:
#include <stdio.h>
int main()
{
    int i, j, rows;

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

    for(i=rows; i>=1; --i)
    {
        for(j=1; j<=i; ++j)
        {
            printf("* ");
        }
        printf("\n");
    }
   
    return 0;
}

Monday, March 25, 2019

Print a pattern of half pyramid or Triangle using alphabets in C Programming or C Language



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

Source Code
#include <stdio.h>
int main()
{
    int i, j;
    char input, alphabet = 'A';

    printf("Enter the uppercase character you want to print in last row: ");
    scanf("%c",&input);

    for(i=1; i <= (input-'A'+1); ++i)
    {
        for(j=1;j<=i;++j)
        {
            printf("%c", alphabet);
        }
        ++alphabet;

        printf("\n");
    }
    return 0;
}

Saturday, March 23, 2019

Print Pattern half pyramid or Triangle using numbers in C Program or C Language

Output:

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

Source Code:

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

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

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

Print Pattern half pyramid or Triangle using * in C Program or C Language

Source Code
#include <stdio.h>
int main()
{
    int i, j, rows;

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

    for(i=1; i<=rows; ++i)
    {
        for(j=1; j<=i; ++j)
        {
            printf("* ");
        }
        printf("\n");
    }
    return 0;
}

Output
*
* *
* * *
* * * *
* * * * *

Friday, March 15, 2019

Display Swapping using Pointer and UDF (User Define Function) Call by Address in C Program



#include<stdio.h>
// function prototype, also called function declaration
void swap(int *a, int *b);

int main()
{
    int m = 22, n = 44;
    //  calling swap function by address
    printf("values before swapping \n m = %d \n and n = %d",m,n);
    swap(&m, &n);        
}

void swap(int *a, int *b)
{
    int tmp;
    tmp = *a;
    *a = *b;
    *b = tmp;
    printf("\n values after swapping \n a = %d \nand b = %d", *a, *b);
}


OUTPUT:

values before swapping 
m = 22
and n = 44
values after swapping 
a = 44
and b = 22

Wednesday, March 13, 2019

Display 3 to 9 using while loop in C programming


Display 3 to 9 using while loop in C programming



#include <stdio.h>

int main()
{
  int i=3;

  while(i<10)
  {
     printf("%d\n",i);
     i++;
  }   

}


OUTPUT:
3 4 5 6 7 8 9

Monday, March 11, 2019

Display 1 to 10 Integer or Real Number using for Loop in C programming


Display 1 to 10 Integer or Real Number using FOR Loop in C programming




#include <stdio.h>

int main()
{
  int i;

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

}

OUTPUT:

0 1 2 3 4 5 6 7 8 9