FOC
Computer
Fundamentals &
Programming
Lab 7
Presented By
Mohammad Anwar Hossain
Lecturer
Department of CSE
World University of Bangladesh
C Program to Swap two Numbers
// C program to swap two variables
#include <stdio.h>
// Driver code
int main()
{
int x, y;
printf("Enter Value of x ");
scanf("%d", &x);
printf("\nEnter Value of y ");
scanf("%d", &y);
// Using a temporary variable to swap the values
// Store the value of x in a temporary variable
int temp = x;
// Assign the value of y to x
x = y;
// Assign the value stored in the temporary variable to
// y
y = temp;
printf("\nAfter Swapping: x = %d, y = %d", x, y);
return 0;
}
C Program to Swap two Numbers
ASCII Value of a Character in C
• American Standard Code for Information Interchange
(ASCII) is a character encoding standard that assigns a
unique numerical value to all characters including
special symbols. In C programming, the ASCII value of
the character is stored instead of the character itself. For
example, the ASCII value of ‘A’ is 65.
• Each character or special character is represented by
some ASCII code.
• Each ASCII code occupies 7 bits in memory.
• Each character variable is assigned an ASCII value
ranging from 0 to 127.
C Program To Print ASCII Value of a
Character
/ C program to print
// ASCII Value of Character
#include <stdio.h>
// Driver code
int main()
{
char c = 'k';
// %d displays the integer value of
// a character
// %c displays the actual character
printf("The ASCII value of %c is %d", c, c);
return 0;
}
C program to Check Whether a Number is
Positive or Negative or Zero
#include <stdio.h>
int main()
{
int A;
printf("Enter the number A: ");
scanf("%d", &A);
if (A > 0)
printf("%d is positive.", A);
else if (A < 0)
printf("%d is negative.", A);
else if (A == 0)
printf("%d is zero.", A);
return 0;
}
C program to Check Whether a Number is
Positive or Negative or Zero
Thank You