Day 7 : Constant Variable and swapping in c language.

 

Assignment: 

1./* WAP to input Name of Employee, Basic Salary, and Compute the gross salary.

   The employee has allowances as follows,

   1. Dearness Allowance: 15%

   2. House Rent Allowance:20% */

base salary = 1,00,000;


15 perc =  100000*15/100



2./* Ass: WAP to input two numbers and perform swapping without using temporary 

   variable */


3./*How do you take integer input from the user in C?


4/*How do you display an integer variable in C?


5/* How do you take float input from the user in C?


Constant Variable and swapping in c language.


Const variable declaration in c language;


//1. In the C programming language, the const keyword is used to declare a constant variable.

//2. A constant is a value that cannot be modified once it has been assigned. Here's the syntax for declaring a const variable in C:


const data_type Variable_name = value;


ex: const long int firstlong = 100000;



Overall, constants in C help improve code quality, readability, and maintainability. They provide a way to express meaningful and unchangeable values, making your code easier to understand and less prone to errors.


Constant Variable and swapping in c language.



Swapping in c lang 

In C, "swap" refers to the process of exchanging the values of two variables. Swapping two variables means that their values are interchanged. Swapping is a common operation in programming and can be useful in various scenarios, such as sorting algorithms, data manipulation, and optimizing code.


There are multiple ways to implement swapping in C, but the most common approach involves using a temporary variable to hold one of the values temporarily while the exchange is performed.


Read More: Day 6: Operators and Arithmetic Calculation in c language.


ex:

//with temperay variable 

#include <stdio.h>


int main() {

    int a = 5;

    int b = 10;

    int temp;


    printf("Before swapping: a = %d, b = %d\n", a, b); //These are values befor swapping 


    temp = a;

    a = b;

    b = temp;


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


    return 0;

}


Read More: Day 5: Assignment for All // Write a program for the below questions.


//** ASCII (American Standard Code for Information Interchange)


  • ASCII is a character encoding standard used in computers and communication systems to represent text characters.
  •  It assigns a unique numeric code to each character, including uppercase and lowercase letters, digits, punctuation marks, control characters, and special symbols.
  • The ASCII standard uses 7 bits (128 unique codes) to represent characters, which allows for a total of 128 different characters.
  •  The most common ASCII encoding uses 8 bits (1 byte), with the additional bit typically used for parity or extended ASCII characters.


For example, some ASCII codes include:


  • - The letter 'A' is represented by the code 65 (or 0x41 in hexadecimal).
  • - The digit '0' is represented by the code 48 (or 0x30 in hexadecimal).
  • - The symbol '$' is represented by the code 36 (or 0x24 in hexadecimal).
  • - The control character for line feed (LF) is represented by code 10 (or 0x0A in hexadecimal).


ASCII codes have widespread usage in computer systems, programming languages, communication protocols, and various applications that involve working with text. However, it's worth noting that the ASCII standard only covers a limited set of characters and is primarily designed for the English language. Other character encoding schemes, such as Unicode, have been developed to support a broader range of characters and languages.


Read More: Day 3: Variable and Data Types in the C language.














Post a Comment

Previous Post Next Post