C Programming and MySQL Queries
7 Questions
0 Views

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

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

Description

This quiz covers essential topics in C programming and MySQL queries. It includes tasks such as extracting digits from strings, dynamic memory allocation in C, and inserting and querying data in MySQL. Test your knowledge and skills in both programming and database management.

More Like This

Conexión a MySQL desde PHP
10 questions

Conexión a MySQL desde PHP

AffluentSmokyQuartz avatar
AffluentSmokyQuartz
PHP and MySQL Basics Quiz
3 questions
PHP and MySQL Basics
17 questions

PHP and MySQL Basics

AdventurousColosseum avatar
AdventurousColosseum
Conectarse y Crear Bases de Datos en MySQL
15 questions
Use Quizgecko on...
Browser
Browser