0% found this document useful (0 votes)
39 views11 pages

Cse 2nd Assignment

This document contains 10 programming problems and their solutions in C language. It focuses on array operations, functions, recursion, and breaking down an amount into smallest number of banknotes. The problems cover sorting arrays, finding sum of odd array elements, counting even elements, calculating employee salary, printing ASCII values, reversing arrays, finding minimum and maximum values using functions, calculating factorials and sum of natural numbers recursively, checking even/odd numbers using functions, and breaking down an amount into banknotes.

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)
39 views11 pages

Cse 2nd Assignment

This document contains 10 programming problems and their solutions in C language. It focuses on array operations, functions, recursion, and breaking down an amount into smallest number of banknotes. The problems cover sorting arrays, finding sum of odd array elements, counting even elements, calculating employee salary, printing ASCII values, reversing arrays, finding minimum and maximum values using functions, calculating factorials and sum of natural numbers recursively, checking even/odd numbers using functions, and breaking down an amount into banknotes.

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/ 11

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 the values from the user.
a. Sort an array in ascending order.
Solution:
#include<stdio.h>
int main()
{
int i, j, a, num[50];

printf("Enter the numbers: \n");


for(i=0; i<10; ++i)
scanf("%d", & num[i]);

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;

b. Display the sum of all odd values stored in an array.

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];
}

printf("Summation of all odd values stored in the array : %d",sum);

return 0;
}

c. Display the number of even values stored in an array.

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;
}
Problem 2: Write a program to evaluate the net salary of an
employee given the following constraints:
Solution:
#include<stdio.h>
int main()
{
float salary, da, hra, ta, others, pf, it, net;
printf("Basic Salary = ");
scanf("%f", &salary);
printf("TA = ");
scanf("%f", &ta);
printf("HRA = ");
scanf("%f", &hra);
printf("Others = ");
scanf("%f", &others);
da = (12.0*salary)/100;
pf = (14.0*salary)/100;
it = (15.0*salary)/100;

net = salary+da+hra+ta+ others -( pf + it);

printf("The Net Salary of the employee is %.0f$", net);

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("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:

Problem 5: Write a program that accepts the following


numbers in an array and reverses the array.

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;
}

Problem 6: Write a C program to find the minimum and the


maximum value in an array (Use Function)

Solution:
#include<stdio.h>

int max(int a[], int n)


{
int max = 0;
for(int i=0; i<n; i++)
{
if(max<a[i])
max = a[i];
}
return max;
}

int min(int a[], int n)


{
int min = 1000000;
for(int i=0; i<n; i++)
{
if(min>a[i])
min = a[i];
}
return min;
}

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]);
}

printf("Maximum = %d\n", max(a, n));


printf("Minimum = %d\n", min(a, n));

return 0;
}

Problem 7: Write a C program to calculate the factorial of an


integer using Recursion.

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;
}

Problem 8: Write a C Program to Find the Sum of Natural


Numbers using Recursion.

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

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

Solution:

You might also like