fork download
  1. // Lab 8, Working with structs
  2. // Programmer : Maiar Khattab
  3. // Editor(s) used : Code Blocks 13.12
  4. // Compiler(s) used : Code Blocks 13.12
  5.  
  6. #include<iostream>
  7. using std::cout;
  8. using std::endl;
  9.  
  10. #include<cstdlib>
  11.  
  12. //struct def
  13. struct tod
  14. {
  15. int hour;// the hr , 0-23
  16. int minute;// the min, 0-59
  17. int second;//the sec, 0-59
  18. char descr [32];//the description of the time of day
  19.  
  20. };
  21. //void printTod(const tod&);
  22. int main ()
  23. {
  24. cout << "Lab 8, Working With structs\n";
  25. cout << "Programmer: Maiar Khattab\n";
  26. cout << "Editor(s) used: Code Blocks 13.12\n";
  27. cout << "Compiler(s) used: Code Blocks 13.12\n";
  28. cout << "File: " << __FILE__ << endl;
  29. cout << "Complied: " << __DATE__ << " at " << __TIME__ << endl << endl;
  30.  
  31. tod theTime[] = {{12,0,0, "noon"},
  32. {0,0,0," midnight"},
  33. {6,00,00," supper "},
  34. {11,30,0,"bedtime"}};
  35.  
  36. for(int i; i <5; i++)
  37. {
  38. char descr [32];
  39. cout << theTime[i].descr << " is " << theTime[i].hour << ':'
  40. << theTime[i].minute << ":" << theTime[i].second << endl;
  41. }
  42. }
  43.  
  44.  
Success #stdin #stdout 0.01s 5488KB
stdin
import java.util.Random;
import java.util.Scanner;
public class MergeSort
{
public static void main(String[] args)
{
int a[]= new int[100000];
Scanner in = new Scanner(System.in);
long start, end;
System.out.print("Enter the number of elements to be sorted: ");
int n = in.nextInt();
Random rand= new Random();
for(int i=0;i<n;i++)
a[i]=rand.nextInt(2000);
System.out.println("Array elements to be sorted are:");
for(int i=0; i<n; i++)
System.out.println(a[i]);
start=System.nanoTime();
mergesort(a,0,n-1);
end=System.nanoTime();
System.out.println("\nThe sorted elements are: ");
for(int i=0; i<n; i++)
System.out.println(a[i]);
System.out.println("\nThe time taken to sort is "+(end-start)+"ns");
}
static void mergesort(int a[], int low, int high)
{
int mid;
if(low < high)
{
mid = (low+high)/2;
mergesort(a, low, mid);
mergesort(a, mid+1, high);
merge(a, low, mid, high);
}
}
static void merge(int a[], int low, int mid, int high)
{
int i, j, h, k, b[]= new int[100000];
h=low; i=low; j=mid+1;
while((h<=mid) && (j<=high))
{if(a[h] < a[j])
{
b[i]=a[h];
h=h+1;
}
else
{
b[i] = a[j];
j=j+1;
}
i = i+1;
}
if(h > mid)
{
for(k=j; k<=high; k++)
{
b[i]=a[k];
i= i+1;
}
}
else
{
for(k=h;k<=mid;k++)
{
b[i]=a[k];
i= i+1;
}
}
for(k=low; k<= high; k++)
a[k] = b[k];
}
}
stdout
Lab 8, Working With structs
Programmer: Maiar Khattab
Editor(s) used: Code Blocks 13.12
Compiler(s) used: Code Blocks 13.12
File: prog.cpp
Complied: Sep 26 2023 at 08:34:19

noon is 12:0:0
 midnight is 0:0:0
 supper  is 6:0:0
bedtime is 11:30:0
W]1r ��X� is -1454565544:32765:-1370064384