Posts

Hackerearth Pr1.

''' # Sample code to perform I/O: name = input() # Reading input from STDIN print('Hi, %s.' % name) # Writing output to STDOUT # Warning: Printing unwanted or ill-formatted data to output will cause the test cases to fail ''' # Write your code here #let's begin t = int ( input ( 'Enter the number of test cases: ' )) pr_list = [] for x in range ( 0 , t ): grcost , prcost = input ( 'Enter price of green and purple balloon respectively: ' ) .split () n = int ( input ( 'Enter the number of participants: ' )) for y in range ( 0 , n ): points = input ( "0 or 1 for 1st problem and 2nd problem respectively: " ) .split () pr_list.append ( points ) points = [] sum1 = 0 sum2 = 0 for z in range ( 0 , n ): sum1 = sum1 + pr_list [ z ][ 0 ] sum2 = sum2 + pr_list [ z ][ 1 ] if sum1 > sum2 and grcost > prcost or sum2 > s...

Stock Market Simulator / Comp. Interest Calculator

 #include <iostream> #include <cmath> using namespace std; int main() {     float a;     float p = 100 0;     float r = .01;     for(int day = 1; day <= 30; day++){         a = p * pow(1+r, day);         cout << day << "  --------  " << a << endl;     } }

Avg age of any no. of ppl while loop

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int age, totalppl = 0, ageTotal = 0;     cout << "Enter First persons age or -1 to exit " << endl;     cin >> age;     while(age!=-1){         ageTotal = age + ageTotal;         totalppl = totalppl + 1; //Important          cout << "Enter next persons age or -1 to exit: " << endl;          cin >> age;     }     cout << "Total People Entered is: " << totalppl << endl;     cout << "Average age is : " << ageTotal/totalppl << endl;     return 0; }

Avg age of any no. of ppl for loop

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int age, totalppl = 0, ageTotal = 0;     cout << "Enter First persons age or -1 to exit " << endl;     cin >> age;     for(totalppl; age!=-1; totalppl++)     {         ageTotal = age + ageTotal;         cout << "Enter next persons age or -1 to exit: " << endl;         cin >> age;     }     cout << "\n\n Total no. of people are : " << totalppl << endl;     cout << "\n Avereage age of all the people is: \n\n " << ageTotal/totalppl;     return 0; }

Random Number

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int x;     cout << time(0); //IMPORTANT     srand(123);     for(x; x<30; x++){         cout << (rand()%31)+15 << endl; //IMPORTANT     } }

Sum of n numbers( n is entered by user).

 #include <iostream> #include <cstdlib> #include <ctime> using namespace std; int main() {     int x = 1, n, number, total;     total = 0;     cout << "Enter how many numbers you want to add: " << endl;     cin >> n;     for(x; x<=n; x++){ //Important         cout << "Enter " << x << " number: " << endl;         cin >> number;         total = total + number;     }     cout << total << endl;     return 0; }

Primitive Calculator using C++

 #include <iostream> using namespace std; int main() {     int a, b, Sum, Difference, Multiplication, Division, Op;     cout << "Enter first no. " << endl;     cin >> a;     cout << "Enter second no. " << endl;     cin >> b;     cout << "Choose Operation from below \n Sum \n Difference \n Multiplication \n Division" << endl;     cin >> Op;     if(Op==Sum)     {         cout << "The Sum is " << a + b << endl;     }     else if(Op==Difference)     {         cout << "The difference is " << a -b << endl;     }     else if(Op==Multiplication)     {         cout << "Product is " << a*b << endl;     }     else if(Op==Division)     {   ...