Posts

Showing posts from November, 2020

Program to decide whether a given number is positive, negative or zero number.

Image
Here, user will input a number and program will assign it in variable 'a' using scanf. After that, the value inside variable is checked, whether it is greater than 0 or not and if it is greater than 0 then inputted number is positive and if it is less than 0, the inputted number is negative. But if these two condition is not satisfied then the inputted number must be equal to 0.  Output  

When you use structure and union in C ?

Structure is a user defined data type which hold or store homogeneous data item or element in a single variable. It is a Combination of primitive and derived data type. In C language , array is also a user defined data type but array hold or store only similar type of data, If we want to store different type of data, then we need to define separate variable for each type of data. For this problem, Structure is best suit.   A union is quite similar to the structures in C. It also stores different data types in the same memory location. It is also a user defined data type same like structure. It is more near to structure. Union can be defined in same manner as structures, for defining union, use union keyword where as for defining structure, use struct keyword.  When you need to manipulate the data for all member variables then use structure. When need to manipulate only on member then use union. All the properties of the structure are same for union, except initialization proce...