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

Structured Programming Assignment

The document contains an assignment on structured programming for a course with the code CSE 1151. It includes 10 problems to solve involving arrays, functions, recursion, and breaking down amounts of money into denominations of notes. Sample solutions in C code are provided for each problem to demonstrate structured programming techniques.

Uploaded by

TI Nafis
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)
75 views

Structured Programming Assignment

The document contains an assignment on structured programming for a course with the code CSE 1151. It includes 10 problems to solve involving arrays, functions, recursion, and breaking down amounts of money into denominations of notes. Sample solutions in C code are provided for each problem to demonstrate structured programming techniques.

Uploaded by

TI Nafis
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/ 16

An Assignment on structured programming

Course Title: Structured Programming


Course Code: CSE 1151

Submitted To
Jabed Al Faisal
Lecturer
CSE Discipline
Khulna University, Khulna

Submitted By
Rukhshana Yeasmin
Student id: 200914
Electronics And Communication Engineering Discipline
Khulna University, Khulna
Problem 1: perform the following operations on integer array of 10 elements. Accept the values from
user.

Solution:

a.

#include<stdio.h>

int main()

int i, j, temp;

int arr[11];

printf(“enter 10 integers:\n”);

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

scanf(“%d”,&arr[i];

for (i=1; i<10; i++)

j=i;

while (j>0 && arr[j-1];

temp = arr[j];

arr[j] =arr[j-1];

arr[j-1]=temp;

j--;

printf(“sorted list in ascending order:\n”);

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

{
printf(“%d”, arr[i];

return 0;

b.

#include<stdio.h>

int main()

int i,ara[11],sum=0;

printf(“enter 10 numbers: “);

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

scanf(“d”, &ara[i]);

if(ara[i]%2!=0)

sum+=ara[i];

printf(“odd sum= %d”, sum);

return 0;

c.

#include<stdio.h>

int main()

int ara[11], count=0,i;

printf(“enter 10 numbers: “);

for(i=0: i<10; i++)

scanf(“%d”, &ara[i);

if(ara[i]%2==0)

++count;
}

printf(“there are %d even numbers”,count);

return 0;

Problem 2: Write a program to evaluate the salary of an employee given the following constraints.

Solution:

#include<stdio.h>

int main()

double basic_salary, da, hra, ta, others, pf, it, net_salary;

printf(“enter the following values:\n”);

printf(“basic salary: “);

scanf(“%If, &basic_salary);

printf(“TA: “);

scanf(“%If”, &ta);

double basic_salary, da, hra, ta, others, pf, it, net_salary;

printf(“enter the following values:\n);

printf(“basic_salary: “);

printf(“TA: “);

scanf(“%If”,&ta);

printf(“HRA: “);

scanf(“%If”, &hra);

printf(“others: “);

scanf(“%If”, &others);

da=0.12*basic_salary;

pf=0.14*basic_salary;

it=0.15*basic_salary;

net_salary= basic_salary+dra+hra+ta+others-pf-it;

printf(“the net salary of the employee is .0If$”, net_salary);


return 0;

Problem 3: Write a program which prints the ASCII values of the characters “A” and “b”.

Solution:

#include<stdio.h>

int main()

printf(“ASCII values of A: %d and b: %d”, ‘A’, ‘b’);

return 0;

Problem 4: Write a program to count the number of vowels in a line of text.

Solution:

#include<stdio.h>

#include<string.h>

int main()

char text[100],ch;

int i,|en, count=0;

scanf(“%s”, text);

|en = str|en(text);

for(int i=0;i<|en; i++)

ch=text[i];

if(ch==’a’||ch=’e’||ch==’i’||ch=’o’||ch=’u’)

++count;

printf(“there are %d vowels in the text.”, count);

return 0;

}
Problem 5: Write a program that accepts the following numbers in an array and reverse the array.

Solution:

#include<stdio.h>

void swap(int*a, int*b)

int t;

t=*a;

*a=*b;

*b=t;

int main()

int ara[100], n, i;

printf(“enter the number of elements in the array:”);

scanf(“%d”, &n);

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

scanf(“%d”,&ara[i];

for(i=0:I,n/2,i++)

swap(&ara[i], &ara[n-i-1]);

printf(“reverse array:”);

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

printf(“%d”, ara[i];

return 0;
}

Problem 6: Write a C program to find the minimum and the maximum in an array using function.

Solution:

#include <stdio.h>

#include <conio.h>

int main()

int a[1000], i, n, min,max;

printf(“enter size of the array : ”);

scanf(“%d” ,&n);

printf(“enter elements in array : ”);

for(i=0; i<n: i++)

scanf(“%d”,&a[i] ;

min=max=a[0];

for(i=1; i<n; i++)

if(min>a[i]

min=a[i];

if(max<a[i])

max=a[i];

printf(“minimum of array is : %d”, min);

printf(“\nmaximum of array is : %d”, max);

return 0;

Problem 7: Write a C program to calculate the factorial of an integer using recursion.


Solution:

#include <stdio.h>

Long factorial(int);

int main()

int n;

long f;

printf(“Enter an integer to find its factorial.\n”);

scanf(“%d”,&n);

if (n<0)

printf(“Factorial of negative integers isn’t defined.\n”);

else

f= factorial(n);

Printf(“%d!= %1d\n”, n, f);

return 0;

long factorial(int n)

if (n==0) // Base case

return 1;

else

return (n*factorial(n-1));

Problem 8: Write a C program to find the sum of natural numbers using recursion.
Solution:

#include <stdio.h>

int addNumbers(int n);

int main()

int num;

printf(“Enter a positive integer:”);

scanf(“%d”, &num);

printf(“Sum=%d”,addNumbers(num));

return 0;

int addNumbers(int n)

if (n!=0)

return n + addNumbers(n - 1);

else

return n;

Problem 9: Write a C program to check whether a number is even or odd using functions.

Solution:

#include <stdio.h>

int main ()

int num;

printf(“Enter an integer: “);

scanf(“%d”, &num);

if(num%2==0)

printf(“%d is even.”,num);

else
printf(“%d is odd.”,num);

return 0;

Problem 10: Write a C program to read an amount (integer value) and break the amount into smallest
possible number of bank notes.

Solution:

#include<stdio.h>

#include<conio.h>

int main()

int taka=0, one=0, two=0, five=0, ten=0;

int twenty=0, fifty=0, hundred=0;

printf(“enter total amount\n”);

scanf(“%d”, &taka);

if(taka>=100)

hundred= taka/100;

taka=taka%100;

if(taka>=50)

fifty= taka/50;

taka= taka%50;

if(taka>=20)

ten=taka/10;

taka=taka%10;

}
if(taka>=5)

five=taka/5;

taka=taka%5;

if(taka>=2)

two=taka/2;

taka=taka%2;

if(taka>=1)

one=taka;

printf(“100 taka= %d note\n”, hundred);

printf(“50 taka= %d note\n, fifty);

printf(“20 taka= %d note\n, twenty);

printf(“10 taka= %d note\n, ten”);

printf(“5 taka= %d note\n, five”);

printf(“2 taka= %d note\n, two”);

printf(“1 taka=%d note\n, one);

return 0;

You might also like