int term;
int main()
{
term = 3 * 5;
printf("Twice %d is %d\n", term, 2*term);
printf("Three times %d is %d\n", term, 3*term);
return (0);
}
#include
float answer; //the result of our calculation
int main()
{
//wrong
answer = 1/3;
printf("The value of 1/3 is %f\n", answer);
//right
answer = 1.0/3.0;
printf("The value of 1/3 is %f\n", answer);
//return 0 if program runs
return(0);
}
#include
float result;
int main()
{
result = 7.0/22.0;
printf("The result is %d\n", result);
//right
printf("The result is %f\n", result);
return(0);
}
#include
char char1;
char char2;
char char3;
int main()
{
char1 = 'A';
char2 = 'B';
char3 = 'C';
printf("%c%c%c reversed is %c%c%c\n", char1, char2, char3, char3, char2, char1);
return(0);
}
#include
float data[5];
float total;
float average;
int main()
{
data[0] = 34.0;
data[1] = 27.0;
data[2] = 45.0;
data[3] = 82.0;
data[4] = 22.0;
total = data[0] + data[1] + data[2] + data[3] + data[4];
average = total / 5.0;
printf("Total %f Average %f\n", total, average);
return(0);
}
#include
#include
char name[30];
int main()
{
strcpy(name, "Sam");
printf("The name is %s\n", name);
return(0);
}
#include
#include
char first[100];
char last[100];
char full_name[200];
int main()
{
strcpy(first, "Steve");
strcpy(last, "Oualline");
strcpy(full_name, first);
//strcat not strcpy!!!
strcat(full_name, " ");
strcat(full_name, last);
printf("The full name is %s\n", full_name);
return (0);
}
#include
#include
char line[100];
int main()
{
printf("Enter a line: ");
fgets(line, sizeof(line), stdin);
printf("The length of the line is: %d\n", strlen(line));
return (0);
}
#include
#include
char line[100];
int main()
{
printf("Enter a line: ");
fgets(line, sizeof(line), stdin);
printf("The length of the line is: %d\n", strlen(line));
return (0);
}
#include
#include
char first[100];
char last[100];
char full[200];
int main() {
printf("Enter first name: ");
fgets(first, sizeof(first), stdin);
//trim off last character
first[strlen(first)-1] = '\0';
printf("Enter last name: ");
fgets(last, sizeof(last), stdin);
//trim off last character
last[strlen(last)-1] = '\0';
strcpy(full, first);
strcat(full, " ");
strcat(full, last);
printf("The name is %s\n", full);
return(0);
}
#include
#define SIZE 10
#define PAR 72
int main(void)
{
int index, score[SIZE];
int sum = 0;
float average;
printf("Enter %d golf scores:\n", SIZE);
for(index = 0; index < SIZE; index++)
{
scanf("%d", &score[index]);
}
printf("The scores read in area as follows:\n");
for (index=0; index
printf("%5d", score[index]); //verify input
}
printf("\n");
for (index = 0; index < SIZE; index++)
{
sum += score[index];
}
average = (float) sum / SIZE;
printf("Sum of scores = %d, average = %.2f\n", sum, average);
printf("That's a handicap of %.0f.\n", average - PAR);
return 0;
}
#include
double power(double n, int p);
int main(void)
{
double x, xpow;
int exp;
printf("Enter a number and the positive integer power");
printf(" to which \n the number will be raised. Enter q to quit.\n");
while (scanf("%lf%d", &x, &exp) == 2)
{
xpow = power(x, exp); //function call
printf("%.3g to the power %d is %.5g\n", x, exp, xpow);
printf("Enter next pair of numbers or q to quit.\n");
}
printf("Hope you enjoyed this power trip -- bye!\n");
return 0;
}
double power(double n, int p) //function definition
{
double pow = 1;
int i;
for (i = 1; i <= p; i++)
{
pow *= n;
}
return pow;
}
Sub Main()
Dim arr As Array
Dim int() As Integer = {12, 16, 20, 24, 28, 32}
arr = CType(int, Array)
Dim byFours() As Integer = {12, 24, 36, 48}
Dim names() As String = {"K", "S", "S", "D", "N"}
Dim miscData() As Object = {"this", 12D, 16UI, "a"}
Dim objArray() As Object
miscData = names
Dim myArray2(10) As Integer
Dim Employees1(,) As Object
Dim Employees(200, 2) As Object
Dim jagged1(9)() As String
Dim jagged2()() As String = New String(9)() {}
Dim myArray1arr As Array
Dim myArray2a As Array = Array.CreateInstance(GetType(Integer), 10)
Dim members() As Integer = {3, 10}
Dim myArray3a As Array = Array.CreateInstance(GetType(Integer), members)
End Sub
Module Tester
Sub Main()
PrintSub(40, 10.5)
PrintSub(38, 21.75)
PrintSub(20, 13)
PrintSub(50, 14)
End Sub
Sub PrintSub(ByVal hours As Double, ByVal wage As Decimal)
Console.WriteLine("The payment is {0:C}", hours * wage)
End Sub
End Module
Class Job
Public Event Meeting()
Public Event Testing(ByVal Temp As Integer)
Public Event Coding(ByVal Room As String, ByVal Duration As Integer)
Public Sub GenerateEvents()
RaiseEvent Meeting()
RaiseEvent Testing(212)
RaiseEvent Coding("VB.NET", 25)
End Sub
End Class
Class MainClass
Shared WithEvents Alarms As New Job()
Shared Sub MyMeeting() Handles Alarms.Meeting
Console.WriteLine("MyMeeting alarm occurred.")
End Sub
Shared Sub MyTesting(ByVal Temp As Integer) Handles Alarms.Testing
Console.WriteLine("MyTesting alarm occurred: Temp : " & Temp)
End Sub
Shared Sub MyCoding(ByVal Room As String, ByVal Duration As Integer) Handles Alarms.Coding
Console.WriteLine("MyCoding alarm occurred: " & Room & " " & Duration)
End Sub
Public Shared Sub Main()
Alarms.GenerateEvents()
End Sub
End Class
<?xml version="1.0"?>
<pet>
<name>Polly Parrot</name>
<age>3</age>
<species>parrot</species>
<parents>
<mother>Pia Parrot</mother>
<father>Peter Parrot</father>
</parents>
</pet>
<?php
if(file_exists('pet.xml'))
{
$xml =simplexml_load_file('pet.xml');
print_r($xml);
} else {
exit('failed to open pet.xml');
}
?>
No comments:
Post a Comment