Posts

Showing posts from August, 2020

For Loop Factorial Question

  Factorial of a number Question:- Remya is studying in 10th std and she was not good at maths. Her maths teacher asked to find a factorial of the given number. Can you help Remya by writing a program for the same. Input Format: The input consist of an integer Output Format: Print the factorial of a number which denotes an integer Sample Input: 5 Sample Output: 120                                                             Answer #include<iostream> int main() { int  a,i,b = 1;   std::cin>>a;   for ( i=1 ; a >=i  ; i++)   {   b  = i*b;   }       std::cout<<b; }

Car Mileage Problem

  Car mileage Nanu bought a new car and for the first time, he wants to go to a temple. Without checking how much petrol is available in the car, he started traveling. After reaching a certain distance, he remembered that he didn't check the petrol level of his car. Then he checks the petrol level and calculates how much distance he must travel to reach the destination. Find whether he can reach the destination with the available petrol. Mileage is also known. Display “Can reach” or “Cannot reach” based on the situation. INPUT & OUTPUT FORMAT: Input consists of 1 float and 2 integers values. First input corresponds to the mileage which is of float datatype. Second input corresponds to liters of petrol available. Third input corresponds to the distance to be travelled. The output consists of one string. SAMPLE INPUT: 11 6 67 SAMPLE OUTPUT: Cannot reach Case 1 Case 2 Case 3 Input (stdin) 11 6 67 Output (stdout) Cannot reach ANSWER.. #include<iostream> using nam...

Raj in wonderland An island called “Wonderland” is filled with treasures. Raj is trying to get the treasure. To get it, he has to reach the end of the snow land in the island but got puzzled in the mid-way by a hint he got there. The hint is stating that to cross the snow land he has to jump on the ice stones which is of pairs else he will be drowned in the cold river. He has to check whether the number of ice stones is in pairs or not. Suggest him a logic to check the pairs of stones and say whether he can get the treasure or not. The input should be an integer. The output should be either Possible or Not possible. [Hint : Use ternary operator]

Raj in wonderland An island called “Wonderland” is filled with treasures. Raj is trying to get the treasure. To get it, he has to reach the end of the snow land in the island but got puzzled in the mid-way by a hint he got there. The hint is stating that to cross the snow land he has to jump on the ice stones which is of pairs else he will be drowned in the cold river. He has to check whether the number of ice stones is in pairs or not. Suggest him a logic to check the pairs of stones and say whether he can get the treasure or not. The input should be an integer. The output should be either  Possible  or  Not possible . [Hint : Use ternary operator] Ans:- #include<iostream> int main() {  int a;  std::cin>>a;  (a%2==0)?std::cout<<"Possible":std::cout<<"Not possible"; }

Basic Syntax of C++ and Hello world code explained

#include<iostream> int main() {  std::cout<<"Hello World"; } OUTPUT Hello World  #include<iostream> # - Preprocessor directive iostream - Header ( processing before time ) int main  main - Function name { - indicates the begging of the main function. } - closing of the main function. std:: cout << " Hello World "; std :: - standard character output cout - character output ""  used before writing the Character and also end with that. << ; insertion operator  ; - This tell us the end of the line