Monday, 9 February 2009

C program While loop

#include
void main ()
{
int x;
int sum = 0;
printf ("Enter a number \n");
scanf ("%d",&x);
while (x != 0)
{
sum=sum+x;
printf ("Enter a number \n");
scanf ("%d",&x);

}
printf ("%d",sum);
}

Friday, 6 February 2009

String

import java.util.Scanner;
public class operator {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter two number:");

int sum,minus, product, multiple;
float divide;

int x =s.nextInt();
int y =s.nextInt();

System.out.println (" Enter the desire operator | + | - | / | * | % |:");
String operator = s.next();

if (operator.equals( "+"))
{sum = x+y;
System.out.println (" The sum of the 2 number is "+sum);}

else if (operator.equals ("-"))
{minus = x-y;
System.out.println (" The minus of the 2 number is "+minus);}

else if (operator.equals ("/"))
{divide = x/y;
System.out.println (" The divide of the 2 number is "+divide);}

else if (operator.equals ("*"))
{product = x*y;
System.out.println (" The product of the 2 number is "+product);}


else if (operator.equals ("%"))
{multiple = x%y;
System.out.println (" The product of the 2 number is "+multiple);}






}
}

Just for the sake of boring ness

import java.util.Scanner;
public class SwitchCase {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Select 1 - 12 to view the month");

int x =s.nextInt();

switch (x){
case 1:
System.out.println ("January");
break;

case 2:
System.out.println ("Febuary");
break;

case 3:
System.out.println ("March");
break;

case 4:
System.out.println ("April");
break;

case 5:
System.out.println ("May");
break;

case 6:
System.out.println ("June");
break;

case 7:
System.out.println ("July");
break;

case 8:
System.out.println ("August");
break;

case 9:
System.out.println ("September");
break;

case 10:
System.out.println ("October");
break;

case 11:
System.out.println ("November");
break;

case 12:
System.out.println ("December");
break;

default:
System.out.println ("-------------------------");
System.out.println ("|**** | ");
System.out.println ("|**** ( )");
System.out.println ("|**** | ");
System.out.println ("|**** / | \\ ");
System.out.println ("|**** / | \\ ");
System.out.println ("|**** | ");
System.out.println ("|**** / \\ ");
System.out.println ("|**** / \\ ");
System.out.println ("|****");
System.out.println ("-------------------------------------------------------------");
System.out.println ("U have select the wrong number");
break;

}

}
}

Tuesday, 3 February 2009

Switch !!

//*Calculate walt

#include
void main ()
{
int x;
printf ("Please enter the light bulb's wattage in the following list.\n");
printf ("|15|25|40|60|75|100|\n");
scanf ("%d",&x);

switch (x){
case 15:

printf ( "The brightness is 125. \n");
break;

case 25:

printf ( "The brightness is 215. \n");
break;

case 40:

printf ( "The brightness is 500. \n");
break;

case 60:

printf ( "The brightness is 880. \n");
break;

case 75:

printf ( "The brightness is 1000. \n");
break;

case 100:

printf ( "The brightness is 1675. \n");
break;
default:

printf ( "The brightness is -1. \n");
break;
}
}

C programming

#include
void main ()
{
float n;
printf ("Please enter the scale of the earthquake.\n");
scanf ("%f",&n);

if (n<5.0)
printf ("Little or no damage. \n");
else if (n >=5.0 && n < 5.5)
printf ( "Some damage. \n");
else if (n >= 5.5 && n < 6.5)
printf ( "Serious damage: walls may crack or fall. \n");
else if (n>=6.5 && n < 7.5)
printf ("Disaster: house and building may collapse. \n");
else if (n>= 7,5)
printf ("Catastrophe: Most building destroyed.\n");
printf ("GG.COM\n");
printf (" * \n");
printf (" ***** \n");
printf (" ***** \n");
printf (" ******* \n");
printf (" ********* \n");
printf (" ************* \n");
printf (" *************** \n");
printf (" ***************** \n");


}

Coding q3 *JAVA*

To calculate sum,product,average,smallest,largest

import java.util.Scanner;
public class Application {
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter your number:");
int sum, product,smallest,largest;
float average;
int x =s.nextInt();
int y =s.nextInt();
int z =s.nextInt();
sum = x+y+z;
average = (x+y+z)/3;
product = x*y*z;
System.out.println ("The sum of the 3 integer is " +sum);
System.out.println ("The average of the 3 integer is " +average);
System.out.println ("The product of the 3 integer is " +product);
if (x>y && x>z)
System.out.println ("The largest integer is " +x);
else if (y>x && y>z)
System.out.println ("The largest integer is " +y);
else
System.out.println ("The largest integer is " +z);
if (xSystem.out.println ("The smallest integer is " +x);
else if (ySystem.out.println ("The smallest integer is " +y);
else
System.out.println ("The smallest integer is " +z);
}
}

WTF CODE

import java.util.Scanner;
public class q4
{
public static void main (String args[])
{
Scanner s = new Scanner (System.in);
System.out.println (" Enter 5 number:");
int pos = 0,neg = 0,zero = 0,x;
int num1 =s.nextInt();
int num2 =s.nextInt();
int num3 =s.nextInt();
int num4 =s.nextInt();
int num5 =s.nextInt();
if (num1 >0)
pos++;
else if (num1<0)
neg++;
else
zero++;
if (num2 >0)
pos++;
else if (num2<0)
neg++;
else
zero++;
if (num3 >0)
pos++;
else if (num3<0)
neg++;
else
zero++;
if (num4 >0)
pos++;
else if (num4<0)
neg++;
else
zero++;
if (num5 >0)
pos++;
else if (num5<0)
neg++;
else
zero++;
System.out.println ( " The number of posittive numbers are " +pos);
System.out.println ( " The number of negative numbers are " +neg);
System.out.println ( " The number of zero numbers are " +zero);
}
}