Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1.
- #include <stdio.h>
- #include <math.h>
- struct point1 {
- int x1;
- int y1;
- };
- struct point2 {
- int x2;
- int y2;
- };
- main(){
- struct point1 P;
- struct point2 Q;
- int a,b,c;
- printf("Enter the value of x1: ");
- scanf("%d",&P.x1);
- printf("Enter the value of y1: ");
- scanf("%d",&P.y1);
- printf("Enter the value of x2: ");
- scanf("%d",&Q.x2);
- printf("Enter the value of y2: ");
- scanf("%d",&Q.y2);
- a = P.x1-Q.x2;
- if(a<0)
- a*(-1);
- b = P.y1-Q.y2;
- if(b<0)
- b*(-1);
- c = a+b;
- printf("M.D. = %d",c);
- }
- 2.
- struct student{
- int id;
- float sub1;
- float sub2;
- float sub3;
- };
- main(){
- struct student info;
- float max,total;
- printf("Enter student ID: ");
- scanf("%f",&info.id);
- printf("Enter 1st subject mark: ");
- scanf("%f",&info.sub1);
- max = info.sub1;
- printf("Enter 2nd subject mark: ");
- scanf("%f",&info.sub2);
- if(info.sub2>info.sub1)
- max = info.sub2;
- printf("Enter 3rd subject mark: ");
- scanf("%d",&info.sub3);
- if(info.sub3>info.sub2)
- max = info.sub3;
- total = info.sub1+info.sub2+info.sub3;
- printf("ID: %d\nTotal marks: %.2f \nHighest marks: %.2f",info.id,total,max);
- }
- 3.
- struct employee{
- int id;
- int age;
- float salary;
- };
- float highest(struct employee e[], int N){
- int i;
- float max;
- max = e[0].salary;
- for(i=1;i<N;i++){
- if(e[i].salary>max)
- max = e[i].salary;
- }
- return max;
- }
- main(){
- int N,i;
- float maxSalary;
- printf("Enter the number of employees: ");
- scanf("%d",&N);
- struct employee e[N];
- for(i=0;i<N;i++){
- printf("\nEnter no. %d employee ID: ",i+1);
- scanf("%d",&e[i].id);
- printf("Enter no. %d employee age: ",i+1);
- scanf("%d",&e[i].age);
- printf("Enter no. %d employee salary: ",i+1);
- scanf("%f",&e[i].salary);
- }
- maxSalary = highest(e,N);
- printf("%.2f",maxSalary);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement