Khulna University: Structured Programing Assignment, CSE
Khulna University: Structured Programing Assignment, CSE
Khulna University: Structured Programing Assignment, CSE
SUBMITTED BY
MD.TOWHIDUL ISLAM
STUDENT_ID: 200913
ELECTRONICS AND COMMUNICATION ENGINEERING DISCIPLINE
Problem 1:Perform the following operations on an integer array
of 10 elements. Accept thevalues from the user.
a. Sort an array in ascending order.
Solution:
#include<stdio.h>
int main()
{
int i,j,a,num[50];
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(num[i]>num[j])
{
a=num[i];
num[i]=num[j];
num[j]=a;
}
}
}
printf("Sorted elements of array in ascending order: ");
for(i=0;i<10;i++)
{
printf(" %d",num[i]);
}
return 0;
Solution:
#include<stdio.h>
int main()
{
int i,num[50],sum=0;
for(i=0;i<10;i++)
{
scanf("%d",&num[i]);
}
for(i=0;i<10;i++)
{
if(num[i]%2!=0)
sum=sum+num[i];
}
return 0;
}
Solution:
#include<stdio.h>
int main()
{
int i, numbers[50], a=0;
for(i=0; i<10; i++)
{
scanf("%d", &numbers[i]);
}
for(i=0; i<10; i++)
{
if(numbers[i]%2==0)
a=a+1;
}
printf("The number of even values stored in an array : %d", a);
return 0;
}
return 0;
}
Solution:
#include<stdio.h>
int main()
{
printf("the ASCII value of the character A = %d\n and ", 'A');
printf("the ASCII value of the character b = %d\n ", '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 a[100], ch;
int i, n, c = 0;
scanf("%s", a);
n = strlen(a);
return 0;
}
Solution:
#include<stdio.h>
int main()
{
int a[50], n, i;
scanf("%d", &n);
for(i=0 ; i<n; i++)
{
scanf("%d", &a[i]);
}
printf("Reverse Array: ");
for(i=n-1; i>=0; i--)
{
printf("%d ", a[i]);
}
return 0;
}
Solution:
#include<stdio.h>
int main()
{
int a[100], i, n;
printf("Enter the number of elements in the array: ");
scanf("%d", &n);
for(i=0 ; i<n; i++)
{
scanf("%d", &a[i]);
}
return 0;
}
Solution:
#include<stdio.h>
int fac(int n)
{
if(n==1)
return 1;
else
return (n*fac(n-1));
}
int main()
{
int n;
scanf("%d", &n);
printf("factorial = %d", fac(n) );
return 0;
}
Solution:
#include<stdio.h>
int sum(int n)
{
if(n==1)
return 1;
else
return n+sum(n-1);
}
int main()
{
int n;
scanf("%d", &n);
return 0;
}
Solution:
#include<stdio.h>
int is_even(int n)
{
if(n%2==0)
return 1;
else
return 0;
}
int main()
{
int n;
scanf("%d", &n);
if(is_even(n))
printf("Even");
else
printf("Odd");
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>
int main()
{
int amount;
printf("Input the amount: ", &amount);
scanf("%d", &amount);
return 0;
}