Run C, C++, Java, PHP, Python, JavaScript Codes Just from This Forum!

Post Reply
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#1

Now you will be able to program in C, C++, Java, PHP, Python, JavaScript, and more! Thanks to the Techie Delight and GDB Online for their esteemed support. Select any language from the drop-down menu, write your code, and click run (or press F9) to execute it. There are two IDE that complement each other.

For best experience use, Mozilla Firefox if using desktop;
Google Chrome or Mozilla Firefox if using mobile:



1
1 Image
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#2

Here is another IDE for Team collaborations powered by CP Initiative:

C++




Python 3



Try the following codes:


C:

  1. #include<stdio.h>  
  2.  
  3. long factorial(int n)  
  4. {  
  5.   if (n == 0)  
  6.     return 1;  
  7.   else  
  8.     return(n * factorial(n-1));  
  9. }  
  10.    
  11. void main()  
  12. {  
  13.   int number;  
  14.   long fact;  
  15.   printf("Enter a number: ");  
  16.   scanf("%d", &number);  
  17.    
  18.   fact = factorial(number);  
  19.   printf("Factorial of %d is %ld\n", number, fact);  
  20.   return 0;  
  21. }  


  1. #include<stdio.h>  
  2. int main()    
  3. {    
  4.  int i,fact=1,number;    
  5.  printf("Enter a number: ");    
  6.   scanf("%d",&number);    
  7.     for(i=1;i<=number;i++){    
  8.       fact=fact*i;    
  9.   }    
  10.   printf("Factorial of %d is: %d",number,fact);    
  11. return 0;  
  12. }  


C++:

  1. #include <iostream>
  2. using namespace std;
  3.  
  4. int main() {
  5.     int numbers[2][3];
  6.  
  7.     cout << "Enter 6 numbers: " << endl;
  8.  
  9.     // Storing user input in the array
  10.     for (int i = 0; i < 2; ++i) {
  11.         for (int j = 0; j < 3; ++j) {
  12.             cin >> numbers[i][j];
  13.         }
  14.     }
  15.  
  16.     cout << "The numbers are: " << endl;
  17.  
  18.     //  Printing array elements
  19.     for (int i = 0; i < 2; ++i) {
  20.         for (int j = 0; j < 3; ++j) {
  21.             cout << "numbers[" << i << "][" << j << "]: " << numbers[i][j] << endl;
  22.         }
  23.     }
  24.  
  25.     return 0;
  26. }


Java:

  1. public class GCD {
  2.  
  3.     public static void main(String[] args) {
  4.         int n1 = 366, n2 = 60;
  5.         int hcf = hcf(n1, n2);
  6.  
  7.         System.out.printf("G.C.D of %d and %d is %d.", n1, n2, hcf);
  8.     }
  9.  
  10.     public static int hcf(int n1, int n2)
  11.     {
  12.         if (n2 != 0)
  13.             return hcf(n2, n1 % n2);
  14.         else
  15.             return n1;
  16.     }
  17. }



Python:


Given the list of integers, X, write code to count how many integers are strictly larger than all the integers to their right. Exclude the last digit since it doesn’t have a number to its right. E.g. for [2,3,1] the answer should be 1 while for [12,4,4,2,2,3] the answer is 2.

In Python the code may look like (Use other languages):

  1. X = [7,9,5,3,2,4,5,0]
  2.  
  3. def current_max(X):
  4.     m = 0
  5.     for i in X[::-1]:
  6.         m = max(m, i)
  7.         yield m
  8. N_int = sum([x>y for x,y in zip(X[-2::-1], current_max(X))])
  9. print(N_int)

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#3

Copy and paste this template into the editor above and start learning HTML5, CSS, and JavaScript:

  1. <!DOCTYPE html>
  2. <html lang='en'>
  3. <head>
  4.     <meta charset="UTF-8">
  5.     <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6.     <meta name="viewport" content="width=device-width, initial-scale=1">
  7.     <!-- The above 3 meta tags must come first in the head; thereafter
  8.    other head content may follow -->
  9.     <title>Document</title>
  10. </head>
  11. <body>
  12. <h1>Hello World</h1>
  13. </body>
  14. </html>

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
User avatar
Eli
Senior Expert Member
Reactions: 183
Posts: 5334
Joined: 9 years ago
Location: Tanzania
Has thanked: 75 times
Been thanked: 88 times
Contact:

#4

  1. import java.util.Date;
  2. public class Main {
  3.     public static void main(String[] args) {
  4.         byte age = 45;
  5.         Date now = new Date();
  6.         System.out.println(now);
  7.         System.out.println("Hello TSSFL ODF");
  8.     }
  9. }

0
TSSFL -- A Creative Journey Towards Infinite Possibilities!
Post Reply
  • Similar Topics
    Replies
    Views
    Last post

Return to “Technologies for Teaching, Learning, Research, Problem Solving and Business”

  • Information
  • Who is online

    Users browsing this forum: No registered users and 11 guests