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
write a program to accept ten numbers and display the total

Objective of this Program: (a) To learn more about modularization of a program into independent modules, (b) To use arrays in a program, (c) To get some experience with us


Your program should use the Free Pascal compiler or the Lazarus IDE described in CSC 540. When you hand in your assignment to the digital dropbox, it should be a .PAS file, not zip

Example for Register Storage Class - computer programming? main() { register int i; for (i=0; i { ............... ............... } } /* block exit will free the register

THIS PROGRAM IS TO ADD THE TWO COMPLEX NO.S GIVEN BY THE USER  */ #include #include #include struct complex     {     int real;     int imag;     }; void main()  {  clrs

string will contain only lower case alphabet& the ascii value starts from 1-26,(ie,a=1&z=26).it perform the operation like the following costs:add=2units,replace=1unit,delete=3unit

Explain about Evaluation of Expression in c language? An Expressions are evaluated using an assignment statement of the form: variable = expression; The Variable is any v

The program must use the file named on the command line as its input file. Suppose the program is named pdbtool. Then if the user types pdbtool 1A36.pdb the program must read the d

A Padovan string P(n) for a natural number n is defined as: P(0) = ‘X’ P(1) = ‘Y’ P(2) = ‘Z’ P(n) = P(n-2) + P(n-3), n>2 where + denotes string concatenation.