C Language

#include<stdio.h>
/*
Program to print Hello World
*/
int main()
{
     printf("Hello World");
     return 0;
}

A C program basically consist of following parts::

  • Pre-processor Commands
  • Comment
  • Functions
  • variables
  • Statements and expressions

Pre-processor Commands : First line of the program #include is a pre-processor commands.  Preprocessor directives are lines included in the code of programs preceded by a hash sign (#). Before compiling source code in a compiler,  the preprocessor examines the code before. No Semocolon(;) is expected

Comments : Single Line Comment (//) or Multi – Line Comment (/*  —   */). Comments are not mandatory for any C Program. These lines will be ignored by the compiler. Its a good practice to include comments in your programs as it improves readability also easy to understand complex or large programs.

Functions :  main function(int main() ), is a function where program execution startand ends. Every program should have main function.

Variables : Used to store temporary values.

Statements and Expression

 

 

 

 

Pyramid and Pattern in C Language

Pyramid and Pattern
1) 
*
**
***
****
*****

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

    printf("Enter number of rows: ");
    scanf("%d",&rows);
    for(i=1;i<=4;i++)
    {
        for(j=1;j<=i;j++)
        {
            printf("*");
        }
        printf("\n");
    }

    return 0;
}
2)
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

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

3)
A
B B
C C C
D D D D
E E E E E

#include<stdio.h>
int main(){

    int i, j,rows;

    printf("Enter number of rows: ");
    scanf("%d",&rows);
    for(i=0;i<rows;i++)
    {
        for(j=0;j<=i;j++)
        {
            printf("%c",('A'+j));
        }
        printf("\n");
    }
    return 0;
}
4)
* * * * *
* * * *
* * * 
* *
*

#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=i;j<=rows;j++)
        {
            printf("*");
        }
        printf("\n");
    }


    return 0;
}

5)

1 2 3 4 5
1 2 3 4 
1 2 3
1 2
1
/*
Pyramid 1
Key Computer Education
Koding Keys - Blog
1 2 3 4 5
1 2 3 4
1 2 3
1 2
1
*/
#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<=rows-i+1;j++)
        {
            printf("%d",j);
        }
        printf("\n");
    }


    return 0;
}


6.
1
01
010
1010
10101
#include<stdio.h>
int main()
{
int n, c, k, num = 1;
printf("Enter number of rows: ");
scanf("%d", &n);

for ( c = 1 ; c <= n ; c++ )
{
  for ( k = 1 ; k <<= c ; k++ )
  {
      printf("%d", num);

      if ( num == 0 )
         num = 1;
      else
         num = 0;
  }
  printf("\n");
}

return 0;
}

7. Floyds Triangle – https://kodingkeys.wordpress.com/2017/05/11/7-floyds-triangle-c-language/

Library Functions

isalnum Check if character is alphanumeric
isalpha Check for Alphabetic
iscntrl Test for Control Character
isdigit Test for Digit
isgraph Test for Graphical Character (does not include a space)
islower Test for Lowercase Letter
isprint Test for Printing Character (does include a space)
ispunct Test for Punctuation Character
isspace Test for White-Space Character
isupper Test for Uppercase Letter
isxdigit Test for Hexadecimal Digit
tolower Convert to Lowercase
toupper Convert to Uppercase