C program to construct a structure , C/C++ Programming

c program to construct a structure:

struct sensus

                {

                                char name[30];

                                long int population;

                                float litracy_rate;

                };

 

                void main()

                {

                                struct sensus city[5];

                                printf("\n Enter Data for 5 cities:\n");

                                                for(int i=0; i<5;i++)

                                                {

                                                                printf("\n City Name:\t");

                                                                scanf("%s",&city[i].name);

                                                                printf("\n Population:\t");

                                                                scanf("%ld",&city[i].population);

                                                                printf("\n litracy rate:\t");

                                                                scanf("%f",&city[i].litracy_rate);

                                                                printf("\n\n\a");

                                                }

                                                for(i=0; i<4;i++)

                                                {for(int j=0;j<5-(i+1);j++)

                                                                {

                                                                if(city[i].litracy_rate>city[i+1].litracy_rate)

                                                                {

                                                                                struct sensus t=city[i];

                                                                                city[i]=city[i+1];

                                                                                city[i+1]=t;

                                                                }

                                                }

                                                }

                                                printf("You enter the Following Data:\n");

                                                for(i=0;i<5;i++)

                                                {

                                                                printf("\n CityName:\t%s",city[i].name);

                                                                printf("\n Pupulation:\t%ld",city[i].population);

                                                                printf("\n Litracy Rate=\t%f",city[i].litracy_rate);

                                                                printf("\n\n");

                                                }

 

                }

Posted Date: 9/29/2012 7:15:08 AM | Location : United States







Related Discussions:- C program to construct a structure , Assignment Help, Ask Question on C program to construct a structure , Get Answer, Expert's Help, C program to construct a structure Discussions

Write discussion on C program to construct a structure
Your posts are moderated
Related Questions
Within programs we very often want to execute a different section of code, depending upon various conditions within C the If statement is used to achieve this. The If statement con

Make the following 3 functions work by filling in appropriate C code. This file 1. // Write a function to count the number of particular characters in a string. // Do not use a

Is it probable to encompass Virtual Constructor? If yes, how? If not, Why?

What are compound statements? - Compound statements are made up of two or more program statements that are executed together. They may be executed with a loop. - Curly brack

Write a program that computes the cost of a long distance call. The cost of the call is determined according to the following rate schedules. a. A call made between 8:00 AM and

Define hash functions. Explain the Division method, Mid square method and Folding method of hash functions.

Write a program to find the area under the curve y = f(x) between x = a and x = b, integrate y = f(x) between the limits of a and b. The area under a curve between two points can b

calculate the total resisitance of a series circuit?

a program code for superposition of sine waves

Default Arguments A default argument is a value that is automatically assigned to a formal variable, if the actual argument from the function call is omitted. e.g. void