Posts

Showing posts from April, 2023

Control Statement

Image
 Control statements in C Control statements are executed sequentially in the order in which they appear in the program. But sometimes we may want to use a condition for executing only a part of program. Also many Situation arise where we may want to execute some statements several times. In other word , the control instruction determine the ' flow of control ' in  a program. There are different types of Control statement in C Language : Sequence Control statement  The Sequence Control statement ensures that the instructions are executed in the same order in which they appear in the program.  A group of statements enclosed within a pair of curly braces {}. The statements inside a block are executed Sequentially.  The general form is : statement1 statement2 ................. ................. For example : l = 4 ;  b = 2; area = l*b; printf("Area=%d", area); In the above example first declare the value of l and b after that find area = l*b then print. ...

Practice program of using an Operators.

Image
 Practice program 1. Write a  program that enters temperature in Celsius and converts that into Fahrenheit. solution : first you can write program in your IDE create a logic how to solve the problem  ※  convert temperature  Celsius  to Fahrenheit use  😊 Formula : ℉=( ℃ × 1.8) + 32 OR ℉=( ℃ × 9/5) +32 #include <stdio.h> int main() {     /*program to convert temperature Celsius to Fahrenheit*/     float C, F;     printf( "Input the Temperature in degree Celsius:" );     scanf( "%f" , &C);     F = (C * 9 / 5 ) + 32 ;     printf( "%.2f degree Celsius = %.2f degree Fahrenheit" , C, F);     return 0 ; } Output: Input the Temperature in degree Celsius:31.5 31.50 degree Celsius = 88.70 degree Fahrenheit 2. Write a program to accepts the radius of a circle and calculates the area and perimeter of that circle. solution : logic of that program : ※ accept the value of ra...

Type conversion and Type Casting

Image
 Type conversion Type conversion  in C is the process of converting one data type to another.  The type Conversion is only performed to those data types where conversion is possible. Type conversion is performed by a compiler. In type Conversion data type can be convert lower rank into higher rank. Implicit Type Conversion These conversion are done by the compiler according to some predefine rules of C language. The two types of implicit conversions are automatic type conversion and type conversion in assignment. Generally take place when in an expression more than one data type is present. In such condition type conversion(type promotion) takes place to avoid loss of data. All the data types of the variable are promoted to the data type of the variable with the largest data type. char-> short int-> int-> long int-> float-> double-> long->double Implicit type conversion is also called automatic type conversion. some of its few occurrences are mention ...

Precedence and Associativity of operator in C

/*Precedence and Associativity of operators in C */ operator precedence determines which operation is performed first in an expression with more than one operators with different precedence. for example : 2+5*3 in  the above example multiplication operator have high precedence as compare to addition operator so,  multiply will happening first as higher precedence than after addition will happening lower precedence. 2+5*3 2+15 17 /*program to demonstrate precedence of an operator*/ #include <stdio.h> int main() {     int a = 2 , b = 5 , c = 3 , d;     d = a + b * c; / / multiplication have higher precedence as compare to addition operator have lower precedence     printf( "d=%d" , d);     return 0 ; } Output: d=17 Operators Associativity is used when two operator have same precedence appear in an expression. Associativity can either left to right or right to left. for example: '*' and '/' have same precedence and t...