C Programming Examples

basics of the C programming language,

0 188

1.Program to Display “Hello, World!”

 

#include <stdio.h>
void main()
 {
   // printf() displays the string inside quotation
   printf("Hello, World!");
   return 0;
}

 

2. C Program to Print an Integer (Entered by the User)

#include <stdio.h>
void main() 
{   
    int number;
   
    printf("Enter an integer: ");  
    
    // reads and stores input
    scanf("%d", &number);

    // displays output
    printf("You entered: %d", number);
    
 }

3.Program to Print ASCII Value

#include <stdio.h>
void  main()
 {  
    char c;
    printf("Enter a character: ");
    scanf("%c", &c);  
    
    // %d displays the integer value of a character
    // %c displays the actual character
    printf("ASCII value of %c = %d", c, c);         
 }

 

4. Program to Find the Size of Variables

#include<stdio.h>
void main() {
    int intType;
    float floatType;
    double doubleType;
    char charType;

    // sizeof evaluates the size of a variable
    printf("Size of int: %zu bytes\n", sizeof(intType));
    printf("Size of float: %zu bytes\n", sizeof(floatType));
    printf("Size of double: %zu bytes\n", sizeof(doubleType));
    printf("Size of char: %zu byte\n", sizeof(charType));
    
  }

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

#include <stdio.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);

    }

6. C Program to Multiply Two Floating-Point Numbers

#include <stdio.h>
void main() {
    double a, b, product;
    printf("Enter two numbers: ");
    scanf("%lf %lf", &a, &b);  
 
    // Calculating product
    product = a * b;

    // %.2lf displays number up to 2 decimal point
    printf("Product = %.2lf", product);
    
    }
Leave A Reply

Your email address will not be published.