Header Ads Widget

Ticker

6/recent/ticker-posts

structure programs

 

STRUCTURE


download link given at the bottom of the page

(only those who comment below they can able to download the file)

 

 

Q1. Write a program to

-Define the structure student having member’s rollno, name, address, marks.

- Initialize the structure for single student by taking input at compile time

- Display the information

 

Ans:-

#include<stdio.h>

struct stud 

{

            char name[20];

            int rollnumber;

            float marks;

}s1; // structure's variable

 

int main()

{

            printf("Enter the name\n");

            scanf("%s",s1.name);

            printf("Enter your roll number \n");

            scanf("%d",&s1.rollnumber);

            printf("Enter marks \n");

            scanf("%f",&s1.marks); 

            printf("Name = %s\n",s1.name);

          printf("Roll Number = %d \n",s1.rollnumber); // dot operator .

            printf("Marks = %f \n",s1.marks);

            return 0;

}

                                    


Q2. Write a program to

-Definethe structure book having members book_id ,title, author, price.

- Initialize the structure for single book by taking input at run time

- Display the information

Ans:-

#include<stdio.h>

struct book

{

            char name[10];

            char author;

            float price;

           

};

int main()

{

            struct book b;

            printf("enter the book name \n");

            gets(b.name);

            printf("enter the book price\n");

            scanf("%f",&b.price);

            printf("enter the name of author \n");

            scanf("%s",&b.author);

           

            printf("book details...\n");

            printf("book name=%s \n",b.name);

            printf("book price=%f \n",b.price);

            printf("book author=%s \n",b.author);

            return 0;

           

}

 

Q3.

. Write a program to

- Define structure Cricket_Team having element player_name, age, score_in_ODI.

- Declare and do Initialization the structure for 5 cricketers by taking input at run time

- Display the information of all cricketers.

 

Ans:-

 

#include<stdio.h>

struct cricketteam

{

    char name[10];

    int age;

    float score;

   

};

int main()

{

    int i,j;

    struct cricketteam b;

    for(i=0;i<=4;i++)

    {

   

    printf("enter the player name \n");

    scanf("%s",&b.name);

   

    printf("enter the player age \n");

    scanf("%d",&b.age);

   

    printf("enter score of player \n");

    scanf("%f",&b.score);

          }

         

          printf("team details...\n");

         

          for(j=0;j<=4;j++)

          {

   

   

   

    printf("player name=%s \n",b.name);

    printf("player age=%d \n",b.age);

    printf("player score=%f \n",b.score);

          }

         

    return 0;

   

}

 

1)    Q4. Write a program to

- Define structure Cricket_Team having element player_name, age, score_in_ODI.

- Declare and do Initialization the structure for 5 cricketers by taking input at run time

- Display the information of all those cricketers those score_in_ODI is >=100.

 

Ans:-

#include<stdio.h>

struct cricketteam

{

     char name[10];

     int age;

     float score;

    

};

int main()

{

     int i,j;

     struct cricketteam b;

     for(i=0;i<=4;i++)

     {

    

     printf("enter the player name \n");

     scanf("%s",&b.name);

    

     printf("enter the player age \n");

     scanf("%d",&b.age);

    

     printf("enter score of player \n");

     scanf("%f",&b.score);

          }

         

          printf("team details...\n");

         

          for(j=0;j<=4;j++)

          {

        if(b.score>=100)

         {

    

 

               printf("player name=%s \n",b.name);

               printf("player age=%d \n",b.age);

               printf("player score=%d \n",b.score);

              }

          }

         

     return 0;

    

}

 

Q5. Write a program to

-Define the structure Student having member’s rollno, name, address, marks.

- Declare and do Initialization of structure for 5 students by taking input at run time

- Display the information each student along with grade i.e pass or fail (marks >= 40 then pass, otherwise fail)

 

Ans:-

 

#include<stdio.h>

struct student

{

    char name[100],address[100];

    int rollno,marks;

 

}st[100];

 

 int main()

 {

     int i;

     printf("enter student info like rollno, name, address, marks \n");

     for(i=1;i<=5;i++)

     {

         scanf("%d %s %s %d", &st[i].rollno,st[i].name,st[i].address,&st[i].marks);

     }

     for(i=1;i<=5;i++)

     {

         if(st[i].marks>=40)

         {

             printf("student %s is pass\t his roll no=%d, name=%s, address=%s, marks=%d  \n",st[i].name,st[i].rollno,st[i].name,st[i].address,st[i].marks);

         }

         if(st[i].marks<40)

         {

             printf("student %s is fail\t his roll no=%d, name=%s, address=%s, marks=%d  \n",st[i].name,st[i].rollno,st[i].name,st[i].address,st[i].marks);

         }

        

        

     }

     return 0;

 }

 

Q6. Write a program to

-Define the structure Book_store having members book_title, book_author, no_of_copies, price_per_copy.

- Declare and do Initialization the structure for 5 books

-Find the total price of each book in store based on no_of_copies and price_per_book.

-Also print the total price of all the books in store.

 

Ans:-

 

 

#include<stdio.h>

struct book

{

    char title[100],author[100];

    int no_copies,price;

 

}h[100];

 

 int main()

 {

     int i;

     printf("enter book info like Book title, Book Author, No of Copies, Price of sum all Copy \n");

     for(i=1;i<=5;i++)

     {

         scanf("%s %s %d %d", h[i].title,h[i].author,&h[i].no_copies,&h[i].price);

     }

     for(i=1;i<=5;i++)

     {

       printf("Title of book=%s\n Author of Book=%s\n No of copies=%d\n price per book=%d\n", h[i].title,h[i].author,h[i].no_copies,(h[i].price)/(h[i].no_copies));  

        

     }

     return 0;

 }

 

 

download link :-

https://cutt.ly/9bW72h3

 

 

 

 

 

Post a Comment

1 Comments