Skip to main content

Online C Compilers easy to debug and run

Online C compilers provide facility to code from anywhere and run it. There are many online compilers available online but here is the one which is more useful and tested.

  1. OnlineGDB
  • This compile program in C , Turbo C as per option we select.
  • Editor provide to copy and paste the code. We can type new code and after that run and debug it.
  • This online code compiler provide facility to share written program.
  • User can pass command line arguments as well.
  • Facility to organize written code in tabular format.
  • Three different editor mode are provided like normal, Emacs, VIM.
  • It takes no time to return program output
  • facility to save program, projects by signing up.
  • Easy to share and Embed written code to any other website.

Online GDB complier is useful for languages like C, C++, Python, Java, PHP, C#, HTML, CSS, RUBY, PERL, Pascal, R, Fortran, Haskell, SQLite, Prolog, Swift, Rust, Go, Bash.

Other compilers which are available and also useful are

2) Programiz

3) Tutorialspoint

4) Onecompiler

5) Jdoodle

C Program to Find Largest & Smallest among N Numbers

There are many ways to identify largest or smallest number from user input. Here we are using for loop.

// Program to find smallest and largest number from user input.

#include<stdio.h>
void main()
{
    int large,small,no,range,i;
    printf ("\n\tFrom how many numbers you want to identify smallest and largest\t");
    scanf ("%d", &range);
    printf ("\n\tEnter  number 1==>");
    scanf ("%d", &no);
    large = no;
    small=no;
    for (i=1; i<= range -1 ; i++)
    {
        printf ("\n\t Enter number %d ==> ",i+1);
        scanf ("%d",&no);
        if (no >= large)
        large = no;
        if (no <= small)
        small = no;
    }//end of For loop
    printf ("\n\t The largest number is %d", large);
    printf ("\n\t The smallest number is %d", small);

}

Output

 From how many numbers you want to identify smallest and largest 6

        Enter  number 1==>11

         Enter number 2 ==> 11

         Enter number 3 ==> 22

         Enter number 4 ==> 22

         Enter number 5 ==> 33

         Enter number 6 ==> 44

         The largest number is 44

         The smallest number is 11

We can write this program using various loop and logic.

Program for KiloMeters to mile In C

Here is C Program – Complete code to convert kilometers to mile by accepting user input.

Formula used in program is : miles=(km/1.609344);

//Accept Distance in Kilometer 
// from km to miles need to divide appx  1.609344

#include<stdio.h>
#include<conio.h>

void main()
 {
   float km,miles;// declaring variable as float as km can be in decimal.

   printf("\n\t Enter Kilometer to Convert it in miles: ");
   scanf("%f",&km);    //%f Read float value

   //Now converting kilometer to Miles

   miles=(km/1.609344);

   printf("\n\t %f kilometer in Miles are %f ",km,miles);
   getch();
 }

OUTPUT

    Enter Kilometer to Convert it in miles: 1

         1.000000 kilometer in Miles are 0.621371 

Code to write Fibonacci series for number of elements as per user input.

Fibonacci series means a series of numbers in which each number is the sum of the two preceding numbers. Example is 1, 1, 2, 3, 5, 8

Below is C program code to print Fibonacci series as per user input.

for e.g if user input 20 then program will print 20 elements in Fibonacci series.

//Program Name: Print fibonacci series using for loop upto n term
// for e.g 1, 1, 2, 3, 5, 8

#include <stdio.h>

void main()
{
    int s1=0,s2=1; //initializing first two numbers 
    int nextNum=0,numCnt=0,i;

    printf("\n\n\tPlease enter how many numbers need to print in Fibonacci series.\t");
    scanf("%d",&numCnt);
    //here assuming user will enter value more than 1 
    //printing first two numbers
    printf("\n\tBelow are %d numbers in Fibonacci Series  ",numCnt);
    printf("\n\n\t%d %d",s1,s2);
     for(i=2;i<numCnt;i++)
    {    
        nextNum=s1+s2;
        printf(" %d",nextNum); 
        s1=s2;    
        s2=nextNum; 
       
    }  
}

Output

        Please enter how many numbers need to print in Fibonacci series.       20

        Below are 20 numbers in Fibonacci Series  

        0 1 1 2 3 5 8 13 21 34 55 89 144 233 377 610 987 1597 2584 4181

If you want to print Fibonacci series up to particular number then refer this link

How to write simple C Program for Fibonacci series using for loop

Fibonacci series means a series of numbers in which each number is the sum of the two preceding numbers. Example is 1, 1, 2, 3, 5, 8

Below is C program code to print Fibonacci series as per user input or up to n number.

for e.g if user input 200 then program will print Fibonacci series till 200 meaning sum which is less than or equal to 200.

//Program Name: Print fibonacci series using for loop upto n term
// for e.g 1, 1, 2, 3, 5, 8

#include <stdio.h>

void main()
{
    int s1=0,s2=1; //initializing first two numbers 
    int nextNum=0,SumUpto=0;

    printf("\n\n\tPlease enter number up to which print Fibonacci series is required \t");
    scanf("%d",&SumUpto);
    //here assuming user will enter value more than 1 
    //printing first two numbers
    printf("\n\tfibbonacci Series up to %d is ",SumUpto);
    printf("\n\n\t%d  %d",s1,s2);
     for(nextNum=2;nextNum<=SumUpto;)
    {    
 
        s1=s2;    
        s2=nextNum; 
        printf(" %d",nextNum); 
        nextNum=s1+s2;
    }  
}

Output


        Please enter number up to which print Fibonacci series is required      200

        Fibonacci Series up to 200 is 

        0  1 2 3 5 8 13 21 34 55 89 144

Another method to find the Fibonacci numbers is by using the golden ratio (1.618034).

Here is a method to find the Fibonacci series using the golden ratio method.

Just by multiplying the previous Fibonacci Number by the golden ratio(1.618034), we get the approximated Fibonacci number. For example, 2 × 1.618034… = 3.236068. This gives the next Fibonacci number 2 after 3.

C code for Fibonacci series using the golden ratio.

// Fibbonaci series using golden ratio.
#include <stdio.h>
#include <math.h>
int main() {
    // Write C code here
    float result=1.0;
    //result=1.0;
    printf("\n0\n1\n1");
    for(int i=1;i<15;i++)
    {
        result = lround( result * (1.618034));
        printf("\n%d",lround(result));
    }
}

Output

0
1
1
2
3
5
8
13
21
34
55
89
144
233
377
610
987

C Program for smallest, largest of three number using ternary operator

Below running code will accept 3 Numbers from user.

Based on results given in expression in ternary operator program will return smallest number

// Program Name: C Program to find smallest number using Ternary operator
#include <stdio.h>

void main()
{
    int num1,num2,num3;
    int counter;
    printf("\n\tEnter first Integer Number\t");
    scanf("%d",&num1);
    printf("\n\tEnter Second Integer Number\t");
    scanf("%d",&num2);
    printf("\n\tEnter Third Integer Number\t");
    scanf("%d",&num3);
    
    
    // Ternary operator
    counter = (num1 < num2) ? (num1 < num3 ? num1:num3) : (num2 < num3 ? num2:num3);
    
    printf("\n\t Minimum of 3 Number is %d", counter);
}

Output


        Enter first Integer Number      11

        Enter Second Integer Number     90

        Enter Third Integer Number      32

         Minimum of 3 Number is 11

To find another method Click here . Program to find smallest number without comparison

Program to find largest or greatest of 3 number using ternary operator

Accept 3 numbers from user using scanf. User ternary operator to compare them and print result using printf. Here is complete code.

// Program Name: C Program to find largest number using Ternary operator
#include <stdio.h>

void main()
{
    int num1,num2,num3;
    int counter;
    printf("\n\tEnter first Integer Number\t");
    scanf("%d",&num1);
    printf("\n\tEnter Second Integer Number\t");
    scanf("%d",&num2);
    printf("\n\tEnter Third Integer Number\t");
    scanf("%d",&num3);
    
    
    // Ternary operator
    counter = (num1 > num2) ? (num1 > num3 ? num1:num3) : (num2 > num3 ? num2:num3);
    
    printf("\n\t Largest of 3 Number is %d", counter);
}

Output

Enter first Integer Number	4
Enter Second Integer Number	5
Enter Third Integer Number	6
Largest of 3 Number is 6

C Program for Smallest of three numbers without comparing

There are many ways to find smallest. Below program will accept 3 integer numbers from user

We are using while loop here and one increment variable.

Every time program is subtracting value by 1 and incrementing counter variable by 1. once condition is false program will return smallest number. This is simple basic mathematical operation. Below is complete running code.

// Program Name: C Program to find smallest number without comparison
#include <stdio.h>

void main()
{
    int num1,num2,num3;
    int counter=0;
    printf("\n\tEnter first Integer Number\t");
    scanf("%d",&num1);
    printf("\n\tEnter Second Integer Number\t");
    scanf("%d",&num2);
    printf("\n\tEnter Third Integer Number\t");
    scanf("%d",&num3);
    
    
    // Here we are using while loop when result is false we will get smallest number 
    while(num1 && num2 && num3)
    {
        num1--;
        num2--;
        num3--;
        counter++;
    }
    printf("\n\t Minimum of 3 Number is %d", counter);
}

Output

Enter first Integer Number      4

        Enter Second Integer Number     3

        Enter Third Integer Number      0

         Minimum of 3 Number is 0

C Program to find even ,odd numbers and their sum and average

Below program will accept the range for example 62 to 70. Program will count all even and odd numbers from range 62 to 70 and perform sum of even and odd numbers respectively. It also provide average of odd and even numbers.

// Program Name: Accept Range from user and then find even odd numbers with sum and average respectively.
#include<stdio.h>
 
void main()
{
 int startNum=0,endNum=0,i=0,eNoCnt=0,oNoCnt=0,eSum=0,oSum=0;
 
 printf("\n\t Provide Range of number to identify even number as requested for e.g 56 90");
 printf("\n\n\n\t Please provide Range\t");
 scanf("%d", &startNum);
 scanf("%d", &endNum);

 for(i = startNum; i < endNum; i ++)
 {
   if(i % 2 == 0)
   {
     eNoCnt++;
     eSum=eSum+i;
   }
   else
   {
     oNoCnt++;
     oSum=oSum+i;
   }
 }
  
 printf("\n\t Total Number of Even Numbers are = %d ", eNoCnt);
 printf("\n\t Total of Even number is %d",eSum);
 printf("\n\t Average of Even Number is %d",eSum/eNoCnt);
 printf("\n\n\t Total Number of Odd Numbers are = %d ", oNoCnt);
 printf("\n\t Total of Odd number is %d",oSum);
 printf("\n\t Average of Odd Number is %d",oSum/oNoCnt);
}

Output

Please provide Range   1
500

         Total Number of Even Numbers are = 249 
         Total of Even number is 62250
         Average of Even Number is 250

         Total Number of Odd Numbers are = 250 
         Total of Odd number is 62500
         Average of Odd Number is 250

C Program to find length of string with or without function

//Program Name: To find length of the string with and without function.

#include<stdio.h>
#include<string.h>
void main()
{
char str[250]; //to store entered string
int cnt;  //counter

printf("\n\tEnter a string to check length:" );
gets(str);

for(cnt = 0; str[cnt] != '\0'; ++cnt);

printf("\n\t Length of string without using function: %d", cnt);

printf("\n\t Length of string with strlen function %d",strlen(str));

}

Output

Enter a string to check length:Learning C
Length of string without using function: 10
	 Length of string with strlen function 10

C Program to Identify Even Odd numbers from user input.

Below program will first accept total number which user want to enter. Then user has to enter numbers one by one.

Program will identify even and Odd numbers and store their total count in variable.

// Program Name: Accept n numbers from user and then identify even or odd Numbers
#include<stdio.h>
 
void main()
{
 int totalNum, i, ary[100];
 int eNoCnt = 0, oNoCnt = 0;
 
 printf("\n\t Enter the Size of an Array (total numbers)  :  \t");
 scanf("%d", &totalNum);
 
 printf("\n\t Enter the Numbers to identify even numbers\t");
 for(i = 0; i < totalNum; i++)
 {
   scanf("%d", &ary[i]);
 }
  
 for(i = 0; i < totalNum; i ++)
 {
   if(ary[i] % 2 == 0)
   {
     eNoCnt++;
   }
   else
   {
     oNoCnt++;
   }
 }
  
 printf("\n\t Total Number of Even Numbers are = %d ", eNoCnt);
 printf("\n\t Total Number of Odd Numbers are = %d ", oNoCnt);
}


	 Enter the Size of an Array (total numbers)  :  	6



	 Enter the Numbers to identify even numbers	1

2

3

4

5

6



	 Total Number of Even Numbers are = 3 

	 Total Number of Odd Numbers are = 3 

Program to print Odd Numbers till user input

// Program to print odd numbers from 1 to n
#include <stdio.h>
int main() {
    int range;
    printf("Enter range of number to print odd numbers");
    scanf("%d",&range);
      printf("Odd Numbers from 1 to %d are \n",range);
    for(int i =1;i<=range;i++)
    {
        if (i%2 != 0)
        printf("\t%d",i);
    }
    return 0;
}

Output

Enter range of number to print odd numbers   15
Odd Numbers from 1 to 15 are 
	1	3	5	7	9	11	13	15

Program to Print Even Numbers till User Input

// Program to print even numbers from 1 to n
#include <stdio.h>
int main() {
    int range;
    printf("Enter range of number to print even numbers  ");
    scanf("%d",&range);
      printf("Even numbers from  1 to %d are \n",range);
    for(int i =1;i<=range;i++)
    {
        if (i%2 ==  0)
        printf("\t%d",i);
    }
    return 0;
}

Output

Enter range of number to print even numbers  15
Even numbers from  1 to 15 are 
	2	4	6	8	10	12	14