0% found this document useful (0 votes)
2 views4 pages

Introduction Examples

The document contains multiple C programs demonstrating basic programming concepts such as printing output, user input, arithmetic operations, and data type sizes. Each program is structured with standard input/output functions and showcases different functionalities like addition, multiplication, and swapping of numbers. It serves as a practical guide for beginners to understand and implement fundamental C programming tasks.

Uploaded by

Nirmal M
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Introduction Examples

The document contains multiple C programs demonstrating basic programming concepts such as printing output, user input, arithmetic operations, and data type sizes. Each program is structured with standard input/output functions and showcases different functionalities like addition, multiplication, and swapping of numbers. It serves as a practical guide for beginners to understand and implement fundamental C programming tasks.

Uploaded by

Nirmal M
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

1 C program to print a sentence

#include <stdio.h>
void main()
{
printf("Hello, World!");
}

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 C program to add two integers entered by the User

#include <stdio.h>
void main()
{
int number1, number2, sum;

printf("Enter two integers: ");


scanf("%d %d", &number1, &number2);

// calculate the sum


sum = number1 + number2;

printf("%d + %d = %d", number1, number2, sum);


}
4 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);
}

5 C program to find ASCII value of a character entered by the user

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

6 C program to find quotient and remainder of Two Integers

#include <stdio.h>
void main()
{
int dividend, divisor, quotient, remainder;
printf("Enter dividend: ");
scanf("%d", &dividend);
printf("Enter divisor: ");
scanf("%d", &divisor);

// Computes quotient
quotient = dividend / divisor;

// Computes remainder
remainder = dividend % divisor;

printf("Quotient = %d\n", quotient);


printf("Remainder = %d", remainder);
}
7 C program to find the size of int, float, double and char

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

8 C program to demonstrate the working of keyword long

#include <stdio.h>
void main()
{
int a;
long b; // equivalent to long int b;
long long c; // equivalent to long long int c;
double e;
long double f;

printf("Size of int = %zu bytes \n", sizeof(a));


printf("Size of long int = %zu bytes\n", sizeof(b));
printf("Size of long long int = %zu bytes\n", sizeof(c));
printf("Size of double = %zu bytes\n", sizeof(e));
printf("Size of long double = %zu bytes\n", sizeof(f));
}
9 C program to swap two numbers

#include<stdio.h>
void main()
{
double first, second, temp;
printf("Enter first number: ");
scanf("%lf", &first);
printf("Enter second number: ");
scanf("%lf", &second);

// value of first is assigned to temp


temp = first;

// value of second is assigned to first


first = second;

// value of temp (initial value of first) is assigned to second


second = temp;

// %.2lf displays number up to 2 decimal points


printf("\nAfter swapping, first number = %.2lf\n", first);
printf("After swapping, second number = %.2lf", second);
}

You might also like