The Next Number

General Statement:
A relatively simple task for humans to do is to identify the next number in an arithmetic sequence of numbers. For example, given the sequence of numbers 3, 6, and 9, we know that the next number in the sequence is 12 since each number is followed by a number increasing it by 3. Alternatively, given the sequence of numbers 3, 6, and 12, we know that the next number in the sequence is 24 since each number is followed by a number that doubles it.

Your task is to write a program that will deduce the next integer in a given sequence of three integers where the same arithmetic operation is applied to each integer to produce the next. The only arithmetic operations that will be used are addition, subtraction, multiplication, or division.

Input: The first line of the input contains an integer n that represents the number of data collections that follow where each data collection is on a single line. Each input line contains three integers with each pair of integers separated by a single space. The integers represent a sequence as described in the General Statement.

Output: Your program should produce n lines of output (one for each data collection). The output for each data collection should be the next integer in the corresponding input sequence.

The output is to be formatted exactly like that for the sample output given below.

Assumptions: The value of n will be between 1 and 100, inclusive.
There will be exactly one answer to each input sequence.
The answer will always be an integer (even if division is used).

Sample Input:
3
7 21 35
-10 20 -40
64 16 4

Sample Output:
49
80
1

#include <stdio.h>

int main ()
{
    int n;
    scanf ("%d", &n);

    while ( n-- ) {
        double x, y, z;

        scanf ("%lf %lf %lf", &x, &y, &z);

        if ( y - x == z - y )
            printf ("%0.lf\n", z + y - x);

        else
            printf ("%0.lf\n", z / (x / y));
    }

    return 0;
}

Anything You Can Do, I Can Do Better

General Statement:
You have a colleague that is extremely competitive and always tries to “top” one of your stories. If you say your car is fast, your colleague will say his or her car is faster. If you say your car is faster, your colleague will say his or her car is fastest. After a few such conversations, you realize that you can always predict what your colleague will say next.

To demonstrate how annoying this is, you decide to write a program that can accurately predict the responses of your colleague. Your task is to write this program. Specifically, given any adjective, your program will return its comparative form by appending “er” to it. Note that if the adjective already ends in “e”, you should only append “r”. If your program is given an adjective already in its comparative form, your program should return the superlative form of the adjective created by simply replacing the “er” with “est”. Your program should consider any string that ends in “er” to be an adjective in comparative form.

Input:
The first line of the input contains an integer n that represents the number of data collections that follow where each data collection is on a single line. Each input line contains a string representing an adjective or its comparative form. Each string will be given in all lower case letters.

Output:
Your program should produce n lines of output (one for each data collection). Each line should be in lower case letters. If the input is the comparative form of an adjective (ends in “er”), your program should output the superlative form.

Otherwise, your program should output the comparative form of the string given as input.

The output is to be formatted exactly like that for the sample output given below.

Assumptions:
The value of n will be between 1 and 100, inclusive.
Each input word will have between 1 and 30 characters, inclusive.

Sample Input:
3
warm
smaller
rare

Sample Output:
warmer
smallest
rarer

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

int main ()
{
    int dataset;
    scanf ("%d", &dataset);

    while ( dataset--) {
        char input [35];
        scanf ("%s", input);

        int length = strlen (input);

        if ( input [length - 1] == 'r' && input [length - 2] == 'e' ) {
            input [length - 1] = 's';
            input [length] = 't';
            input [length + 1] = 0;
        }

        else {
            if ( input [length - 1] == 'e' )
                strcat (input, "r");
            else
                strcat (input, "er");
        }

        printf ("%s\n", input);

    }

    return 0;
}

Training Times

General Statement:
Some training simulation systems automatically record the response time of their users in order to gauge the effectiveness of the training system. The goal is for the user to become faster at completing the simulation. There are times, however, when a user gets fatigued and starts becoming slower at completing the simulation. Your task is to write a program that can determine from a collection of two input recorded times if the user is improving.

Input:
The first line of the input is an integer n that represents the number of data collections that follow where each data collection is on a single line. Each data collection contains two integers x and y separated by a single space. The integers represent the first and second times (in milliseconds) of the users, respectively.

Output:
Your program should produce n lines of output (one for each data collection). If the second time is smaller than the first, then the user is getting faster. In this case, your program should print IMPROVING. Otherwise, the user is not improving, and your program should print NOT IMPROVING.
The output is to be formatted exactly like that for the sample output given below.

Assumptions:
The value of n will be between 1 and 100, inclusive.
Each input integer will be between 0 and 1,000,000, inclusive.

Sample Input:
3
500 450
1000 1001
75 75

Sample Output:
IMPROVING
NOT IMPROVING
NOT IMPROVING

#include <stdio.h>

int main ()
{
    int dataset;
    scanf ("%d", &dataset);

    while ( dataset--) {
        int first;
        int second;

        scanf ("%d %d", &first, &second);

        if ( second < first )
            printf ("IMPROVING\n");

        else
            printf ("NOT IMPROVING\n");
    }

    return 0;
}

Problem : 20

#include <stdio.h>

int SUM ()
{
    int sum = 0, i, j;

	for(i = 1; i < 1000; i++) {
		for(j = 1; j < 1000; j++) {
			for(int k = 1; k < 1000; k++) {
				sum++;
				sum %= 1000;
			}
		}
	}
	printf("%d\n",sum);
	return sum;

}
int main() {
	SUM();
	return 0;

}


// What's the output ?
// Source : http://www.youngprogrammer.com/

Problem : 19

#include <stdio.h>

void Printf () {

	int i, sum = 0;
	for(i = 0; i< 2147483646; i++) {
		sum++;
		sum %= 26;
	}

	printf("%c\n",sum + 'A');
}

int main () 
{
	Printf();
	return 0;
}


// What's the output ?
// Source : http://www.youngprogrammer.com/

Problem : 18

#include <stdio.h>

int While (int k)
{
	return k++;
}


int FOR (int n, int m, int k)
{
	return While (k * (++m) *n);
}


int main ()
{
    int i = 5, sum = 0, j;
	for(j = 0; j< FOR(i = 10, i > 5, i++); j++, sum += j);
	printf("%d\n",j);
	return 0;
}


// What's the output ?
// Source : http://www.youngprogrammer.com/

Problem : 17

#include <stdio.h>

typedef long long INT;

int Boolean (INT n) 
{
    if ( n is a fibonacci number )
        return 1;
        
    else 
        return 0;
}


int main ()
{
    INT i, total = 0;
    
    for(i = 1; i < 2147483649; i++) {
        if( Boolean(i) ) 
            total++;
    }
    
    printf("%lld\n",total);
    return 0;
}


// What's the output ?
// Source : http://www.youngprogrammer.com/

Problem : 16

#include <stdio.h>
  
int main () 
{
    long long sum = 0;
    
    for(int i = 0; i <= 1000000000; i++) {
        sum += i%5;
    }
    
    printf("%lld\n",sum);
    return 0;
}


// What's the output ?
// Source : http://www.youngprogrammer.com/

Problem : 15

#include <stdio.h>
#define F(a,b) (a*b) / (a-b)

int main ()
{
    int a = 20, b = 10;
    printf("%d\n", F(a-1, b+2));
    return 0;
}


// What's the output ? [Do not execute / run]
// Source : http://www.youngprogrammer.com/

Problem : 14

#include <stdio.h>
#define ABC 20
#define XYZ 10
#define XXX ABC-XYZ


int main ()
{
    int a = XXX * 10;
    printf("%d\n", a);
    return 0;
}

// What's the output ? [Do not execute / run]
// Source : http://www.youngprogrammer.com/

Follow

Get every new post delivered to your Inbox.

Join 48 other followers