Advertisement
Mr_kindle

marks.c

Oct 27th, 2022
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.60 KB | None | 0 0
  1. /*The Department faculty prepared multiple-choice questions for a class surprise test. The
  2. surprise test consists of “Q” questions with each question having certain number of marks
  3. assigned to it. However, the faculty has been told by the Examination Head that each question
  4. in the paper should carry a different weightage of marks, which means no two questions can
  5. have the same marks.
  6. So the Department faculty wants to do this by adjusting minimal changes in the original
  7. assigned marks; assigning every question at least as much marks as it originally had.
  8. Find the minimum total marks that the faculty can set the paper for.
  9. Input
  10. 1) First-line contains “Q”, the total number of questions in the paper.
  11. 2) Second-line contains “N” space-separated integers A1, A2 ... An representing the original
  12. marks assigned to every question.
  13. Output
  14.  Minimum total marks the faculty can set the paper for*/
  15.  
  16. /*input
  17. 10
  18. 3
  19. 4
  20. 4
  21. 4
  22. 5
  23. 5
  24. 6
  25. 10
  26. 10
  27. 10
  28. output
  29. 75 */
  30.  
  31. #include<stdio.h>
  32. #include<stdlib.h>
  33. /*fun for sorting array in ascending order*/
  34. void sortarray(int item[], int n)
  35. {
  36.     int i,j,temp,flag = 0;
  37.     for(i=0;i<n-1;i++)
  38.         {
  39.             for(j=i+1;j<n;j++)
  40.                 {
  41.                     if(item[i]>item[j])
  42.                         {
  43.                             temp = item[i];
  44.                             item[i] = item[j];
  45.                             item[j]= temp;
  46.                             flag++;
  47.  
  48.                         }
  49.                 }
  50.                 if(flag == 0)//it mean no swapping happened means array is sorted  
  51.                     break;
  52.         }
  53. }//sortarray
  54.  
  55. int main()
  56. {
  57.     int marks[30],num,i,j,sum=0;
  58.     printf("Enter number of questions: ");
  59.     scanf("%d",&num);
  60.     printf("\nPlease enter marks of %d questions:\n ",num);
  61.     for(i=0;i<num;i++)
  62.         {    printf("Question %d: ",i+1);
  63.              scanf("%d",&marks[i]);
  64.         }
  65.         /*sorting array in ascending order*/
  66.         sortarray(marks, num);
  67.     for(i=0;i<num;i++)
  68.         {    
  69.             for(j=i+1;j<num;j++)
  70.                 {
  71.                     if(marks[i]<marks[j])
  72.                         break;
  73.                     else if(marks[i]>=marks[j])
  74.                         {
  75.                             marks[j]=marks[i]+(j-i);
  76.                         }
  77.                 }
  78.         }
  79.         printf("\nupdated marks:\n");
  80.         for(i=0;i<num;i++)
  81.            { printf("%d ",marks[i]);
  82.                 sum = sum + marks[i];
  83.             }
  84.             printf("\n");
  85.             printf("\nMinimum total marks = %d",sum);
  86.        
  87.        
  88.     return 0;
  89. }
  90.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement