Skip to main content

Practice Problems #1.

Below are 6 problems related to arrays, decision making statements etc.

No solution will be provided for these problems except Bonus Problem.

Problem 1 - Your program should print 

  1. "The weather is Good" if today's temperature is greater than 20 degree and less than 25 degree, 
  2. "The weather is little cold" if today's temperature is less than 20 degree and greater than 15 degree, 
  3. "The weather is cold" if today's temperature is less than 15 degree.
  4. "The weather is little warm" if today's temperature is greater than 25 degree but less than 30 degree.
  5. "The weather is warm" if today's temperature is greater than greater than 30 degree and less than 40 degree.
  6. "The weather is really hot" if today's temperature is greater than 40 degree.
Try, to not to confuse yourself with all these statements and print accordingly to the condition matching the user's input.


Problem 2 - Try to create a program with following rules -
  1. In main method you should create an array dynamically and allocate memory for it.
  2. Create a function which take the array as argument and try to initialize this array in the function with the distinct multiples of number 2, but not in main method.

Problem 3 - Create a program which should take two, 2 dimensional arrays as input, and output there product. (Assume that both the arrays are square matrices and both arrays has same dimensions)


Problem 4 - Write a program to calculate the volume of a cube and area of a square.


Problem 5 - Try to create a program with following rules - 
  1. Create and initialize an array in your main method/function and pass it a function.
  2. The function should return an array (Return means really return).
  3. The returned array and array which is defined in main must have same sizes.
  4. The returned array must have every values 2 times the array sent as a paramter.
  5. The array sent as a parameter should not be modified.

Bonus Problem - Create a Program to print fibonacci sequence. The program should print 93 fibonacci numbers(let's see if you figure out, what I want you to).
Solution to Problem.

If you still don't get, what is wrong in bonus problem, comment below and I will try to clear that concept too.

Before watching this tutorial, please try to solve them by yourself.

Comments

Post a Comment

Popular posts from this blog

Introduction to Computer Science.

 Before directly jumping deeply in c++, let's first start by creating the roots of computer science. In this post we will answer the following question. What is Computer and How it works? What is Program and Operating system? Low Level vs High Level Language? Compiler v/s Interpreter? By Knowing All these basic concepts You will be able to understand the upcoming more complex concepts easily. Let's start answering the above questions. What is Computer and How it works? What is computer? If I answer briefly,  what is computer?  then it is just a calculator used for doing simple calculations. If I have to answer where is computer used?, then I could probably say everywhere. We are surrounded by computer, for example mobile, smartwatches, and personal computer (obviously).  The below image is the first mechanical computer that we used for calculation.                                   ...

C++ Built-in Data types.

Before diving into definition of various Data Types, let's first discuss something about memory. Below is the block diagram of memory(ram) where all the data is temporarily stored before execution. Memory. The lower area of this diagram is referred as Low Memory address and upper area of this diagram is referred as High Memory address. Now let's briefly discuss each of the segments, one by one. Code Segment - The segment of memory where the text or code or your file is stored temporarily is referred as code segment. For example the main function, the function that we defined etc. Data Segment  - Data segment is of two types  Initialized data segment or simply data segment - The variables that are declared and initialized in our program are stored here. Uninitialized data segment .- The variables that are just declared or have value zero and not in use are stored here. Heap - Heap is a storage where generally dynamic memory allocation takes place with the help of pointers. If...

Pointers.

I have already introduced pointers in the C++ Derived Data Types post , But, here I will be showing some practical examples and at the end of this slide, you will be understanding pointers like they are, obvious to you. So, let' start by reminding you the basic syntax :- <data type> *<name_of_pointer> ; Below is the simple program for pointer declaration and initialization. #include<iostream> using namespace std; int main (){ int a = 20 ; int *b; // Declaration of pointer b b = &a; // Initialization of pointer b (& is used to extract the address of a) int *c = b; // Initialization of pointer c to pointer b cout << a << endl << b << endl << c << endl; } Okay, after reminding the basic syntax of pointers, you have to memorize the reason why we generally use pointers, I have already discussed that also, but, let me briefly describe it. One of the memory section in our Comp...