Coding Practice
Showing posts with label Assignment Solution. Show all posts
Showing posts with label Assignment Solution. Show all posts

Take 5 numbers in an array and find all pairs of prime numbers from that array

Find all pair of prime numbers from a array

Sample Input Sample Output
2, 3, 4, 5, 6 2, 3
2, 5
3, 5
Sample Output
Enter 5 element: 2 3 4 5 6
2,3
2,5
3,5
Source Code
#include<stdio.h>

void main()
{
    int i, j, k = 0, isPrime, size = 5, arr[5], primeNum[5];

    printf("Enter 5 element: ");
    for(i = 0; i < size; i++)
    {
        scanf("%d", &arr[i]);
    }

    for(i = 0; i < size; i++)
    {
        if(arr[i] == 2)
        {
            primeNum[k++] = arr[i];
        }
        else
        {
            isPrime = 1;
            for(j = 2; j < arr[i]; j++)
            {
                if(arr[i] % j == 0)
                {
                    isPrime = 0;
                    break;
                }
            }
            if(isPrime == 1)
            {
                primeNum[k++] = arr[i];
            }
        }
    }
    if(k < 2)
    {
        printf("\nPair not possible!");
    }
    for(i = 0; i < ((k * (k+1))/2); i++)
    {
        for(j = i+1; j < k; j++)
        {
            printf("%d,%d\n", primeNum[i], primeNum[j]);
        }
    }
    printf("\n");

}
Sample Output
Enter 5 element: 2 3 5 7 11
2,3
2,5
2,7
2,11
3,5
3,7
3,11
5,7
5,11
7,11

Lab Task: MID TERM [20 Marks] | Assignment - June 2021

1. [5] Write a C program to solve the Drake equation N = R*fp*ne*fl*fi*fc*L. Where R, ne and L must be discrete value

Sample Input

    Enter R, F(p), n(e), f(l), f(i), f(c), L: 5 0.25 20 0.2 0.15 0.11 150

Sample Output

    The number of communicative civilizations within the Milky Way today: 12.375

2. [7] Write a C Code to calculate D = 𝒃^𝟐 − 𝟒𝐚𝐜 and show the result according to following conditions:

a. D>0 then Calculate X1, X2. Where 𝒙𝟏 = (−𝒃+√𝒃^𝟐−𝟒𝒂𝒄)/𝟐𝒂 and 𝒙𝟐 = (−𝒃−√𝒃^𝟐−𝟒𝒂𝒄)/𝟐𝒂

        b. D =0 then calculate X. Where 𝐱 = 𝒃^𝟐/𝟐𝒂

        c. D<0 then print “No Solution”.

Sample Input

        Enter a, b & c: 5 6 1

Sample Output

    X1: -0.2

    X2: -1

3. [8] Write a C Code to find total marks from given input: Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam and find the grade using the following method:

  1. If Total mark >=80 then A+
  2. If Total mark >=70 then A
  3. If Total mark >=60 then A
  4. If Total mark >=50 then B
  5. Else Grade = F

Sample Input

Enter Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam: 2.5 7.5 3.5 7 21.5 33

Sample Output

Total Mark: 75 & Grade: A

Complex Variables and Quadratic Equations

 1.

(a) Find the modulus, argument and express following complex number in Euler form:

            (i) 𝒛 = 𝟏 − √𝟑𝒊

            (ii) z = ((1+i)/(1−i ))7

(b) Find poles and order of the function 𝑓(𝑧) = 1/(z3-5z2+8z-4)

(c) Sketch and describe the region of the following inequalities:

             (i) |𝒛 − 𝟏 − 𝒊| ≤ 𝟐

             (ii) 𝟐 < |𝒛 − 𝟑| < 4

Rubrics for Question-1:

 

Marks

Level

Descriptions

5

Excellent

Gives a complete response with a clear, coherent and suitable explanation including strong arguments; identifies all the important elements of the problem with proper examples

4

Very Good

Gives a complete response including strong arguments; identifies all the important elements of the problem without examples.

3

Good

Completes the problem but the explanation may be muddled; argumentation may be incomplete; may not include examples.

2

Average

Completes the problem with some minor computational errors, may include wrong examples.

1

Poor

Description is not understandable; may make major computational errors, include wrong examples.

2.

(a) Find the center and radius of the circle |𝑧 + 1 − 2𝑖| = √π

(b) By using De Moivre’s theorem, compute all roots of the complex function 𝒛𝟏𝟐 = (−√𝟑 − 𝒊).

(c) Prove that |𝑧 + 4𝑖| + |𝑧 − 4𝑖| = 10 represents an ellipse

Rubrics for Question-2:

 

Marks

Level

Descriptions

5

Excellent

Gives clear explanations with appropriate diagrams (if necessary); identifies all the important elements of the problem

4

Very Good

Gives clear explanations without appropriate diagrams; understands the underlying mathematical ideas shortly

3

Good

Completes the problem but the explanation may be muddled; diagram may be inappropriate or unclear, understands the underlying mathematical ideas shortly

2

Average

Completes the problem with some minor computational errors and mathematical ideas is not clearly stated.

1

Poor

Unable to indicate which information is appropriate to the problem.

3.

(a) Verify that the Cauchy-Riemann equations are satisfied for the function 𝒇(𝒛) = 𝒆^𝒙+𝒊y

(b) An unbiased coin is tossed 20 times. Find the probability of

             (i) Just 5 heads

             (ii) At least one head or at best two head

(c) Find residues of the function 𝑓(𝑧) = (z + 22)/(z - 3)^3

Rubrics for Question-3:

Marks

Level

Descriptions

5

Excellent

A high level of mathematical thinking which includes exceptional skills and appropriate mathematical tools and techniques in the resolution of problems in task(s).

4

Very Good

Apply excepted methods and mathematical tools and techniques in the resolution of problems in task(s) with minor computational errors.

3

Good

Illustrates the essential elements but some ideas are missing, a limited variety of tools and techniques used to resolve the situation presented in the task(s).

2

Average

Demonstrates the essential elements with limited variety of

tools and techniques. Lack of mathematical concepts leads to wrong outputs.

1

Poor

Contains    irrelevant    responses    that    have    no    valid relationship to the task(s). Lack of mathematical concepts and unsuccessful attempt to justify results.

4.

(a) By using Cauchy’s integral formula, evaluate ∮ 𝒛^𝟐𝒅𝒛/(𝒛 − 𝒛^2)(z + i) , where C is the circle |𝒛| = 𝟐 described in the positive sense.

(b) Evaluate the contour integral ∫𝟐𝝅0 𝟏d𝜽(𝟓 − 𝟒𝐜𝐨𝐬 𝜽).

(c) Determine whether the function 𝑢 = 𝑒^𝑥 (sin 𝑥 + cos 𝑦) is harmonic or not.

Rubrics for Question-4: 

Marks

Level

Descriptions

5

Excellent

A high level of mathematical thinking which includes exceptional skills and appropriate mathematical tools and techniques in the resolution of problems in task(s).

4

Very Good

Apply excepted methods and mathematical tools and techniques in the resolution of problems in task(s) with minor computational errors.

3

Good

Illustrates the essential elements but some ideas are missing, a limited variety of tools and techniques used to resolve the situation presented in the task(s).

2

Average

Demonstrates the essential elements with limited variety of

tools and techniques. Lack of mathematical concepts leads to wrong outputs.

1

Poor

Contains    irrelevant    responses    that    have    no    valid

relationship to the task(s). Lack of mathematical concepts and unsuccessful attempt to justify results.


Write a C Program to check if a Substring is present in the given String

Check String to Substring

3. Write a C Program to check if a Substring is present in the given String.

Sample Input Sample Output
String: Bangladesh
Substring: lad
Match found
String: Paragraph
Substring: rag
Match found
String: America
Substring: rice
Not Match found

Sample Output
String: Bangladesh
Substring: lad

Match found


Process returned 0 (0x0)   execution time : 11.043 s
Press any key to continue.
Source Code
#include<stdio.h>
#include<string.h>
 
int main()
{
    int i, j, temp, count = 0, count2 = 0;
    char str[50], subString[20];
 
    printf("String: ");
    gets(str);
 
    printf("Substring: ");
    gets(subString);
 
    while (str[count] != '\0')
    {
        count++;
    }
    while (subString[count2] != '\0')
    {
        count2++;
    }
 
    for (i = 0; i <= count - count2; i++)
    {
        for (j = i; j < i + count2; j++)
        {
            temp = 1;
            if (str[j] != subString[j - i])
            {
                temp = 0;
                break;
            }
        }
        if (temp == 1)
            break;
    }
    if (temp == 1)
    {
        printf("\nMatch found\n\n");
    }
    else
    {
        printf("\nNo match found\n\n");
    }
    return 0;
}
Sample Output
String: America
Substring: rice

No match found


Process returned 0 (0x0)   execution time : 12.346 s
Press any key to continue.

Write a C Program to check the minimum number of turns required

Check Minimum Number of Turns Required

1. You’re given an array of n integers. You want to modify the array so that it is increasing, i.e., each component is at least as large as the previous component. On every turn, you may increase the worth of any component by one. What's the minimum number of turns required?

Input: The 1st input line contains number n: the size (limit) of the array. Then, the 2nd line contains n integers (the contents of the array).

Output: Print the minimum number of turns.

Sample Input Sample Output
5
3 2 5 1 7
5 turns
4
1 2 2 6
0 turns

Explanation: Total input numbers = 5
Turns = 3 - 2 = 1 turns
Turns = 2 - 5 = 0+1 turns
Turns = 5 - 1 = 4+0+1 turns
Turns = 1 - 7 = 0+4+0+1 turns
So, Total Turns = 5

Sample Output
5
3 2 5 1 7
5 turns


Process returned 0 (0x0)   execution time : 10.196 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    int i, size, turn = 0;
    scanf("%d", &size);
    int numbers[size];
 
    for(i = 0; i < size; i++)
    {
        scanf("%d", &numbers[i]);
    }
 
    for(i = 1; i < size; i++)
    {
        if(numbers[i-1] > numbers[i])
        {
            turn += (numbers[i-1] - numbers[i]);
            //Or, you can also write this line. Both are same.
            //turn = turn + (numbers[i-1] - numbers[i]);
        }
    }
    printf("%d turns\n\n", turn);
 
    return 0;
}
Sample Output
4
1 2 2 6
0 turns


Process returned 0 (0x0)   execution time : 4.518 s
Press any key to continue.

Write a C program to generate the following pattern

Generate Pattern

4. Write a C program to generate the following pattern

Sample Output
Enter number of rows
9

9       9
 8     8
  7   7
   6 6
    5
   4 4
  3   3
 2     2
1       1

Process returned 0 (0x0)   execution time : 1.879 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    int i, j, k, rows;
 
    printf("Enter number of rows\n");
    scanf("%d", &rows);
    printf("\n");
 
    for(i = rows, k = 1; i >= 1; i--, k++)
    {
        for(j = rows; j >= 1; j--)
        {
            if(i == j || j == k)
            {
                printf("%d", i);
            }
            else
            {
                printf(" ");
            }
        }
        printf("\n");
    }
    return 0;
}
Sample Output
Enter number of rows
5

5   5
 4 4
  3
 2 2
1   1

Process returned 0 (0x0)   execution time : 1.845 s
Press any key to continue.

Write appropriate code for the following questions | Problem Solution in C

1. Check the grade of the students based on marks by C language

2. Write a C program using three different User Defined Function (UDF) to compute- 1. Volume or 2. Surface Area of a sphere whose radius is given by the user as the input.

3. Create a program that reads some words and print it all right justified

4. Create a robust encryption system for generate password

5. We have RUNU and JHUNU with us from a distant village of Bangladesh who came to this Dhaka city for the first time. They have a special bag of money which gives them money every morning when they wake up from sleep. Somehow they figure out how much money each day they will be able to get from the magic bag in the next N days

6. I like odd numbers a lot! I know it's your exam but you have to do me a little favor! I will give you a random integer number and you have to make it a Strongly Odd Number and check if it is a prime number or not. A strongly Odd Number is a number where every digit is an odd number. And Prime Number is a number that is divisible only by itself and 1. Write necessary C code for doing the job

7. Write a C Program to check minimum number of turns required

8. You're given all numbers between 1, 2, 3, 4 … n except one. Your task is to find the missing number

9. Write a C Program to check if a Substring is present in the given String

10. Write a C program to generate the following pattern

11. Find how many numbers in a array are greater than the average and then reverse the arrays numbers

12. 12. Write a C Program to check twin string or not

13. Write a C program to split a number and then add all factorial digit

14. Write a C program to convert IP address to 32-bit binary format

15. Write a c program to reverse an array before target number and after target number. i.e. if the array is 1 2 3 4 5 6 7 and the target number is 4 then it will print 3 2 1 4 7 6 5

16. Write a program in C to print all alphabets using pointer

17. Write a program that construct an Even parity Hamming code

18. Write a program that choose Even parity / Odd parity according to user choose. And accordingly performs Even parity / Odd parity process

19. Write a C program to solve the Drake equation N = R*fp*ne*fl*fi*fc*L. Where R, ne and L must be discrete value

20. Write a C Code to calculate D = 𝒃^𝟐 − 𝟒𝐚𝐜 and show the result according to following conditions:

21. Write a C Code to find total marks from given input: Attendance, Class test, Quiz test, Assignment, Midterm and Final Exam and find the grade using the following method...

22. Take 5 numbers in an array and find all pairs of prime numbers from that array

Change Theme
X