Structured Programming Assignment
Structured Programming Assignment
Structured Programming Assignment
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”);
scanf(“%d”,&arr[i];
j=i;
temp = arr[j];
arr[j] =arr[j-1];
arr[j-1]=temp;
j--;
{
printf(“%d”, arr[i];
return 0;
b.
#include<stdio.h>
int main()
int i,ara[11],sum=0;
scanf(“d”, &ara[i]);
if(ara[i]%2!=0)
sum+=ara[i];
return 0;
c.
#include<stdio.h>
int main()
scanf(“%d”, &ara[i);
if(ara[i]%2==0)
++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()
scanf(“%If, &basic_salary);
printf(“TA: “);
scanf(“%If”, &ta);
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;
Problem 3: Write a program which prints the ASCII values of the characters “A” and “b”.
Solution:
#include<stdio.h>
int main()
return 0;
Solution:
#include<stdio.h>
#include<string.h>
int main()
char text[100],ch;
scanf(“%s”, text);
|en = str|en(text);
ch=text[i];
if(ch==’a’||ch=’e’||ch==’i’||ch=’o’||ch=’u’)
++count;
return 0;
}
Problem 5: Write a program that accepts the following numbers in an array and reverse the array.
Solution:
#include<stdio.h>
int t;
t=*a;
*a=*b;
*b=t;
int main()
int ara[100], n, i;
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()
scanf(“%d” ,&n);
scanf(“%d”,&a[i] ;
min=max=a[0];
if(min>a[i]
min=a[i];
if(max<a[i])
max=a[i];
return 0;
#include <stdio.h>
Long factorial(int);
int main()
int n;
long f;
scanf(“%d”,&n);
if (n<0)
else
f= factorial(n);
return 0;
long factorial(int n)
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 main()
int num;
scanf(“%d”, &num);
printf(“Sum=%d”,addNumbers(num));
return 0;
int addNumbers(int n)
if (n!=0)
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;
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()
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;
return 0;