Cse Assignment
Cse Assignment
Assignment – 01
Total Marks: 100
Question 1: Given the value of coefficients a, b and c, write a C program to find the value of x.
The equation is given by: 𝑎𝑥 + 𝑏𝑥 + 𝑐 = 0
Question 2: If d, w, and l are given, find out the area of the green portion.
Question 4:
Calculate the sum of the following series, where x and n are given by the user. n is the number of
terms in the series.
Question 5: What is a function in C? Solve a self-chosen problem with function and without function
and compare them. Discuss the benefits of using functions.
Question 6:
Point out the error(s), if any, in the following programs and provide solutions as well:
a.
# include<stdio.h>
int addmult(int, int)
int main()
{
int i = 3, j = 4, k, l;
k = addmult(i, j);
l = addmult(i, j);
printf("%d %d\n", k, l);
return 0;
}
b.
# include <stdio.h>
int main( )
{
int a = 15.5;
char ch = 'C';
print(a, ch);
return 0;
}
printf(a, ch)
{
print("%f %c\n", a, ch);
}
c.
# include <stdio.h>
void message( );
int main( )
{
message(message( ));
return 0;
}
void message( )
{
printf ("It's a small world after all...\n");
}
d.
e.
Question 7: Write a C program to find out the Bitwise OR, Bitwise AND & Bitwise XOR value of
the given X, Y input. X and Y will be given as decimal values. Your output also should be in
Decimal. Constraint, 0 ≤ 𝑋, 𝑌 < 63
Hint:
Input: X=3, Y=5
Bitwise OR:
3 = 011
5 = 101
7 = 111
Bitwise AND:
3 = 011
5 = 101
1 = 001
Bitwise XOR:
3 = 011
5 = 101
6 = 110
Output: 7, 1, 6
Question 8: Write a C Program to print the following according to their GPA. Also, print the amount
of semester fees they have to pay.
CGPA Scholarship
4.00 100%
3.75 75%
3.50 50%
3.30 25%
< 3.30 0%
Sample Input:
Enter your CGPA: 3.5
Enter Semester Fee: 100,000
Sample Output:
You got 50% scholarship on your CGPA.
Your payable amount is 50,000 BDT.
Question 9: Take a year as user input. Write a function checkLeapYear(int year) to determine
whether the year is a leap year.
Question 10: What is an array? How do you declare and initialize an array in C? How many types of
arrays are there?
Question 11: Suppose you have given n size array. Each contains the height of a student in your
class. Use another array to store their names sequentially. Now write a program that finds the names
of the tallest students (assuming there could be more than one tallest student).
Question 12: Write a C program to read the number of minutes talked on the phone and to calculate
the total
bill according to the given conditions:
For the first 5 minutes Tk. 0.45/min,
For the next 30 minutes Tk. 0.60/min,
For the next 1 hour Tk. 0.85/min,
After that, Tk. 1.00/min.
An additional VAT of 18% is added to the bill.
For example, for 45 minutes talking time:
Total bill = 1.18*(Tk. 0.45/min*5min + Tk. 0.6/min*30min + 0.85/min*10min)
= Tk. 1.18*(0.45*5+0.6*30+0.85*10)
= Tk. 33.92
int main( )
{
int num[26], temp;
num[0] = 100;
num[25] = 200;
temp = num[25];
num[25] = num[0];
num[0] = temp;
printf("%d %d\n", num[0], num[25]);
return 0;
}
b.
# include<stdio.h>
int main( )
{
int array[10], i;
for(i = 0; i <10; i++)
{
array[i] = 'A' + i;
printf("%d %c\n", array[i], array[i]);
}
return 0;
}
Question 14: Point out the errors in the following code segment if any:
a.
#include<stdio.h>
int main( )
{
int a[10], i;
for (i = 1; i <= 10; i++)
{
scanf("%f", a[i]);
printf("%f\n", a[i]);
}
return 0;
}
b.
# include<stdio.h>
int main( )
{
int size;
scanf ("%d", &size);
int arr[size];
return 0;
}
c.
# include<stdio.h>
int main( )
{
int i, a = 2, b = 3;
int arr[2 + 3];
for (i = 0; i < a + b; i++)
{
scanf("%d", &arr[i]);
printf("%d\n", arr[i]);
}
return 0;
}
Question 15: Write a C program to find the summation of n size array excluding second largest
element in a given array.
Question 16: Write a function sumEven(int arr[], int length) which returns the summation of all the
even elements of the array. And write another function sumOdd(int arr[], int length) which returns
the summation of all the odds elements of the array. Print the difference between the sum of even and
the sum of odd numbers.
Question 17:
(a) What are Strings in C? Why is a ‘\0’ necessary at the end of the string?
(b) What are preprocessor directives? Why it is necessary to include them at the beginning of
any C code file?
Question 18: Write a C program that counts the total number of letters, numbers or special
character/symbols in a string.
#include <stdio.h>
void main(){
int i=14>>2, j=11<<2;
printf("i=%d, j=%d\n",i,j);
if(i > 2){
i=i|16;
printf("i=%d, j=%d\n",i,j);
}
int k=0;
k=j|16;
printf("i=%d, k=%d\n",i,k);
if(j%2){
j=j&16;
printf("i=%d, j=%d\n",i,j);
}
if(i>j)
printf("i=%d, j=%d\n",++i,--j);
else
printf("i=%d, j=%d\n",--i,++j);
printf("Done");
}