1.Write a C program print ASCII value of any character
#include <stdio.h>
#include <conio.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;
}
output:
1.Write a C program print ASCII value of any character2.Write a C program using enum keyword. 3.Write a C program for typecasting the value from integer to float4.Write a C program to take character from user using getchar() function and print that character using putchar() function. 5.Write a program to perform arithmetic operations on two numbers. 6.Write a program to find maximum number from two numbers using conditional operator(Ternary operator). 7.Write a program to perform Postfix increment and Postfix Decrement using Increment/Decrement Operators.
Enter a character: G
ASCII value of G = 71
2.Write a C program using enum keyword.
#include <stdio.h>
#include <conio.h>
enum week {Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday};
int main()
{
enum week today;
today = Tuesday;
printf("Day %d",today+1);
return 0;
}
output:
Day 3
3.Write a C program for typecasting the value from integer to float
#include <stdio.h>
#include <conio.h>
main() {
int a = 17, b = 5;
float ans;
ans = (float) (a + b);
printf("Value of Ans : %fn", ans );
}
output:
Value of Ans : 22.000000
4.Write a C program to take character from user using getchar() function and print that character using putchar() function.
#include <stdio.h>
#include <conio.h>
int main()
{
char c;
printf("Enter some character....n");
c = getchar();
printf("n Entered character is: ");
putchar(c);
printf("n");
return 0;
}
output:
Enter some character....
A
Entered character is: A
5.Write a program to perform arithmetic operations on two numbers.
#include <stdio.h>
#include <conio.h>
int main()
{
int num1, num2;
int sum, sub, mult, mod;
float div;
printf("Enter any two numbers: ");
scanf("%d%d", &num1, &num2);
sum = num1 + num2;
sub = num1 - num2;
mult = num1 * num2;
div = (float)num1 / num2;
mod = num1 % num2;
printf("Addition = %dn", sum);
printf("Substraction = %dn", sub);
printf("Multliplication = %dn", mult);
printf("Divisoin = %fn", div);
printf("Modulus = %d", mod);
return 0;
}
output:
Enter any two numbers: 5
10
Addition = 15
Substraction = -5
Multliplication = 50
Divisoin = 0.500000
Modulus = 5
6.Write a program to find maximum number from two numbers using conditional operator(Ternary operator).
#include <stdio.h>
#include <conio.h>
int main()
{
int num1, num2, max;
printf("Enter two numbers: ");
scanf("%d%d", &num1, &num2);
max = (num1 > num2) ? num1 : num2;
printf("Maximum between %d and %d is %d", num1, num2, max);
return 0;
}
output:
Enter two numbers: 10 15
Maximum between 10 and 15 is 15
7.Write a program to perform Postfix increment and Postfix Decrement using Increment/Decrement Operators.
#include <stdio.h>
#include <conio.h>
int main()
{
int x = 12, y = 1;
printf("Initial value of x = %dn", x);
printf("Initial value of y = %dnn", y);
y = x++;
printf("After incrementing by 1: x = %dn", x);
printf("y = %dnn", y);
y = x--;
printf("After decrementing by 1: x = %dn", x);
printf("y = %dnn", y);
return 0;
}
output:
Initial value of x = 12
Initial value of y = 1
After incrementing by 1: x = 13
y = 12
After decrementing by 1: x = 12
y = 13
Hello there, just became alert to your blog through
Google, and found that it is truly informative. I am going to
watch out for brussels. I’ll be grateful if you continue
this in future. Numerous people will be benefited from your writing.
Cheers!
I have read so many posts concerning the blogger lovers except this article is actually a fastidious article, keep it up.
Hello there, I discovered your site by means of Google even as looking for
a related subject, your site came up, it appears to be like
good. I’ve bookmarked it in my google bookmarks.
Hello there, just turned into aware of your blog through Google, and located that it’s
really informative. I’m gonna watch out for brussels. I will be grateful in the
event you continue this in future. A lot of folks will likely be benefited
out of your writing. Cheers!