Program to display, add and subtract two value of times in HRS, Minutes and Seconds using structures

Code:

#include <stdio.h>
struct time1
{
    int h1,h2;
    int m1,m2;
    int s1,s2;
}time;
main( )
{
    int i,s1,s2,d1,d2,d3;
    printf("Enter the first time in Hrs, mins and seconds.\n");
    scanf("%d %d %d",&time.h1,&time.m1,&time.s1);
    printf("Enter the second time in Hrs, mins and seconds.\n");
    scanf("%d %d %d",&time.h2,&time.m2,&time.s2);
    printf("Choose the operation:\n1. Read\n2. Display\n3. Add\n4. Subtract\n5. Exit.\n");
    scanf("%d",&i);
    switch(i)
    {
        case 1:
        {
            printf("You have entered:\n1. %dHr %dMin %dSeconds.\n2. %dHr %dMin %dSeconds.",time.h1,time.m1,time.s1,time.h2,time.m2,time.s2);
            break;

        }

        case 2:
        {
            printf("You have entered:\n1. %dHr %dMin %dSeconds.\n2. %dHr %dMin %dSeconds.",time.h1,time.m1,time.s1,time.h2,time.m2,time.s2);
            break;
        }

        case 3:
        {
            s1=time.s1+time.s2;
            s2=time.m1+time.m2;
            if(time.s1+time.s2>60)
            {
                s1=time.s1+time.s2;
                s1=s1-60;
                s2++;
            }
            if(time.m1+time.m2>60)
            {
                s2=s2-60;
                time.h1++;
            }

            printf("Addition:\n%dHr %dMin %dSeconds",time.h1+time.h2,s2,s1);
            break;

        }
        case 4:
            {
                if(time.h1>time.h2)
                {

                    d1=time.h1-time.h2;
                    d2=time.m1-time.m2;
                    d3=time.s1-time.s2;
                    if(d2<0)
                    {
                        d2=d2+60;
                        d1=d1-1;
                    }
                     if(d3<0)
                    {
                        d3=d3+60;
                        d2=d2-1;
                    }
                }
                if(time.h2>time.h1)
                {
                    d1=time.h2-time.h1;
                    d2=time.m2-time.m1;
                    d3=time.s2-time.s1;

                    if(d2<0)
                    {
                        d2=d2+60;
                        d1=d1-1;
                    }
                     if(d3<0)
                    {
                        d3=d3+60;
                        d2=d2-1;
                    }

                }
                if(time.h1==time.h2)
                {
                    d1=0;
                    d2=time.m1-time.m2;
                    d3=time.s1-time.s2;
                    if(d2<0)
                    {
                        d2=0-d2;
                    }
                    if(d3<0)
                    {
                        d3=d3+60;
                        d2--;
                    }

                }
                if(time.m1==time.m2)
                {
                    d2=0;
                }
                if(time.s1==time.s2)
                {
                    d3=0;
                }
                    printf("Subtraction - %dHr %dMin %dSeconds.",d1,d2,d3);
                    break;

                }

            }
    }

 

Program to to read and display data of students using an array of pointers

#include<stdio.h>

    struct dob1
    {
        int date;
        int month;
        int year;
    }dob;

    struct student
    {
        int rno;
        char fname[80];
        char lname[80];
        int fees;
    } 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]=dob.date;
        p[j+3]=dob.month;
        p[j+4]=dob.year;
        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 date of birth [DD/MM/YYYY respectively] of student no. %d\n",i+1);
        scanf("%d",&p[j+2]);
        scanf("%d",&p[j+3]);
        scanf("%d",&p[j+4]);
        j=j+5;
        k=k+2;
        l=l+30;
        m=m+30;

    }
    j=0;
    k=0;
    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("Roll no. of student - %d\n",p[j]);
        printf("Fees - %d\n",p[j+1]);
        printf("Date of birth - %d/%d/%d\n",p[j+2],p[j+3],p[j+4]);
        printf("\n\n\n_______________________________________________\n\n\n\n");
        l=l+30;
        m=m+30;
        j=j+5;
        k=k+2;

    }
}

Output:

21_3