You are on page 1of 12

PROCEDURAL PROGRAMMING

COMP 211
PAKO OTENG
19000839
ELECTRICAL AND ELECTRONICS ENGINEERING
QUESTION 1 FLOWCHART

Start

Enter house value

Is house value > 1000000? Yes Tax = (10/100)*house value

No

Is house value > 750000? Yes Tax = (7.5/100)*house value

No

Is house value >500000? Yes Tax = (5/100)*house value

No

Is house value >250000? Yes Tax = (10/100)*house value Display Tax

No

Display “Don’t pay tax” Stop


QUESTION 1 CODE
TESTING QUESTION 1 OUTPUT
QUESTION 2 FLOWCHART

QUESTION 2 CODE

#include <stdio.h>

int IsaPrimenumber(int noum);

int main()

int noum1, num2, i, prm; //FUNCTION PROTOTYPE

printf("Enter two positive integers as the range:\n");

scanf("%d %d", &num1, &num2);

if(num1<num2){

printf("Prime numbers between %d and %d are:\n", num1, num2);

else{

printf("First number should be smaller than Second number");

for (i = num1 + 1; i < num2; ++i) {

prm = IsaPrimenumber(i); //FUNCTION CALLING

if (prm == 1)

printf("%d ", i);

return 0;

int IsaPrimenumber(int no) { //FUNCTION DEFINITION

int z, prm = 1;

for (z = 2; z <= n / 2; ++z) {


if (n % z == 0) {

prm = 0;

break;

return prm; //RETURN STATEMENT

}
TESTING OUTPUT
QUESTION 3 CODE

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
typedef struct{
char title[50];
char author[50];
char publisher[50];
int year_pub;
int noum_pages;
double price;
}
BK;
void sortByPrice(BK *BK, int no);
void sortByAuthorTitle(BK *BK, int no);
int main()
{
int no;
printf("How many BKs would you like to enter: ");
scanf("%d", &n);
BK *BKs = (BK *)malloc(n*sizeof(BK));
for(int i=0; i<n; i++)
{
printf("Enter BK title: ");
scanf("%s", BKs[i].title);
printf("Enter BK author: ");
scanf("%s", BKs[i].author);
printf("Enter BK publisher: ");
scanf("%s", BKs[i].publisher);
printf("Enter BK publishing year: ");
scanf("%d", &BKs[i].year_pub);
printf("Enter no of pages: ");
scanf("%d", &BKs[i].num_pages);
printf("Enter price: ");
scanf("%lf", &BKs[i].price);
}
char author[60];
printf("Enter author name: ");
scanf("%s", author);
int exists = 0;
for(int i=0; i<n; i++)
{
if(strcmp(BKs[i].author, author)==0)
{
printf("BK Title: %s\n", BKs[i].title);
printf("BK Publisher: %s\n", BKs[i].publisher);
printf("BK Publishing Year: %d\n",BKs[i].year_pub);
printf("BK No_of Pages: %d\n", BKs[i].num_pages);
printf("BK Price: %lf\n",BKs[i].price);
exists = 1;
}
}
if(!exists)
printf("No BKs found with author %s\n\n", author);
sortByPrice(BKs, n);
char publisher[60];
printf("Enter publisher name: ");
scanf("%s", publisher);
exists = 0;
for(int i=0; i<n; i++){
if(strcmp(BKs[i].publisher, publisher)==0)
{
printf("BK Title: %s\n", BKs[i].title);
printf("BK Publisher: %s\n", BKs[i].publisher);
printf("BK Publishing Year: %d\n",BKs[i].year_pub);
printf("BK No_of Pages: %d\n", BKs[i].num_pages);
printf("BK Price: %lf\n",BKs[i].price);
exists = 1;
}
}
if(!exists)
printf("No BKs found with publisher %s\n\n", publisher);
sortByAuthorTitle(BKs, n);
for(int i=0; i<n; i++){
if(strcmp(BKs[i].publisher, publisher)==0)
{
printf("BK Title: %s\n", BKs[i].title);
printf("BK Publisher: %s\n", BKs[i].publisher);
printf("BK Publishing Year: %d\n",BKs[i].year_pub);
printf("BK No_of Pages: %d\n", BKs[i].num_pages);
printf("BK Price: %lf\n",BKs[i].price);

}
printf("\n");`
}
return 0;
}
void sortByPrice(BK *BKs, int no)
{
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(BKs[i].price>BKs[i].price)
{
BK temp = BKs[i];
BKs[i] = BKs[j];
BKs[j] = temp;
}}}}
void sortByAuthorTitle(BK *BKs, int no)
{
for(int i=0; i<n; i++)
{
for(int j=i+1; j<n; j++)
{
if(BKs[i].author>BKs[i].author && BKs[i].title>BKs[i].title)
{
BK temp = BKs[i];
BKs[i] = BKs[j];
BKs[j] = temp;
}}}}

You might also like