0% found this document useful (0 votes)
36 views

Terminal: Introduction To Computer Programming CSC-14

This document contains 4 questions related to C programming involving structures. The questions ask the student to define nested structures for locations, cities, and countries; write a function to initialize the structure variables; compare the populations of cities in an array; and write a function to input city names and display those starting with vowels. Sample code is provided for each question to demonstrate how to define and use the structures as requested.

Uploaded by

Souban Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
36 views

Terminal: Introduction To Computer Programming CSC-14

This document contains 4 questions related to C programming involving structures. The questions ask the student to define nested structures for locations, cities, and countries; write a function to initialize the structure variables; compare the populations of cities in an array; and write a function to input city names and display those starting with vowels. Sample code is provided for each question to demonstrate how to define and use the structures as requested.

Uploaded by

Souban Javed
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 7

Introduction to Computer Programming

CSC-14

Terminal

Name Muhammad Khubaib Hassan

Registration
FA20-BEE-131
Number

Class
FA20-BEE-2C

Instructor’s Name Mam. Amber Zeb


Question no:-01
a) Write a structure called Location which has two integer
members, latitude and longitude.
b) Write another structure City with three members, a string
called name, an integer called population and a Location
called loc.
c) Write a structure Country with four members, a string
called name, an integer called population, an integer called
n_cities (number of cities in a country) and an array of City
called cities.
Program:-
a:-
#include <stdio.h>

#include <stdlib.h>

struct location

int latitude;

int longitude;

};

b:-
#include <stdio.h>

#include <stdlib.h>

struct city

char name[10];

int population;
int loc;

name, population, location;

c:-
#include <stdio.h>

#include <stdlib.h>

struct coutry

string name[10]

int population;

int n_cities;

array cities[10]

name,population,number of cities,cities name;

Question no:-02
Write a function input that initializes all the member
variables of the struct Country. You should pass a structure variable
to the function using pointer.

Program:-
#include <stdio.h>

#include <stdlib.h>

#include <string.h>
struct location

int latitude;

int longitude;

};

struct country

char name[100];

int population;

int n_cities; //number of cities

struct city c[100];

};

void input(struct country co2)

co1=co2;

int main()

struct location l1;

l1.latitude=10;

l1.longitude=20;

struct city c1;


strcpy(c1.name,"Islamabad");

c1.population=10000;

c1.l=l1;

struct country co2;

strcpy(co2.name,"Pakistan");

co2.population=220000000;

co2.c[0]=c1;

input(co2);

return 0;

Question no:-03
Write in main a City structure array with 4 cities details in it.
(You can initialize the array in the main by giving direct values to the
array.)

Write a function compare that compares the population of two


of the cities and prints the name of the city that has lesser population.
The function takes structure array as parameter. For example compare
city[2] and city [3]. The cities city[2] and city[3] will be given as the
parameter to the function.

Program:-

Output:-
Question no:-04
Write a function that inputs the names of 5 cities and displays the
names of the city whose name starts with a vowel. (For ease and
simplicity, Do not use the above mentioned city structure.)

Program:-
#include <stdio.h>

#include <stdlib.h>

void function()

int i=0;

char ch;

char city1[5][20];

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

printf("please write the name of city:\n");

scanf("%s",&city1[i]);

printf("names of cities starting with vowels:");

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

ch=city1[i][0];

if (ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u');

printf("%s\n",city1[i]);
}

int main()

function();

return 0;

Output:-

You might also like