Travel with cheap hotels and flights ! Book online now

Travel with cheap hotels and flights ! Book online now
Travel with cheap hotels and flights ! Book online now

Thursday, 2 February 2017

Write a prog to read data of 30 students for four subjects. total marks obtained, student with highest marks in each subject and student with highest marks.

//Write a prog to read data of 30 students for four subjects. total marks obtained, student with highest marks in each subject and student with highest marks.
#include<stdio.h>
#define SIZE 30

struct stu {                      //stu for student
   char name[30];
   int rollno;
   int sub[4];
};

void main() {
   int i, j, max, count, total, n, a[SIZE], ni;  // n for number of students
   struct stu st[SIZE];
   clrscr();

   printf("Enter Number of students: ");  // for eg: 2 students
   scanf("%d", &n);

   // loop to print the names and roll numbers
   for (i = 0; i < n; i++) {
      printf("\nEnter name and roll number for student %d : ", i);
      scanf("%s", &st[i].name);
      scanf("%d", &st[i].rollno);
   }

   //loop to print ith student's jth subject
   for (i = 0; i < n; i++) {
      for (j = 0; j <= 4; j++) {
         printf("\nEnter marks of student %d for subject %d : ", i, j);
         scanf("%d", &st[i].sub[j]);
      }
   }

   //(i) for loop to calculate total marks obtained by each student

   for (i = 0; i < n; i++) {
      total = 0;
      for (j = 0; j < 4; j++) {
         total = total + st[i].sub[j];
      }
      printf("\nTotal marks obtained by student %s are %d\n", st[i].name,total);
      a[i] = total;
   }

  // (ii) for loop to list out the student's roll numbers who
   // have secured the highest marks in each subject

   // roll number who secured the highest marks

   for (j = 0; j < 4; j++) {
      max = 0;
      for (i = 0; i < n; i++) {
         if (max < st[i].sub[j]) {
            max = st[i].sub[j];
            ni = i;
         }
      }
      printf("\nStudent %s got maximum marks = %d in Subject : %d",st[ni].name, max, j);
   }

   max = 0;

   for (i = 0; i < n; i++) {
      if (max < a[i]) {
         max = a[i];
         ni = i;
      }
   }

   printf("\n%s obtained the total highest marks.", st[ni].name);
   getch();
}

Write a program in C language to input the details of 3 books ( name, price, quantity) and then calculate its total cost with loop.

Write a program in C language to input the details of 3 books ( name, price, quantity) and then calculate its total cost with loop.

#include<stdio.h>
#include<conio.h>
void main()
       struct book
        {
              char bname[20];
               input p,qty,tc;  // p is price, qty is quantity, tc is total cost
          };    // semicolon is must

            struct book b[100] ; 
           int i,n ; // i for looping, n is number to enter for books quanity
           clrscr();
           printf("Enter Number of Books");
           scanf("%d",&n);
            
            for(i=0;i<=n-1;n++)  // i starts from first number ie..0, i will be equal to last number ie n-1,                                                                                     //increase one by one
             {
                printf("Enter details of books  %d", i+1);
                printf(" Enter Bookname");
                scanf("%s",&b[i].p, b[i].qty); 
               printf("Enter price and quantity");
               scanf("%d%d",&b[i].p,&b[i].qty);
        
              }
                   for(i=0;i<=n-1;i++)
                   {
                         b[i]tc = b[i].p * b[i].qty;
                           printf(" Total cost of book = %d\n", i+1,b[i].tc);
                     }
                     getch();
}

write a program in C using struture to calculate marks of 10 students in differnet subjects

write a program in C using struture to calculate marks of 10 students in different subjects

#include<stdio.h>
#include<conio.h>

        struct student // sturcture for student

        {
          int sub1;                   //subject 1
          
                   int sub2;                 //subject 2
 
          int sub3;                 //subject 3
 
       };
           
 void main()
     
   {
            
              struct student s[10]; 
              int i,total=0;
             
             clrscr(); 
             for(i=0;i<=2;i++)   // loop
 
                 {
                  printf("\nEnter Marks in Three Subjects = ");

                                       scanf("%d%d%d",& s[i].sub1,&s[i].sub2,&s[i].sub3);

                        total=s[i].sub1+s[i].sub2+s[i].sub3;  // total to calculate

                        printf("\nTotal marks of s[%d] Student= %d",i,total); 
                 } 
              getch();
 
        }

Write a program in c language to input the details of 3 books ( name, price, quantity) and then calculate its total cost.

Write a program in c language to input the details of 3 books ( name, price, quantity) and then calculate its total cost.

#include<stdio.h>
#include<conio.h>
void main()
{
       struct book                // structure book
       {
            char bname[20];
            int p,qty,tc ;                 // p is price ; qty is quantity, tc is total cost
         };

                struct book b1, b2, b3;    // b1 is book 1, b2 is book 2, b3 is book 3
                clrscr();
                printf(" Enter details of book 1");
                printf("\n Bookname");
                scanf("%s", b1.bname);   // enter name of book
                printf(" Enter price & qty");
                scanf("%d%d",&b1.p,&b1.qty); // enter the price and quanity of book 1

               printf(" Enter details of book 2");
                printf("\n Bookname");
                scanf("%s", b2.bnaame);
                printf(" Enter price & quty");
                scanf("%d%d",&b2.p,&b2.qty); // enter the price and quanity of book 2

               printf(" Enter details of book 3");
                printf("\n Bookname");
                scanf("%s", b3.bnaame);
                printf(" Enter price & quty");
                scanf("%d%d",&b3.p,&b3.qty); // enter the price and quanity of book 3

                b1.tc = b1.p * b1.qty;    // formula to calculate total cost of book1
                b2.tc = b2.p * b1.qty;    // formula to calculate total cost of book2
                b3.tc = b3.p * b1.qty;    // formula to calculate total cost of book3

              printf("Total cost of book1 = %d\n, b1.tc);
              printf("Total cost of book2 = %d\n, b2.tc);
              printf("Total cost of book3 = %d\n, b1.tc);
             
               getch();
}