Advertisement
Guest User

Untitled

a guest
Mar 27th, 2017
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.19 KB | None | 0 0
  1. 1.
  2.  
  3.  
  4.  
  5.  
  6. #include <stdio.h>
  7. #include <math.h>
  8.  
  9. struct point1 {
  10. int x1;
  11. int y1;
  12. };
  13.  
  14. struct point2 {
  15. int x2;
  16. int y2;
  17. };
  18.  
  19.  
  20. main(){
  21.  
  22. struct point1 P;
  23. struct point2 Q;
  24.  
  25. int a,b,c;
  26.  
  27. printf("Enter the value of x1: ");
  28. scanf("%d",&P.x1);
  29. printf("Enter the value of y1: ");
  30. scanf("%d",&P.y1);
  31. printf("Enter the value of x2: ");
  32. scanf("%d",&Q.x2);
  33. printf("Enter the value of y2: ");
  34. scanf("%d",&Q.y2);
  35.  
  36. a = P.x1-Q.x2;
  37. if(a<0)
  38. a*(-1);
  39.  
  40. b = P.y1-Q.y2;
  41. if(b<0)
  42. b*(-1);
  43.  
  44. c = a+b;
  45.  
  46. printf("M.D. = %d",c);
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53. }
  54.  
  55.  
  56.  
  57.  
  58.  
  59. 2.
  60.  
  61.  
  62. struct student{
  63. int id;
  64. float sub1;
  65. float sub2;
  66. float sub3;
  67. };
  68.  
  69.  
  70. main(){
  71.  
  72. struct student info;
  73. float max,total;
  74.  
  75.  
  76. printf("Enter student ID: ");
  77. scanf("%f",&info.id);
  78.  
  79. printf("Enter 1st subject mark: ");
  80. scanf("%f",&info.sub1);
  81.  
  82. max = info.sub1;
  83.  
  84. printf("Enter 2nd subject mark: ");
  85. scanf("%f",&info.sub2);
  86.  
  87. if(info.sub2>info.sub1)
  88. max = info.sub2;
  89.  
  90.  
  91. printf("Enter 3rd subject mark: ");
  92. scanf("%d",&info.sub3);
  93.  
  94. if(info.sub3>info.sub2)
  95. max = info.sub3;
  96.  
  97. total = info.sub1+info.sub2+info.sub3;
  98.  
  99. printf("ID: %d\nTotal marks: %.2f \nHighest marks: %.2f",info.id,total,max);
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106. }
  107.  
  108.  
  109.  
  110.  
  111.  
  112. 3.
  113.  
  114.  
  115.  
  116. struct employee{
  117. int id;
  118. int age;
  119. float salary;
  120. };
  121.  
  122.  
  123. float highest(struct employee e[], int N){
  124.  
  125. int i;
  126. float max;
  127. max = e[0].salary;
  128. for(i=1;i<N;i++){
  129. if(e[i].salary>max)
  130. max = e[i].salary;
  131. }
  132. return max;
  133.  
  134. }
  135.  
  136. main(){
  137.  
  138.  
  139. int N,i;
  140. float maxSalary;
  141.  
  142. printf("Enter the number of employees: ");
  143. scanf("%d",&N);
  144.  
  145. struct employee e[N];
  146.  
  147. for(i=0;i<N;i++){
  148. printf("\nEnter no. %d employee ID: ",i+1);
  149. scanf("%d",&e[i].id);
  150.  
  151. printf("Enter no. %d employee age: ",i+1);
  152. scanf("%d",&e[i].age);
  153.  
  154. printf("Enter no. %d employee salary: ",i+1);
  155. scanf("%f",&e[i].salary);
  156.  
  157. }
  158.  
  159. maxSalary = highest(e,N);
  160.  
  161.  
  162. printf("%.2f",maxSalary);
  163.  
  164.  
  165. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement