Tuesday, January 31, 2017

Arrays - DS:An array is a type of data structure that stores elements of the same type in a contiguous block of memory

An array is a type of data structure that stores elements of the same type in a contiguous block of memory. In an array, , of size , each memory location has some unique index, (where ), that can be referenced as (you may also see it written as ).
Given an array, , of integers, print each element in reverse order as a single line of space-separated integers.
Note: If you've already solved our C++ domain's Arrays Introduction challenge, you may want to skip this.
Input Format
The first line contains an integer, (the number of integers in ).
The second line contains space-separated integers describing .
Constraints


Output Format
Print all integers in in reverse order as a single line of space-separated integers.
Sample Input
4
1 4 3 2
Sample Output
2 3 4 1
 
 
My Code in C:
 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <limits.h>
#include <stdbool.h>

int main(){
    int n,j=0; 
    int arr_i;
    scanf("%d",&n);
    int *arr = malloc(sizeof(int) * n);
    int *rarr=malloc(sizeof(int) * n);
    for( arr_i = 0; arr_i < n; arr_i++){
       scanf("%d",&arr[arr_i]);
    }
    for(arr_i = n-1; arr_i >= 0; arr_i--){
       rarr[j]=arr[arr_i];
        printf("%d ",arr[arr_i]);
        j++;
    }
    return 0;
}

Tuesday, January 24, 2017

Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN

Query the names of all the Japanese cities in the CITY table. The COUNTRYCODE for Japan is JPN.
Input Format
The CITY table is described as follows:
 

My SQL query: 

SELECT name from CITY where COUNTRYCODE= 'JPN';

Query all columns for a city in CITY with the ID 1661

Query all columns for a city in CITY with the ID 1661.
Input Format
The CITY table is described as follows:



My SQL Query:
 select * from CITY where ID=1661;

Query all columns (attributes) for every row in the CITY table.

Query all columns (attributes) for every row in the CITY table.
Input Format
The CITY table is described as follows:






CITY.jpg

My SQL Query:
                   select * from CITY;

Weather Observation Station 4-Let be the number of CITY entries in STATION, and let be the number of distinct CITY names in STATION

Let be the number of CITY entries in STATION, and let be the number of distinct CITY names in STATION; query the value of from STATION. In other words, find the difference between the total number of CITY entries in the table and the number of distinct CITY entries in the table.
Input Format
The STATION table is described as follows:

where LAT_N is the northern latitude and LONG_W is the western longitude.

My SQL Query:

select count(CITY)-count(DISTINCT CITY) from STATION;