Coding Practice

I like odd numbers a lot! I know it's your exam but you have to do me a little favor! I will give...

Write necessary C code for doing the job

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.

Sample Input:    Sample Output:
6594                    59. Prime
9805789              9579. Not Prime
Sample Output
6594
59. Prime
Process returned 0 (0x0)   execution time : 3.859 s
Press any key to continue.
                    
Source Code
#include<stdio.h>

int main()
{
    int i, k = 0, arr[20], num, new_num = 0, digit, isPrime = 1;

    scanf("%d", &num);

    while(num > 0)
    {
        digit = num % 10;
        num = num / 10;

        if(digit % 2 != 0)
        {
            arr[k] = digit;
            k++;
        }
    }

    for(i = k - 1; i >= 0; i--)
    {
        new_num = new_num*10 + arr[i];
    }
    for(i = 2; i < new_num; i++)
    {
        if(new_num % i == 0)
        {
            isPrime = 0;
        }
    }
    if(isPrime == 1)
    {
        printf("%d. Prime", new_num);
    }
    else
    {
        printf("%d. Not Prime", new_num);
    }
    return 0;
}
Sample Output
9805789
9579. Not Prime
Process returned 0 (0x0)   execution time : 2.070 s
Press any key to continue.
                

We have RUNU and JHUNU with us from a distant village of Bangladesh...

Write a full C program for each of the following problems

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.

So, now they want your help to decide where to eat in this Dhaka city. Well for your help they also provided the list below:

  • Roadside Food if the amount is 100 or less
  • Fast Food if the amount is 250 or above but less than 350
  • Kacchi if the amount is 350 or above
  • Otherwise in BFC

Input: An integer N (No. of days). Followed by an integer in the next N line defining the amount of each of the N days.

Output: "Roadside Food", "Fast Food", "Kacchi" or "BFC" depending on the amount of each day. Table:

Sample Input:    Sample Output:

3

999                        Kacchi

9                            Roadside Food

282                        Fast Food

Sample Output
3
999
9
282
Kacchi
Roadside Food
Fast Food
 
Process returned 0 (0x0)   execution time : 19.498 s
Press any key to continue.
Source Code
#include<stdio.h>
#define MAX 100

int main()
{
    int i, NDays, amount[MAX];

    scanf("%d", &NDays);

    for(i = 0; i < NDays; i++)
    {
        scanf("%d", &amount[i]);
    }
    for(i = 0; i < NDays; i++)
    {
        if(amount[i] <= 100)
        {
            printf("Roadside Food\n");
        }
        else if(amount[i] >= 250 && amount[i] <= 350)
        {
            printf("Fast Food\n");
        }
        else if(amount[i] >= 350)
        {
            printf("Kacchi\n");
        }
        else
            {
                printf("BFC\n");
            }
    }
}
Sample Output
3
999
9
282
Kacchi
Roadside Food
Fast Food
 
Process returned 0 (0x0)   execution time : 19.498 s
Press any key to continue.

Create a robust encryption system for generate password

Create a robust encryption system for generate password

Cyber Security is a key issue to protect our daily documents and applications stored and submitted in various platforms. Having a sturdy coding system to our generated positive identification is incredibly essential during this perspective. Your task is to make a pleasant and swish encrypted positive identification generator. Follow the directions fastidiously to make the positive identification generator. [5 Marks]

a. Take a 5 digit integer number from user. Use a function named Input_Number() to require the amount from user. If the amount isn't exactly of 5 digits, provides a warning message to user and exit/abort the program.

b. In case of a 5 digit number, pass each digit of the amount to a user defined function named character_extractor() which might return a character like a digit. Character related to each digit will be within the following sequence.


c
. Finally, pass your extracted characters during a user defined function named password_generator() to generate a 5 length password.

d. Show the password on screen.

Sample Output
9876543
Wrong input
Process returned 0 (0x0)   execution time : 14.036 s
Press any key to continue.
Source Code
#include <stdio.h>
 
int Input_Number()
{
    int number, i = 0;
 
    scanf("%d", &number);
    if(number < 9999 || number > 99999)
    {
        return 0;
    }
    else
    {
        return number;
    }
}
 
int character_extractor(int n)
{
    char i = 4, password[10], lastDigit;
 
    while(n >= 1)
    {
        lastDigit = n%10;
 
        if(lastDigit == 1)
        {
            password[i] = '#';
        }
        else if(lastDigit == 2)
        {
            password[i] = 'a';
        }
        else if(lastDigit == 3)
        {
            password[i] = 't';
        }
        else if(lastDigit == 4)
        {
            password[i] = 'j';
        }
        else if(lastDigit == 5)
        {
            password[i] = '9';
        }
        else if(lastDigit == 6)
        {
            password[i] = 'E';
        }
        else if(lastDigit == 7)
        {
            password[i] = '@';
        }
        else if(lastDigit == 8)
        {
            password[i] = '2';
        }
        else if(lastDigit == 9)
        {
            password[i] = 'F';
        }
        else if(lastDigit == 0)
        {
            password[i] = '?';
        }
        n = n/10;
        i--;
    }
    password[5] = '\0';
    printf("%s", password);
}
 
int main()
{
    int num;
    num = Input_Number();
    if(num == 0)
    {
        printf("Wrong input");
    }
    else
    {
        character_extractor(num);
    }
    return 0;
}
Sample Output-1
12345
#atj9
Process returned 0 (0x0)   execution time : 1.253 s
Press any key to continue.
                
Sample Output-2
91778
F#@@2
Process returned 0 (0x0)   execution time : 0.954 s
Press any key to continue.
                

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

Reads some words and print it all right justified

Suppose you have some words and you want to right justify them, that is, align them to the right. Create a program that reads some words and print it alright justified, within the same order as they seem within the input. [5 Marks]

Input:
The first line of the input will contain an integer N (1 ≤ N ≤ 50) indicating the amount of following words. Each word consists of up to 50 letters (‘A’-‘Z’ or 'a'-'z') and will contain a minimum of one letter.

Output:
Print the words padded on the left with space characters in order that they're all an equivalent length because the longest word found therein text

Sample Output
3
Sample Input:
Bod
Tommy
Jim

Sample Output:
  Bod
Tommy
  Jim

Process returned 0 (0x0)   execution time : 14.700 s
Press any key to continue.
Source Code
#include <stdio.h>
 
struct name{
    char name[55];
 
}list[100];
 
int main()
{
    int i, N, num = 5, maxLength = 0, j;
 
    scanf("%d", &N);
 
    printf("Sample Input:\n");
    for(i = 0; i < N; i++)
    {
        scanf("%s", list[i].name);
 
        for(j = 0; list[i].name[j] != '\0'; j++);
 
        if(j > maxLength)
        {
            maxLength = j;
        }
    }
 
    printf("\nSample Output:\n");
    for(i = 0; i < N; i++)
    {
        printf("%*s\n", maxLength, list[i].name);
    }
}
Sample Output
4
Sample Input:
LONGEST
a
LONGER
SHORT
 
Sample Output:
LONGEST
      a
 LONGER
  SHORT
 
Process returned 0 (0x0)   execution time : 28.554 s
Press any key to continue.

Write a C program to check whether a character is uppercase or lowercase alphabet

Check a character is uppercase or lowercase alphabet
Sample Output
Enter a character: p

p is lowercase alphabet.

Process returned 0 (0x0)   execution time : 1.219 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    char ch;

    printf("Enter a character: ");
    scanf("%c", &ch);

    if(ch >= 'a' && ch <= 'z')
    {
        printf("\n%c is lowercase alphabet.\n", ch);
    }
    else if(ch >= 'A' && ch <= 'Z')
    {
        printf("\n%c is uppercase alphabet.\n", ch);
    }
    else
    {
        printf("\nInvalid Alphabet!\n");
    }
    return 0;
}
Sample Output
Enter a character: M

M is uppercase alphabet.

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

Write a C program to input any character and check whether it is alphabet, digit or special characters

Check alphabet, digit or special characters
Sample Output
Enter here: @

@ is special character.

Process returned 25 (0x19)   execution time : 15.245 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    char ch;

    printf("Enter here: ");
    scanf("%c", &ch);

    if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
    {
        printf("\n%c is alphabet.\n", ch);
    }
    else if(ch >= '0' && ch <= '9')
    {
        printf("\n%c is digit.\n", ch);
    }
    else
    {
        printf("\n%c is special character.\n", ch);
    }
    return 0;
}
Sample Output
Enter here: a

a is alphabet.

Process returned 16 (0x10)   execution time : 0.922 s
Press any key to continue.

Write a C program to input any alphabet and check whether it is vowel or consonant

Check vowel or consonant
Sample Output
Enter a alphabet: A

A is vowel.

Process returned 0 (0x0)   execution time : 9.627 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    char ch;

    printf("Enter a alphabet: ");
    scanf("%c", &ch);
 
    if(ch == 'a' || ch == 'e' || ch == 'i' ||ch == 'o' || ch == 'u' ||
        ch == 'A' || ch == 'E' || ch == 'I' ||ch == 'O' || ch == 'U')
    {
        printf("\n%c is vowel.\n", ch);
    }
    else
    {
        printf("\n%c is consonant.\n", ch);
    }
    return 0;
}
Sample Output
Enter a alphabet: y

y is consonant.

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

Write a C program to check whether a character is alphabet or not

Check a character is alphabet or not
Sample Output
Enter here: P

P is an alphabet.

Process returned 0 (0x0)   execution time : 1.397 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    char ch;

    printf("Enter here: ");
    scanf("%c", &ch);

    if(ch >= 'a' && ch <= 'z' || ch >= 'A' && ch <= 'Z')
    {
        printf("\n%c is an alphabet.\n", ch);
    }
    else
    {
        printf("\n%c is not an alphabet.\n", ch);
    }
    return 0;
}
Sample Output
Enter here: 9

9 is not an alphabet.

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

Write a C program to check whether a year is leap year or not

Check a year is leap year or not
Sample Output
Enter a year: 2020

2020 is leap year.

Process returned 0 (0x0)   execution time : 15.009 s
Press any key to continue.
Source Code
#include<stdio.h>
 
int main()
{
    int year;
 
    printf("Enter a year: ");
    scanf("%d", &year);
 
    if(year % 4 == 0 && year % 100 != 0 || year % 400 == 0)
    {
        printf("\n%d is leap year.\n", year);
    }
    else
    {
        printf("\n%d is not leap year.\n", year);
    }
    return 0;
}
Sample Output
Enter a year: 2021

2021 is not leap year.

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

Write a C program to check whether a number is even or odd

Check a number is even or odd
Sample Output
Enter a number: 21

This number is odd.

Process returned 0 (0x0)   execution time : 3.845 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num;
    
    printf("Enter a number: ");
    scanf("%d", &num);
 
    if(num % 2 == 0)
    {
        printf("\nThis number is even.\n");
    }
    else
    {
        printf("\nThis number is odd.\n");
    }
}
Sample Output
Enter a number: 36

This number is even.

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

Write a C program to check whether a number is divisible by 5 and 11 or not

Check a number is divisible by 5 and 11 or not
Sample Output
Enter a number: 33

This number is divisible by 11.

Process returned 0 (0x0)   execution time : 2.361 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num;
    
    printf("Enter a number: ");
    scanf("%d", &num);

    if(num % 5 == 0)
    {
        printf("\nThis number is divisible by 5.\n");
    }
    else if(num % 11 == 0)
    {
        printf("\nThis number is divisible by 11.\n");
    }
    else
    {
        printf("\nThis number is not divisible by 5 or 11.\n");
    }
    return 0;
}
Sample Output
Enter a number: 45

This number is divisible by 5.

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

Write a C program to check whether a number is negative, positive or zero

Check whether a number is negative, positive or zero
Sample Output
Enter a number: -76

-76 is negative number.

Process returned 0 (0x0)   execution time : 18.199 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num1;

    printf("Enter a number: ");
    scanf("%d", &num1);
    if(num1 > 0)
    {
        printf("\n%d is positive number.\n", num1);
    }
    else if(num1 < 0)
    {
        printf("\n%d is negative number.\n", num1);
    }
    else if(num1 == 0)
    {
        printf("\nZero Detected!\n");
    }
    else
    {
        printf("Invalid Input!");
    }
    return 0;
}
Sample Output
Enter a number: 333

333 is positive number.

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

Write a C program to find maximum between three numbers

Find maximum between three numbers
Sample Output
Enter first number: 56

Enter second number: 98

Enter third number: 37

98 is maximum number.

Process returned 0 (0x0)   execution time : 17.875 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num1, num2, num3;

    printf("Enter first number: ");
    scanf("%d", &num1);

    printf("\nEnter second number: ");
    scanf("%d", &num2);

    printf("\nEnter third number: ");
    scanf("%d", &num3);

    if(num1 > num2 && num1 > num3)
    {
        printf("\n%d is maximum number.\n", num1);
    }
    else if(num2 > num1 && num2 > num3)
    {
        printf("\n%d is maximum number.\n", num2);
    }
    else
    {
        printf("\n%d is maximum number.\n", num3);
    }
    return 0;
}
Sample Output
Enter first number: 56

Enter second number: 98

Enter third number: 37

98 is maximum number.

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

Write a C program to find maximum between two numbers

Find maximum between two numbers
Sample Output
Enter first number: 45

Enter second number: 31

45 is maximum number.

Process returned 0 (0x0)   execution time : 6.281 s
Press any key to continue.
Source Code
#include<stdio.h>

int main()
{
    int num1, num2;

    printf("Enter first number: ");
    scanf("%d", &num1);
    
    printf("\nEnter second number: ");
    scanf("%d", &num2);
 
    if(num1 > num2)
    {
        printf("\n%d is maximum number.\n", num1);
    }
    else
    {
        printf("\n%d is maximum number.\n", num2);
    }
    return 0;
}
Sample Output
Enter first number: -25

Enter second number: 24

24 is maximum number.

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

Problem Solution in Java Programming

C Programming Projects

 1. Name Shape

 2. Mini Project Contact Management System

Coming Soon...

 3. Student Management System | Based on C Language

 4. Various Type of Pattern | Based on C Language

 5. Basic Calculator | Based on C Language

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

Write a C program using three different User Defined Function...

Using User Defined Function (UDF)

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.

Sample Output
Enter the radius(inches): 5

Enter the computation mode:
V: Volumn
A: Area
A

The surface area is (square inches): 314.160


Process returned 0 (0x0)   execution time : 14.521 s
Press any key to continue.
Source Code
#include<stdio.h>
#include<math.h>
 
float pi = 3.1416;
 
int volumn(float radius)
{
    float V;
    V = (1.33333 * pi * pow(radius, 3));
 
    printf("\nThe volume is (square inches): %.3f\n\n", V);
}
 
int area(float radius)
{
    float A;
    A = 4 * pi * pow(radius, 2);
    printf("\nThe surface area is (square inches): %.3f\n\n", A);
}
 
int main()
{
    float radius;
    char option;
 
    printf("Enter the radius(inches): ");
    scanf("%f", &radius);
 
    printf("\nEnter the computation mode:\nV: Volumn\nA: Area\n");
    scanf(" %c", &option);
 
    switch(option)
    {
    case 'V':
    case 'v':
        volumn(radius);
        break;
 
    case 'A':
    case 'a':
        area(radius);
        break;
 
    default:
        printf("Invalid mode!");
        break;
    }
    return 0;
}
Sample Output
Enter the radius(inches): 5

Enter the computation mode:
V: Volumn
A: Area
A

The surface area is (square inches): 314.160


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

Write a program in Java to perform the followings - Java Teacher Example | Java Method Overloading

  1. Create a class Teacher with three private members Name, ID and Salary.
  2. Design three constructors of the Teacher class to initialize an object with default values, three different values and the values of another object of the same class.
  3. Design a display method to display the information of the calling object.
  4. Create a TeacherExample class and define a main method inside it. Now create three objects of the Teacher class inside the main method with three types of initialization.
  5. Display the information of the three objects of Teacher class
Write a program in Java to perform the followings
Sample Output
-----------------------------
 Teacher Name : Mohammad Istiaq
 Teacher ID   : 1002401
 Teacher Salary: 87500.0 Taka
-----------------------------
 
-----------------------------
 Teacher Name : Mohammad Arman
 Teacher ID   : 1002402
 Teacher Salary: 85500.0 Taka
-----------------------------
 
-----------------------------
 Teacher Name : Mohammad Istiaq
 Teacher ID   : 1002401
 Teacher Salary: 87500.0 Taka
-----------------------------
Source Code
package teacherexample;
 
class Teacher {
 
    private String Name;
    private long ID;
    private double Salary;
 
    Teacher() {
        Name = "Mohammad Istiaq";
        ID = 1002401;
        Salary = 87500;
    }
 
    Teacher(String name, long id, double salary) {
        Name = name;
        ID = id;
        Salary = salary;
    }
 
    Teacher(Teacher info) {
        Name = info.Name;
        ID = info.ID;
        Salary = info.Salary;
 
    }
 
    void display() {
        System.out.println("-----------------------------");
        System.out.println(" Teacher Name : " + Name);
        System.out.println(" Teacher ID   : " + ID);
        System.out.println(" Teacher Salary: " + Salary + " Taka");
        System.out.println("-----------------------------\n");
    }
}
 
public class TeacherExample {
 
    public static void main(String[] args) {
 
        Teacher info = new Teacher();
        info.display();
        Teacher info2 = new Teacher("Mohammad Arman", 1002402, 85500);
        info2.display();
        Teacher info3 = new Teacher(info);
        info3.display();
    }
}
Sample Output
-----------------------------
 Teacher Name : Mohammad Istiaq
 Teacher ID   : 1002401
 Teacher Salary: 87500.0 Taka
-----------------------------
 
-----------------------------
 Teacher Name : Mohammad Arman
 Teacher ID   : 1002402
 Teacher Salary: 85500.0 Taka
-----------------------------
 
-----------------------------
 Teacher Name : Mohammad Istiaq
 Teacher ID   : 1002401
 Teacher Salary: 87500.0 Taka
-----------------------------
Change Theme
X