Sunday, 24 April 2022

10. Define a structure with tag population with fields Men and Women. Create structure with in structure using state and population structure. Read and display the data.

 


#include<stdio.h>
#include<conio.h>

struct population
{
    long men,women;
}p1;

struct state
{
    char name[60];
    long total;
    struct population p1;
}s1;

void main()
{
    clrscr();

    printf("enter state name: ");
    scanf("%s",s1.name);
    printf("enter how many men: ");
    scanf("%ld",&s1.p1.men);
    printf("enter how many women: ");
    scanf("%ld",&s1.p1.women);

    s1.total = s1.p1.men + s1.p1.women;

    printf("\n\nstate name: %s",s1.name);
    printf("\nmen: %ld",s1.p1.men);
    printf("\nwomen: %ld",s1.p1.women);
    printf("\ntotal population: %ld",s1.total);
    getch();
}

/*  output:

enter state name: gujrat
enter how many men: 28000                                                      
enter how many women: 20000                                                    
                                                                               
                                                                               
state name: gujrat                                                              
men: 28000                                                                      
women: 20000                                                                    
total population: 48000                                                        
                                                                               
*/

No comments:

Post a Comment

python programs

1. sum of two number