Posts

Differences between Structure and Union in C | C programming

STRUCTURE IN C A structure is a user-defined data type available in C that allows to combining data items of different kinds. Structures are used to represent a record. Defining a structure:  To define a structure, you must use the  struct  statement. The struct statement defines a new data type, with more than one member. The format of the struct statement is as follows:    struct [structure name]    {        member definition;        member definition;        ...        member definition;    }; UNION IN C A union is a special data type available in C that allows storing different data types in the same memory location. You can define a union with many members, but only one member can contain a value at any given time. Unions provide an efficient way of using the same memory location for multiple purposes. Defining a Union:  To define a union, you must use the  union  statement in the same way as you did while defining a structure. The union stateme

C Program to Store Information in Structure and Display it | C Programming

Structure    Arrays are used to store large set of data and manipulate them, but the disadvantage is that all the elements stored in an array are to be of the same data type. If we need to use a collection of different data type items, it is not possible using an array. When we require using a collection of different data items of different data types, we can use a structure.  Structure is a method of grouping data of different types.  A structure is a convenient method of handling a group of related data items of different data types.  

C Program for Fibonacci Series | C Programming

C Programming | Fibonacci Series The phrase, “ the  Fibonacci sequence” usually refers to a set of numbers that starts as {0, 1, 1, 2, 3, 5, 8, 13, 21…}. At least, “The Life and Numbers of Fibonacci” starts with “zero and one”. Many others would skip the zero and simply start with “one and one”, but that does not matter.

C Program to change the address of entered number using pointer and function | C programming

Introduction To Pointer A Pointer in C language is a variable which holds the address of another variable of same data type. Pointers are used to access memory and manipulate the address. Pointers are one of the most distinct and exciting features of C language. It provides power and flexibility to the language. Although pointers may appear a little confusing and complicated in the beginning, but trust me, once you understand the concept, you will be able to do so much more with C language. C Program to change the address of entered number using pointer and function #include <stdio.h> #include <string.h> void exchange ( int * , int * ); int main () {     int num1 , num2 ;     printf ( "Enter the number to be exchanged \n " );     scanf ( " %d%d " , & num1 , & num2 );     printf ( "Before exchanging: \n num1= %d num2= %d \n " , num1 , num2 );     exchange (& num1 , & num2 ); } void exchange ( int * num1 , int * num2 )

C program to transpose the matrix

C program to transpose the matrix #include <stdio.h< int main () {     int a [ 10 ][ 10 ], i, j, row, col, trans [ 10 ][ 10 ];     printf ( "Enter no. of rows:" );     scanf ( " %d " , &row);     printf ( "Enter no. of columns:" );     scanf ( " %d " , &col);     printf ( "Enter elements of matrix:" );     for (i = 0 ; i < row; i++)     {         for (j = 0 ; j < col; j++)         {             scanf ( " %d " , & a [i][j]);         }     }     printf ( " \n The given matrix is : \n " );     for (i = 0 ; i < row; i++)     {         for (j = 0 ; j < col; j++)         {             printf ( " %d \t " , a [i][j]);         }         printf ( " \n " );     }     printf ( " \n The matrix after transpose is : \n " );     for (i = 0 ; i < row; i++)     {         for (j = 0 ; j < col; j++)         {             trans [i][j] = a [j][i];             pri

C program to reverse the given word using string

Image
#include<stdio.h> #include<string.h> int main()  {    char str[100], rev;    int i=0,c,j;    printf("Enter the string :\n");    gets(str);    j = strlen(str)-1;    while (i < j)    {   rev = str[i];       str[i] = str[j];       str[j] = rev;       i++;       j--;    }    printf("\nReverse string is\n%s",str);    return 0; } OUTPUT

C program to print pattern of Floyd's triangle

Image
A  for  loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times. Syntax The syntax of a for loop in C programming language is − for(init; condition; increment){  statement(s); } Here is the flow of control in a 'for' loop − The  init  step is executed first, and only once. This step allows you to declare and initialize any loop control variables. You are not required to put a statement here, as long as a semicolon appears. Next, the  condition  is evaluated. If it is true, the body of the loop is executed. If it is false, the body of the loop does not execute and the flow of control jumps to the next statement just after the 'for' loop. After the body of the 'for' loop executes, the flow of control jumps back up to the  increment  statement. This statement allows you to update any loop control variables. This statement can be left blank, as long as a semicolon appears after the co