pratik-a / C-Programs

Any Type of C Programs

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

C-Programs

Any Type of C Programs C Program to Find ASCII Value of a Character

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

return 0;

}

C Program to Multiply Two Floating-Point Numbers #include <stdio.h> int 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);

return 0;

}

C Program to Swap Two Numbers #include<stdio.h> int 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); return 0; }

C Program to Check Whether a Number is Even or Odd #include <stdio.h> int main() { int num; printf("Enter an integer: "); scanf("%d", &num);

// true if num is perfectly divisible by 2
if(num % 2 == 0)
    printf("%d is even.", num);
else
    printf("%d is odd.", num);

return 0;

}

About

Any Type of C Programs