0% found this document useful (0 votes)
17 views5 pages

Data Types - Operartors An Mam

The document provides various C programming examples demonstrating basic operations such as adding two numbers, swapping values without a temporary variable, and using different data types like integers, characters, floats, and doubles. It also covers arithmetic, relational, logical, increment/decrement, and bitwise operators. Each section includes code snippets illustrating the concepts discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views5 pages

Data Types - Operartors An Mam

The document provides various C programming examples demonstrating basic operations such as adding two numbers, swapping values without a temporary variable, and using different data types like integers, characters, floats, and doubles. It also covers arithmetic, relational, logical, increment/decrement, and bitwise operators. Each section includes code snippets illustrating the concepts discussed.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

Addition of Two Numbers: This program adds two numbers entered by

the user and displays the result.

#include <stdio.h>

int main() {
int num1, num2, sum;

printf("Enter first number: ");


scanf("%d", &num1);

printf("Enter second number: ");


scanf("%d", &num2);

sum = num1 + num2;


printf("Sum: %d\n", sum);

return 0;
}

1. Integer (int): Refers to positive and negative whole numbers (without


decimal), such as 10, 12, 65, 3400
#include <stdio.h>
void main()
{
int i = 5;
printf("The integer value is: %d \n", i);
}

2. Character (char): Refers to all the ASCII character sets within single
quotes such as ‘a’, ‘A’, etc.

#include <stdio.h>
void main()
{
char c = 'b';
printf("The character value is: %c \n", c);
}

3. Floating-point (float): Refers to all the real number values or decimal


points, such as 3.14, 10.09, 5.34, etc.
#include <stdio.h>
void main()
{
float f = 7.2357;
printf("The float value is: %f \n", f);
}

4. Double (double): Used when the range exceeds the numeric values that
do not come under either floating-point or integer data type.

#include <stdio.h>
void main()
{
double d = 71.2357455;
printf("The double value is: %lf \n", d);
}

Swap Two Numbers without a Temporary Variable:


#include <stdio.h>

int main() {
int a, b;

printf("Enter the value of a: ");


scanf("%d", &a);

printf("Enter the value of b: ");


scanf("%d", &b);

a = a + b;
b = a - b;
a = a - b;

printf("After swapping: a = %d, b = %d\n", a, b);

return 0;
}

Arithmetic Operators:

#include <stdio.h>

int main() {
int num1 = 10, num2 = 5;

int addition = num1 + num2;


int subtraction = num1 - num2;
int multiplication = num1 * num2;
int division = num1 / num2;

printf("Addition: %d\n", addition);


printf("Subtraction: %d\n", subtraction);
printf("Multiplication: %d\n", multiplication);
printf("Division: %d\n", division);

return 0;
}

Relational Operators:
#include <stdio.h>

int main() {
int num1 = 10, num2 = 5;

printf("%d > %d : %d\n", num1, num2, num1 > num2);


printf("%d < %d : %d\n", num1, num2, num1 < num2);
printf("%d >= %d : %d\n", num1, num2, num1 >= num2);
printf("%d <= %d : %d\n", num1, num2, num1 <= num2);
printf("%d == %d : %d\n", num1, num2, num1 == num2);
printf("%d != %d : %d\n", num1, num2, num1 != num2);

return 0;
}

Logical Operators:

#include <stdio.h>

int main() {
int num = 25;

if (num > 0 && num < 50)


printf("%d is in the range of 1 to 49.\n", num);
else
printf("%d is not in the range of 1 to 49.\n", num);

return 0;
}

Increment and Decrement Operators:

#include <stdio.h>

int main() {
int num = 10;

printf("Original number: %d\n", num);


printf("After post-increment: %d\n", num++);
printf("After pre-increment: %d\n", ++num);
printf("After post-decrement: %d\n", num--);
printf("After pre-decrement: %d\n", --num);
return 0;
}

Bitwise Operators:

#include <stdio.h>

int main() {
int num1 = 5, num2 = 3;

printf("Bitwise AND: %d\n", num1 & num2);


printf("Bitwise OR: %d\n", num1 | num2);
printf("Bitwise XOR: %d\n", num1 ^ num2);

return 0;
}

You might also like