By using this site, you agree to the Privacy Policy and Terms of Use.
Accept
rocoderesrocoderes
Notification Show More
Latest News
Passing a JavaScript Value Between HTML Pages
Passing a JavaScript Value Between HTML Pages
JavaScript
Compare Objects in an Array
JavaScript Problem: Compare Objects in an Array
JavaScript
Switching Name Order Using Capturing Groups in Regular Expressions
Switching Name Order Using Capturing Groups in Regular Expressions
JavaScript
Shuffling an Array
JavaScript Problem: How to Perform Shuffling an Array
JavaScript
Create a Non-duplicated Collection
JavaScript Problem: Using Set to Create a Non-duplicated Collection
JavaScript
Aa
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Aa
rocoderesrocoderes
Search
  • Home
  • HTML & CSS
    • Login and Registration Form
    • Card Design
    • Loader
  • JavaScript
  • Python
  • Internet
  • Landing Pages
  • Tools
    • Google Drive Direct Download Link Generator
    • Word Count
  • Games
    • House Painter
Follow US
High Quality Design Resources for Free.
rocoderes > c > C Programs Practicals
c

C Programs Practicals

Rohan750
Last updated: 2021/05/14 at 7:13 AM
Rohan750
Share
3 Min Read

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:

Contents
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

Related

Subscribe to Our Newsletter

Subscribe to our newsletter to get our newest articles instantly!

Share this Article
Facebook Twitter Email Print
What do you think?
Love0
Sad0
Happy0
Sleepy0
Angry0
Dead0
Wink0
Previous Article Convert Images Into Pencil Sketch Using Python
Next Article Expressions and operators
3 Comments 3 Comments
  • Kent says:
    November 16, 2021 at 11:49 pm

    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!

    Reply
  • May says:
    November 19, 2021 at 12:19 am

    I have read so many posts concerning the blogger lovers except this article is actually a fastidious article, keep it up.

    Reply
  • Aida says:
    November 21, 2021 at 3:10 pm

    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!

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

- Advertisement -
rocoderesrocoderes
Follow US

Copyright © 2022 All Right Reserved By Rocoderes

  • Home
  • About us
  • Contact us
  • Disclaimer
Join Us!

Subscribe to our newsletter and never miss our latest news, podcasts etc.

Zero spam, Unsubscribe at any time.
Welcome Back!

Sign in to your account

Lost your password?