Cse Assignment
Cse Assignment
Submitted by Submitted to
Utsha Das
Name : Md. Abdur Rahman
Lecturer
Roll 2111025
Department of Computer Science &
Engineering
Series 21
Rajshahi University of Engineering &
Technology.
Date of Submission: 18-02-25
Problem no : 01
Problem Name: Writing a program that inputs two integer number and show the
summation, difference, multiplication and division of that two numbers.
Source Code
Here is a simple C program that implements the required functionality:
#include <stdio.h>
int main() {
int num1, num2;
int sum, difference, product;
float division; // Division result is stored as a float for decimal precision
// Prompt the user to input two integers
printf("Enter the first integer: ");
scanf("%d", &num1);
printf("Enter the second integer: ");
scanf("%d", &num2);
// Perform arithmetic
operations sum = num1 +
num2; difference = num1 -
num2; product = num1 *
num2;
// Display results
printf("Summation: %d\n", sum);
printf("Difference: %d\n", difference);
printf("Multiplication: %d\n", product);
// Check for division by zero
if (num2 != 0) {
division = (float)num1 / num2; // Casting to float for precise division
printf("Division: %.2f\n", division);
} else {
printf("Division: undefined (cannot divide by zero)\n");
}
return 0;
}
Problem no : 02
Problem Name: Writing a program that read temperature in Celsius
and display in Fahrenheit.
Source Code
#include <stdio.h>
int main() {
float celsius, fahrenheit;
// Prompt the user to enter the temperature in Celsius
printf("Enter the temperature in Celsius: ");
scanf("%f", &celsius);
// Calculate Fahrenheit
fahrenheit = (celsius * 9 / 5) + 32;
// Display the result
printf("Temperature in Fahrenheit: %.2f\n", fahrenheit);
return 0;
}
Problem no : 03
Problem Name: Writing a program that read radius of a circle and display its
Area.
Source Code
#include <stdio.h>
#define PI 3.14159 // Defining the constant value of π
int main() {
float radius, area;
// Prompt the user to enter the radius
printf("Enter the radius of the circle: ");
scanf("%f", &radius);
// Calculate the area
area = PI * radius * radius;
// Display the area
printf("The area of the circle is: %.2f\n", area);
return 0;
}
Problem no : 04
Problem name : Write a program that check odd or even using modular
operator and bitwise operator.
Source Code
#include <stdio.h>
void checkOddEvenModular(int number)
{ if (number % 2 == 0) {
printf("%d is Even (using modular operator)\n", number);
} else {
printf("%d is Odd (using modular operator)\n", number);
}
}
void checkOddEvenBitwise(int number)
{ if (number & 1) {
printf("%d is Odd (using bitwise operator)\n", number);
} else {
printf("%d is Even (using bitwise operator)\n", number);
}
}
int main()
{ int number;
printf("Enter an integer: ");
scanf("%d", &number);
checkOddEvenModular(number);
checkOddEvenBitwise(number);
return 0;
}
Problem no : 05
Problem name : Write a program that read any angle and display cos, tan , sec and
cosec.
Source Code
The following C program reads an angle in degrees and calculates its cosine, tangent,
secant, and cosecant:
#include <stdio.h>
#include <math.h>
int main() {
Problem no : 06
Problem name : Write a program that generates random number
between 1 to 6.
Source Code
#include<stdio.h>
#include<stdlib.h>
int main()
{
int i,a;
printf("enter number = ");
scanf("%d",&a);
for(i=0;i<a;i++)
printf("\n%d ", 1+ rand()%6);
return 0;
}
Problem no : 07
Problem name : Write a program that read any year and display leap
Source Code:
#include <stdio.h>
int main()
int year;
scanf("%d", &year);
else
}
return 0;}
Problem no : 08
Problem name : Write a program that read three numbers (a,b,c) and determine
the roots of the quadratic equation: ax2 + bx + c=0.
Source Code
#include <stdio.h>
#include <math.h>
int main()
{
if (a == 0) {
return 0;
discriminant = b * b - 4 * a * c;
if (discriminant > 0) {
printf("The equation has two real and distinct roots: %.2f and %.2f\n", root1,
root2);
}
else if (discriminant == 0)
{ root1 = -b / (2 * a);
else {
printf("The equation has two complex roots: %.2f + %.2fi and %.2f -
%.2fi\n", realPart, imaginaryPart, realPart, imaginaryPart);
return 0;
Problem no : 09
Problem name : Write a program that read numbers and display median using
conditional operator.
Source Code
#include <stdio.h>
int main()
{
int a, b, c, median;
printf("Enter three numbers: ");
median = (a > b) ? ((a < c) ? a : (b > c ? b : c)) : ((b < c) ? b : (a > c ? a : c));
return 0;
Problem no : 10
Problem name : Write a program that read a mark and display its grade using
switch statement.
Source Code
#include <stdio.h>
int main()
{ int mark;
char grade;
scanf("%d", &mark);
case 10:
case 9:
grade = 'A';
break;
case 8:
grade = 'B';
break;
case 7:
grade = 'C';
break;
case 6:
grade = 'D';
break;
default:
grade = 'F';
break;
return 0;
Problem no : 11
Problem name : Write a program that read any number and display
Source Code
#include <stdio.h>
int main()
{ int num;
scanf("%d", &num);
switch(num)
{ case 1:
break;
case 2:
break;
case 3:
break;
case 4:
break;
case 5:
break;
case 6:
break;
case 7:
break;
case 8:
break;
case 9:
break;
case 10:
break;
default:
return 0;
Problem no :12
Problem name : Write a program that will print the prime numbers in a given range.
Source Code
#include <stdio.h>
int isPrime(int num) {
{ if (num % i == 0) {
return 0;
return 1;
int main() {
scanf("%d", &lower);
scanf("%d", &upper);
if (isPrime(num))
printf("\n");
return 0; }
Problem no :13
Problem name : Write a program that will check whether a given number is
palindrome or not.
Source Code
#include <stdio.h>
int reversedNum = 0;
int remainder;
while (num != 0) {
num /= 10;
int main()
{ int
number;
scanf("%d", &number);
if (isPalindrome(number)) {
printf("%d is a palindrome.\n", number);
} else {
return 0; }
Problem no :14
Source Code
#include <stdio.h>
void printStarPattern(int n)
{ printf("* ");
printf("\n");
void printNumberPattern(int n)
printf("\n");
}
int main() {
int choice, n;
scanf("%d", &choice);
scanf("%d", &n);
if (choice == 1)
{ printf("Star Pattern:\
n"); printStarPattern(n);
} else if (choice == 2)
{ printf("Number Pattern:\
n"); printNumberPattern(n);
} else {
printf("Invalid choice.\n");
return 0;
}
Problem no : 15
Source Code
#include <stdio.h>
#include <math.h>
{ int originalNum =
int digits = 0;
while (originalNum != 0) {
originalNum /= 10;
digits++;
originalNum = num;
while (num != 0) {
int main() {
int number;
scanf("%d", &number);
if (isArmstrong(number)) {
} else {
return 0;
Problem no : 16
Problem name : Write a program that will print the first n number sequence of
Fibonacci series.
Source Code
#include <stdio.h>
void printFibonacci(int n) {
if (i <= 1)
{ next = i;
} else {
next = first + second;
first = second;
second = next;
printf("\n");
int main()
{ int n;
scanf("%d", &n);
if (n <= 0) {
} else {
printFibonacci(n);
return 0;
Problem No : 17
Problem Name: Writing a program that deletes any number from an array.
Source code:
#include <stdio.h>
if (arr[i] == num)
{ pos = i;
break;
if (pos == -1) {
return;
(*size)--;
}
void displayArray(int arr[], int size)
printf("\n");
int main() {
scanf("%d", &size);
scanf("%d", &arr[i]);
scanf("%d", &num);
// Perform deletion
printf("Updated array:\n");
displayArray(arr, size);
return 0;
Problem No : 18
Problem Name: Write a program that read and sort an array using bubble sort in
ascending or descending order.
Source code:
#include <stdio.h>
void bubbleSort(int arr[], int n, int order)
{ int i, j, temp;
int swapped;
int main() {
int n, order, i;
int arr[n];
return 0;
}
Problem No : 19
Problem Name: Write a program that reads a decimal number and display
equivalent binary number.
Source code:
#include <stdio.h>
void convertToBinary(int decimal) {
int binary[32]; // Array to store binary digits
int index = 0; // Index for the binary array
// Conversion process
while (decimal > 0) {
binary[index] = decimal % 2; // Store remainder (binary digit)
decimal /= 2; // Update decimal to the quotient
index++;
}
int main()
{ int
decimal;
return 0;
}
Problem No :20
Problem name : Write a program that read a line of text from a file and convert it
upper to lower and lower to upper and calculate the frequency of each character.
Source Code
#include <stdio.h>
#include <ctype.h>
#include <string.h>
{ char line[MAX_SIZE];
char c = line[i];
if (isupper(c)) {
c = tolower(c);
} else if (islower(c)) {
c = toupper(c);
fputc(c, output_file);
freq[(unsigned char)c]++;
}
fprintf(output_file, "\nCharacter frequencies:\n");
if (freq[i] > 0) {
int main() {
if (input_file == NULL) {
return 1;
if (output_file == NULL) {
return 1;
toggle_case_and_frequency(input_file, output_file);
fclose(input_file);
fclose(output_file);
return 0;
}
Problem no 22
Problem name : Write a program that read all numbers in a file and write another
file in ascending or descending order.
Source Code
#include <stdio.h>
#include <stdlib.h>
+;
numbers[i] = numbers[j];
numbers[j] = temp;
int main() {
if (input_file == NULL) {
return 1;
if (output_file == NULL) {
return 1;
fclose(input_file);
fclose(output_file);
return 0;
}
Problem no 23
Problem name : Write a program that gets the input of structure from a file and
output display in another file.
Source Code
#include <stdio.h>
#include <string.h>
struct Student
{ char name[50];
int age;
float grade;
};
int main() {
if (input_file == NULL) {
printf("Error opening input file\n");
return 1;
if (output_file == NULL) {
return 1;
process_student_data(input_file, output_file);
fclose(input_file);
fclose(output_file);
return 0;