Program to read display add and subtract the two distances using structures

#include<stdio.h>
#include<conio.h>
struct hi
{
    int k1,k2;
    int m1,m2;
} kil;
main()
{
    int a;
    printf("Enter the first distance in parts of kilometres and metres respectively\n");
    scanf("%d",&kil.k1);
    scanf("%d",&kil.m1);
    printf("Enter the second distance in parts of kilometres and metres respectively\n");
    scanf("%d",&kil.k2);
    scanf("%d",&kil.m2);
    printf("Select the operation\n1. Addition\n2. Subtraction\n3. Read\n4. Display\n5. Exit\n");
    scanf("%d",&a);
    if(a==1)
    {
        printf("Addition - %d Kilometres & %d Metres",kil.k1+kil.k2,kil.m1+kil.m2);
    }
    else if(a==2)
    {
        printf("Subtraction - %d Kilometres & %d Metres)",kil.k1-kil.k2,kil.m1-kil.m2);
    }
    else if(a==3)
    {
        printf("Distances entered by you:\n1. %d Kilometres & %d Metres",kil.k1,kil.m1);
        printf("Distances entered by you:\n2. %d Kilometres & %d Metres",kil.k2,kil.m2);
    }

    else if(a==4)
     {
        printf("Distances entered by you:\n1. %d Kilometres & %d Metres",kil.k1,kil.m1);
        printf("Distances entered by you:\n2. %d Kilometres & %d Metres",kil.k2,kil.m2);
    }
    else if(a==5)
    {
        exit(1);
    }

    else
        {
            printf("Not a valid operation.");

        }

}

 

Output:

14_3

Passing members of structure student by using call by reference.

#include<stdio.h>

    struct student
    {
        int rno;
        char fname[80];
        char lname[80];
        int fees;
        int class;
    } stud;

main()
{

    int n,i,j=0,k=0,l=0,m=0;
    int *p[100];
    char *q[1000];

    printf("Enter no. of students\n");
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        p[j]=stud.rno;
        p[j+1]=stud.fees;
        p[j+2]=stud.class;
        q[k]=&stud.fname[l];
        q[k+1]=&stud.lname[m];
        printf("Enter the first name of student no. %d\n",i+1);
        scanf("%s",q[k]);
        printf("Enter the last name of student no. %d\n",i+1);
        scanf("%s",q[k+1]);
        printf("Enter the roll no. of student no. %d\n",i+1);
        scanf("%d",&p[j]);
        printf("Enter the fees of student no. %d\n",i+1);
        scanf("%d",&p[j+1]);
        printf("Enter the class of student no. %d\n",i+1);
        scanf("%d",&p[j+2]);

        j=j+3;
        k=k+2;
        l=l+30;
        m=m+30;

    }
    func(&p,&q,n);
}

int func(int *p, int *q, int n)
{

    int j=0,k=0,i,l,m;

    printf("\n\n\nInformation of students are as follows:\n\n\n\n_______________________________________________\n\n\n");

    for(i=0;i<n;i++)
    {
        printf("Information of student no. %d\n",i+1);
        printf("Name of the student - %s %s\n",q[k],q[k+1]);
        printf("Class - %d\n",p[j+2]);
        printf("Roll no. of student - %d\n",p[j]);
        printf("Fees - %d\n",p[j+1]);

        printf("\n\n\n_______________________________________________\n\n\n\n");
        l=l+30;
        m=m+30;
        j=j+3;
        k=k+2;

    }
}

 

Output:

14_2