C Programming and MySQL Queries

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

Write a C program to extract the individual digits from a given string.

#include <stdio.h>
#include <string.h>

int main() {
    char str[100];
    int i, len;

    printf("Enter a string: ");
    gets(str);

    len = strlen(str);

    printf("The digits in the string are: ");
    for (i = 0; i < len; i++) {
        if (str[i] >= '0' && str[i] <= '9') {
            printf("%c ", str[i]);
        }
    }

    return 0;
}

Write a C program to dynamically allocate memory for an array to store 10 integers and display the first 5 out of them.

#include <stdio.h>
#include <stdlib.h>

int main() {
    int *ptr, i;

    // Dynamically allocate memory for an array of 10 integers
    ptr = (int *)malloc(10 * sizeof(int));

    if (ptr == NULL) {
        printf("Memory allocation failed!
");
        return 1;
    }

    // Assign values to the array
    printf("Enter 10 integers:\n");
    for (i = 0; i < 10; i++) {
        scanf("%d", &ptr[i]);
    }

    // Display the first 5 integers
    printf("The first 5 integers are:\n");
    for (i = 0; i < 5; i++) {
        printf("%d ", ptr[i]);
    }

    // Free the dynamically allocated memory
    free(ptr);

    return 0;
}

Insert data into the table as follows:

INSERT INTO Sales (SalesmanNo, SalesmanName, DateOfJoining, SalesZone, SalesAmount)
VALUES
('S001', 'Ratul Saha', '2015-07-06', 'SOUTH', 8000000),
('S002', 'Amir Hamza', '2017-08-09', 'EAST', 3400000),
('S003', 'Pankaj Pathak', '2018-03-09', 'WEST', 2400000),
('S004', 'Abdus Salam', '2019-08-05', 'NORTH', 5000000),
('S005', 'Amrit Paul', '2013-07-09', 'SOUTH', 4700000),
('S006', 'Ramesh Sharma', '2012-05-12', 'EAST', 7000000);

Display Salesman No and Salesman Name of each record.

<pre><code class="language-sql">SELECT SalesmanNo, SalesmanName FROM Sales; </code></pre> Signup and view all the answers

Display Salesman No and Salesman Name of East Zone.

<pre><code class="language-sql">SELECT SalesmanNo, SalesmanName FROM Sales WHERE SalesZone = 'EAST'; </code></pre> Signup and view all the answers

Display the records having Sales Amount in the range 2,00,000 to 3,50,000.

<pre><code class="language-sql">SELECT * FROM Sales WHERE SalesAmount BETWEEN 200000 AND 350000; </code></pre> Signup and view all the answers

Display the maximum and minimum Sales Amount.

<pre><code class="language-sql">SELECT MAX(SalesAmount), MIN(SalesAmount) FROM Sales; </code></pre> Signup and view all the answers

Flashcards

C Program

A set of instructions written in C language to perform specific tasks.

Dynamic Memory Allocation

Allocating memory at runtime using functions like malloc and free in C.

The malloc function

A standard library function in C used to allocate a specified number of bytes of memory.

Array in C

A collection of elements stored at contiguous memory locations, indexed from 0.

Signup and view all the flashcards

Extracting Digits from String

Process to retrieve individual numeric characters from a string input.

Signup and view all the flashcards

MySQL INSERT Command

SQL command used to add new records into a database table.

Signup and view all the flashcards

Salesman Table Structure

A defined layout of columns in a database table holding salesman data.

Signup and view all the flashcards

Data Types in C

Different kinds of data that can be stored, such as int, float, and char.

Signup and view all the flashcards

SQL SELECT Statement

A SQL query used to retrieve data from a database.

Signup and view all the flashcards

Display records in SQL

Retrieve and show specific records based on query criteria.

Signup and view all the flashcards

Sales Amount Range Query

A SQL query to filter records based on sales figures between two values.

Signup and view all the flashcards

MySQL MAX and MIN Functions

Functions to find the highest and lowest values in a selected column.

Signup and view all the flashcards

SQL WHERE Clause

A clause to specify criteria for selecting records in a SQL query.

Signup and view all the flashcards

Strings in C

A sequence of characters ending with a null character, used to handle text.

Signup and view all the flashcards

Structuring MySQL Tables

The process of defining columns and data types in a table for data storage.

Signup and view all the flashcards

Loop in C Programming

A programming construct to execute a block of code repeatedly until a condition is met.

Signup and view all the flashcards

ASCII Values

Numeric representation of characters in programming, used for conversions.

Signup and view all the flashcards

Dynamic Array

An array that can change its size during runtime using dynamic memory management.

Signup and view all the flashcards

Joining in SQL

Combining rows from two or more tables based on a related column.

Signup and view all the flashcards

Study Notes

C Programming

  • Write a C program to extract individual digits from a given string
  • Write a C program to dynamically allocate memory
    • Store 10 integers
    • Display first 5 integers

MySQL Queries

  • Insert Data:

    • Insert data into a table, including:
      • Salesman No
      • Salesman Name
      • Date of Joining
      • SalesZone
      • SalesAmount
    • Example Data:
      • S001, Ratul Saha, 2015-07-06, SOUTH, 8,00,000
      • S002, Amir Hamja, 2017-08-09, EAST, 3,40,000
      • ... and so on (see table)
  • Queries:

    • Display Salesman No and Salesman Name for all records
    • Display Salesman No and Salesman Name for East Zone
    • Display records with Sales Amount between 2,00,000 and 3,50,000
    • Maximum and Minimum Sales Amount

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

More Like This

Conexión a MySQL desde PHP
10 questions
PHP and MySQL Basics Quiz
3 questions
PHP and MySQL Basics
17 questions

PHP and MySQL Basics

AdventurousColosseum avatar
AdventurousColosseum
Use Quizgecko on...
Browser
Browser