-->

Program to understand concept of nested structure of struct.

using codeblock
--------------------------------------------------------------------------------------
//understanding nested struct concept         //comment abt. program
#include <stdio.h>                            //header file to handle input and output
struct college                                //struct tag
{
    char name[50];                            //first member named name
    char address[50];                         //second member named address
};
struct student                               //second struct tag
{
char name[50];                              // member1
char stream[40];                            //member 2
struct college first;                       //acts as a member. It is a variable of first tag college
};
struct student info;
int main()
{
    printf("enter college name\n");
    gets(info.first.name);                 //accessing member of first tag for input
    printf("enter college address\n");
    gets(info.first.address);             //accessing member of first tag for input
    printf("enter student name\n");
    gets(info.name);                        //accessing member of second tag for input
    printf("enter student's stream\n");
    gets(info.stream);                      //accessing member of second tag for input
    printf("------------------------\n");
    printf(" college name is\n");
    puts(info.first.name);                   //display of data
    printf("college address is\n");
    puts(info.first.address);                 //display of data
    printf("student name is\n");
    puts(info.name);                           //display of data
    printf("student's stream is\n");
    puts(info.stream);                        //display of data
    return 0;
}
------------------------------------------------------------------------------------------------------------------

using turbo c++
---------------------------------------------------------------------------
//understanding nested struct concept         //comment abt. program
#include <stdio.h>                            //header file to handle input and output
#incluse<conio.h>
struct college                                //struct tag
{
    char name[50];                            //first member named name
    char address[50];                         //second member named address
};
struct student                               //second struct tag
{
char name[50];                              // member1
char stream[40];                            //member 2
struct college first;                       //acts as a member. It is a variable of first tag college
};
struct student info;
int main()
{
    printf("enter college name\n");
    gets(info.first.name);                 //accessing member of first tag for input
    printf("enter college address\n");
    gets(info.first.address);             //accessing member of first tag for input
    printf("enter student name\n");
    gets(info.name);                        //accessing member of second tag for input
    printf("enter student's stream\n");
    gets(info.stream);                      //accessing member of second tag for input
    printf("------------------------\n");
    printf(" college name is\n");
    puts(info.first.name);                   //display of data
    printf("college address is\n");
    puts(info.first.address);                 //display of data
    printf("student name is\n");
    puts(info.name);                           //display of data
    printf("student's stream is\n");
    puts(info.stream);                        //display of data
  getch();    
return 0;
}

Program read 10 students data (roll, name,class and marks in 5 subjects) and display that using struct with percentage.

using codeblocks
--------------------------------------------------------------------------------------------------------------------------------
//Program read 10 students data (roll, name,class and marks in 5 subjects) and display that using //struct with percentage.                      //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct
    int english,maths,physics,chemistry,nepali,total;   //marks member declaration
    float percentage;                       //member for total and percentage

}access[100];                 //'access' is a variable to access members. This can hold maximum 100 members.it is called array of struct.
int main()
{
   int n,i;                                         //variable declaration
   printf("enter total value of n\n");
   scanf("%d",&n);                                  //accepts total value
   for(i=0;i<n;i++)
   {                                                 //execution of loop with inputs
    puts("enter roll number \n");
   scanf("%d",&access[i].roll);                      //gets data in different member
   puts("enter name \n");
   scanf("%s",access[i].name);                       //gets name
   puts("enter address \n");
   scanf("%s",access[i].address);                    //gets address
   printf("enter english marks\n");
   scanf("%d",&access[i].english);                  //gets respective marks
   printf("enter maths marks\n");
   scanf("%d",&access[i].maths);
   printf("enter Physics marks\n");
   scanf("%d",&access[i].physics);
   printf("enter chemistry marks\n");
   scanf("%d",&access[i].chemistry);
   printf("enter nepali marks\n");
   scanf("%d",&access[i].nepali);
   access[i].total=access[i].english+access[i].maths+access[i].physics+access[i].chemistry+access[i].nepali;/finds total and stores
      access[i].percentage=(float)access[i].total/5;               //finds percentage and stores in respective member
   }
   printf("entered data are\n");                  //loop execution to display data
   for(i=0;i<n;i++)
   {
   printf("roll=%d,name=%s,address=%s, english=%d,maths=%d,physics=%d,chemistry=%d,nepali=%d\n",access[i].roll,access[i].name,access[i].address,access[i].english
          ,access[i].maths,access[i].physics,access[i].chemistry,access[i].nepali);
   }                                                //displays data

   printf(" data with total and percentage are\n");     // displays data with total and percentage
  for(i=0;i<n;i++)
   {
   printf("roll=%d,name=%s,address=%s, english=%d,maths=%d,physics=%d,chemistry=%d,nepali=%d, total=%d,percentage=%f\n",access[i].roll,access[i].name,access[i].address,access[i].english
          ,access[i].maths,access[i].physics,access[i].chemistry,access[i].nepali,access[i].total,access[i].percentage);
   }
    return 0;

}
-------------------------------------------------------------------------------------------------------------------------
using turbo c++
---------------------------------------------------------------------------------------
// program to enter detail of some  students       //comment abt. program
#include <stdio.h>                                 //header file
#include<conio.h>
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct
    int english,maths,physics,chemistry,nepali,total;   //marks member declaration
    float percentage;                       //member for total and percentage

}access[100];                 //'access' is a variable to access members. This can hold maximum 100 members.it is called array of struct.
int main()
{
   int n,i;                                         //variable declaration
   printf("enter total value of n\n");
   scanf("%d",&n);                                  //accepts total value
   for(i=0;i<n;i++)
   {                                                 //execution of loop with inputs
    puts("enter roll number \n");
   scanf("%d",&access[i].roll);                      //gets data in different member
   puts("enter name \n");
   scanf("%s",access[i].name);                       //gets name
   puts("enter address \n");
   scanf("%s",access[i].address);                    //gets address
   printf("enter english marks\n");
   scanf("%d",&access[i].english);                  //gets respective marks
   printf("enter maths marks\n");
   scanf("%d",&access[i].maths);
   printf("enter Physics marks\n");
   scanf("%d",&access[i].physics);
   printf("enter chemistry marks\n");
   scanf("%d",&access[i].chemistry);
   printf("enter nepali marks\n");
   scanf("%d",&access[i].nepali);
   access[i].total=access[i].english+access[i].maths+access[i].physics+access[i].chemistry+access[i].nepali;/finds total and stores
      access[i].percentage=(float)access[i].total/5;               //finds percentage and stores in respective member
   }
   printf("entered data are\n");                  //loop execution to display data
   for(i=0;i<n;i++)
   {
   printf("roll=%d,name=%s,address=%s, english=%d,maths=%d,physics=%d,chemistry=%d,nepali=%d\n",access[i].roll,access[i].name,access[i].address,access[i].english
          ,access[i].maths,access[i].physics,access[i].chemistry,access[i].nepali);
   }                                                //displays data

   printf(" data with total and percentage are\n");     // displays data with total and percentage
  for(i=0;i<n;i++)
   {
   printf("roll=%d,name=%s,address=%s, english=%d,maths=%d,physics=%d,chemistry=%d,nepali=%d, total=%d,percentage=%f\n",access[i].roll,access[i].name,access[i].address,access[i].english
          ,access[i].maths,access[i].physics,access[i].chemistry,access[i].nepali,access[i].total,access[i].percentage);
   }
   getch();                              //holds the output.
    return 0;
}

Program to input name,address and roll number of some students using struct/ array of struct.

using codeblocks
---------------------------------------------------------------------------------------
// program to enter detail of some  students       //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access[100]; //'access' is a variable to access members. This can hold maximum 100 members.it is called array of struct.
int main()
{
   int n,i;                                         //variable declaration
   printf("enter total value of n\n");
   scanf("%d",&n);                                  //accepts total value
   for(i=0;i<n;i++)
   {                                                 //execution of loop with inputs
    puts("enter roll number \n");
   scanf("%d",&access[i].roll);                      //gets data in different member
   puts("enter name \n");
   scanf("%s",access[i].name);
   puts("enter address \n");
   scanf("%s",access[i].address);

   }
   printf("entered data are\n");                  //loop execution to display data
   for(i=0;i<n;i++)
   {
    printf("roll is\n");
   printf("%d",access[i].roll);
   printf("name is\n");
   puts(access[i].name);                            //prints data from related member
   printf("address is\n");
   puts(access[i].address);                         //prints output from related member

    }
    return 0;
}
-----------------------------------------------------------------------------------------------------
using turbo c++
-------------------------------------------------------------------------------------------------
// program to enter detail of some  students       //comment abt. program
#include <stdio.h>                                 //header file
#include<conio.h>
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access[100]; //'access' is a variable to access members. This can hold maximum 100 members.it is called array of struct.
int main()
{
   int n,i;                                         //variable declaration
   printf("enter total value of n\n");
   scanf("%d",&n);                                  //accepts total value
   for(i=0;i<n;i++)
   {                                                 //execution of loop with inputs
    puts("enter roll number \n");
   scanf("%d",&access[i].roll);                      //gets data in different member
   puts("enter name \n");
   scanf("%s",access[i].name);
   puts("enter address \n");
   scanf("%s",access[i].address);

   }
   printf("entered data are\n");                  //loop execution to display data
   for(i=0;i<n;i++)
   {
    printf("roll is\n");
   printf("%d",access[i].roll);
   printf("name is\n");
   puts(access[i].name);                            //prints data from related member
   printf("address is\n");
   puts(access[i].address);                         //prints output from related member

    }
getch();
    return 0;
}

Program to know total memory occupied by struct using size of struct concept.

using codeblocks
--------------------------------------------------------------------------------------------------------------------------
Program to know total memory occupied by struct using size of struct concept.
----------------------------------------------------------------------------------------------------------
// program to use sizeof() in struct            //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

};
struct data access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki and 34 are data.
int main()
{

   printf("total memory is\n");
   printf("%d",sizeof(access));                  // display of total bytes used by struct, using access
    return 0;
}

---------------------------------------------------------------------------------------
using turbo c++
------------------------------------------------------------------------
// program to use sizeof() in struct            //comment abt. program
#include <stdio.h>                                 //header file
#include<conio.h>
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

};
struct data access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki and 34 are data.
int main()
{

   printf("total memory is\n");
   printf("%d",sizeof(access));                  // display of total bytes used by struct, using access
getch();
    return 0;
}

Program to input name,address and roll of a student and display that using struct.

using codeblocks
-----------------------------------------------------------------------
Program to input name,address and roll of a student and display that using struct.
----------------------------
// program to enter detail of a  student            //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access; //'access' is a variable to access members.
int main()
{

   puts("enter name \n");
   gets(access.name);                             //accessing member with period operator for input
   puts("enter address \n");
   gets(access.address);                          //accessing member with period operator for input
   puts("enter roll number \n");
   scanf("%d",&access.roll);                     //accessing member with period operator for input
   printf("name is\n");
   puts(access.name);                            //for output
   printf("address is\n");
   puts(access.address);                         //for output
   printf("roll is\n");
   printf("%d",access.roll);                   //for output
    return 0;

}
-----------------------------------------------------------------------------------------------------------------------
using turboc++
----------------------------------------------------------------------------------------
// program to enter detail of a  student            //comment abt. program
#include <stdio.h>                                 //header file
#include<conio.h>
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access; //'access' is a variable to access members.
int main()
{

   puts("enter name \n");
   gets(access.name);                             //accessing member with period operator for input
   puts("enter address \n");
   gets(access.address);                          //accessing member with period operator for input
   puts("enter roll number \n");
   scanf("%d",&access.roll);                     //accessing member with period operator for input
   printf("name is\n");
   puts(access.name);                            //for output
   printf("address is\n");
   puts(access.address);                         //for output
   printf("roll is\n");
   printf("%d",access.roll);                   //for output
   getch();
    return 0;

}


program to initialize data with struct.

using codeblocks
----------------------------------------------------------------------------------------------------------------------
// program to initialize data in struct            //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki and 34 are                                                              //data.

int main()
{

   puts("name is\n");
   puts(access.name);                             //accessing member with period operator
   puts("address is\n");
   puts(access.address);                          //accessing member with period operator
   puts("roll number is\n");
   printf("%d",access.roll);                     //accessing member with period operator

    return 0;
}

------------------------------------------------------------------------------------------
or
--------------------------------------------------------------------------------
using codeblocks
----------------------------------------------------------------------------------------------------------------------
// program to initialize data in struct            //comment abt. program
#include <stdio.h>                                 //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

};
struct data access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki                                                                           //and 34 are    data.

int main()
{

   puts("name is\n");
   puts(access.name);                             //accessing member with period operator
   puts("address is\n");
   puts(access.address);                          //accessing member with period operator
   puts("roll number is\n");
   printf("%d",access.roll);                     //accessing member with period operator

    return 0;
}

------------------------------------------------------------------------------------------
using turbo c++
--------------------------------------------------------------------------------

// program to initialize data in struct            //comment abt. program
#include <stdio.h>                                 //header file
#include<conio.h>                                //header file
struct data                                        //struct tag named data
{
    char name[80];                                //member1 of struct
    char address[80];                             //member2 of struct
    int roll;                                     //member3 of struct

}access={"rajan","Kalanki",34}; //'access' is a variable to access members. rajan,kalanki and 34 are                                                              //data.

int main()
{

   puts("name is\n");
   puts(access.name);                             //accessing member with period operator
   puts("address is\n");
   puts(access.address);                          //accessing member with period operator
   puts("roll number is\n");
   printf("%d",access.roll);                     //accessing member with period operator
   getch();
    return 0;
}

program to reverse a a string using function.

using codeblocks
-------------------------------------------------------------------------------------------------

// program to reverse a string          // title of program
#include<stdio.h>                           // header file to control input and output
#include<string.h>                           //header file to handle string function
void string_reverse();                       // function prototype
int main()                                  // main function returning integer value
{
    string_reverse();                       // function calling
    return 0;                              // returning value 0
}
void string_reverse()                       // function body
{
  char string[100];                       // string declaration
  printf("enter string");                   // message declaration
  gets(string);                           // gets string from user
  strrev(string);                        // reverses the string and stores in memory
  puts(string);                      // displays  that reversed string
}
---------------------------------------------------------------------------------------------------

using Turbo c++
----------------------------------------------------------------------------------------------------
// program to reverse a string          // title of program
#include<stdio.h>                           // header file to control input and output
#include<string.h>                           //header file to handle string function
#include<conio.h>
void string_reverse();                       // function prototype
int main()                                  // main function returning integer value
{
    string_reverse();                       // function calling
   getch();                                   //holds the output
    return 0;                              // returning value 0

}
void string_reverse()                       // function body
{
  char string[100];                       // string declaration
  printf("enter string");                   // message declaration
  gets(string);                           // gets string from user
  strrev(string);                        // reverses the string and stores in memory
  puts(string);                      // displays  that reversed string
}