Tutorialspoint

Check for EVEN or ODD program in C

c

#include <stdio.h>

void main()
{
    int n;
    
    printf(" enter a positive number: ");
    scanf("%d",&n );
    
    if ((n%2)==0)
    {
        printf("the number is even");
    }
    else 
    {
        printf("the number is odd");
    }
}

Hello world program in Perl

#
# Hello World Program in Perl
#
print "Hello World!\n";

A simple Bootstrap example

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>Bootstrap 101 Template</title>

    <!-- Bootstrap -->
    <link href="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css" rel="stylesheet">

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
  </head>
  <body>
    <h1>Hello, world!</h1>

    <!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
    <!-- Include all compiled plugins (below), or include individual files as needed -->
    <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
  </body>
</html>

2. 前20项之和

public class Text20 { 
    //分析:抓住分子与分母的变化规律。 分子分母都是斐波那契数列,递推公式的得出较为简单
 public static void main(String[] args) { 
  float fenmu=1;float fenzi=2; 
  float sum=fenzi/fenmu; 
  float t=0; 
  for(int i=1;i<20;i++) 
  { 
   t=fenmu+fenzi; 
   fenmu=fenzi; 
   fenzi=t; 
   sum=sum+fenzi/fenmu; 
   System.out.println(sum); 
  } 
 } 
} 

C program to input score and print grade using switch case statement

c

//C program to input score and print grade using switch case statement 
#include <stdio.h>

int main(void)
{
    int score;
    char grade;

    printf("Enter score: ");
    scanf("%d", &score);

    switch (score) {
    case 10:
        printf("case 10\n");
    case 9:
        printf("case 9\n");
    case 8:
        grade = 'A';
        break;
    case 7:
        printf("case 7\n");
    case 6:
        grade = 'B';
        break;
    case 5:
        grade = 'C';
        break;
    default:
        grade = 'F';
    }

    printf("Grade is %c.\n", grade);
    return 0;
}

Printing text in Pascal

Program HelloWorld(output);
begin
  writeln('Hello, world!');
end.

Printing multiple line text in Pascal

{Class:4B
Name:Kuok Chun Cho}
Program MyFirst;
begin
   writeln('welcome to pascal programming!');
   writeln('This is my first program!');
   writeln('Hey guys!')
end.

Java selection sort example (passing arguments from command line)

public class SelSort{
	public static void main(String[] args)
	{
		int n,i;
		n=args.length;
		int[] a=new int[n];
		for(i=0;i<n;i++)
		{
		          a[i]=Integer.parseInt(args[i]);
		}
		selectionSort(a);
		printArray(a);
	 }
        static void printArray(int[] x)
       {
	   int i,j, n=x.length;
	   for(i=0;i<n;i++)
	  	System.out.println(x[i]+ "\t");
	}
 	static void selectionSort(int[] x)
	{   
	    int i,j, temp, n;
	    n=x.length;
	    for(i=0;i<=n-2;i++)
	 	 for(j=i+1;j<=n-1;j++)
 		        if(x[i]>x[j])
		        {
		        	temp=x[i];
		        	x[i]=x[j];
			x[j]=temp;
		        }	
        }
}

C language example for command line arguments count

c

#include <stdio.h>

int main( int argc, char *argv[] )  {

   if( argc == 2 ) {
      printf("The argument supplied is %s\n", argv[1]);
   }
   else if( argc > 2 ) {
      printf("Too many arguments supplied.\n");
   }
   else {
      printf("One argument expected.\n");
   }
   
   return 0;
}

SQLite example to create a table, insert record and commit the transactions

BEGIN TRANSACTION;

/* Create a table called NAMES */
CREATE TABLE NAMES(Id integer PRIMARY KEY, Name text);

/* Create few records in this table */
INSERT INTO NAMES VALUES(1,'Tom');
INSERT INTO NAMES VALUES(2,'Lucy');
INSERT INTO NAMES VALUES(3,'Frank');
INSERT INTO NAMES VALUES(4,'Jane');
INSERT INTO NAMES VALUES(5,'Robert');
COMMIT;

/* Display all the records from the table */
SELECT * FROM NAMES;

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.