예제 #1
0
int main()
{
	int a[5];
	int i,j,temp;
	for(i=0;i<5;i++)
	{
		a[i] = 10 - i;
	}
	prints("Array before sorting:\n");
	for(i=0;i<5;i++)
	{
		printi(a[i]);
		prints("\n");
	}
	for(i=0;i<5;i++)
	{
		for(j=0;j<5-i;j++)
		{
			if(a[j] > a[j+1])
			{
				temp = a[j];
				a[j] = a[j+1];
				a[j+1] = temp;
			}
		}
	}
	prints("Array after sorting\n");
	for(i=0;i<15;i++)
	{
		printi(a[i]);
		prints("\n");
	}
	return 0;
}
int main()
{
    int arr[20];
    int i, n, ep;

    prints("Enter the number of integers n: ");
    n = readi(&ep);
    prints("You entered n = ");
    printi(n);
    prints("\n");

    prints("Enter n integers: ");
    for(i=0; i<n; i++) arr[i] = readi(&ep);
    sort(arr,n);

    prints("The n integers in ascending order: ");
    for(i=0; i<n; i++)
    {
        printi(arr[i]);
        prints(" ");
    }
    prints("\n");

    return 0;
}
예제 #3
0
파일: app.c 프로젝트: CZ-NIC/turris-updater
static void
printa (PicoSAT * picosat, int partial)
{
  int max_idx = picosat_variables (picosat), i, lit, val;

  assert (bhead == buffer);

  for (i = 1; i <= max_idx; i++)
    {
      if (partial)
	{
	  val = picosat_deref_partial (picosat, i);
	  if (!val)
	    continue;
	}
      else
	val = picosat_deref (picosat, i);
      lit = (val > 0) ? i : -i;
      printi (lit);
    }

  printi (0);
  if (bhead > buffer)
    bflush ();
}
int main()
{
    int a,b;
    int *e;
    
    prints("***********************Some random outputs!!*************************\n");
    
    b = 3;
    e = &b;

    prints("Passing pointers to function f!\n");
    prints("Value passed to function: ");
    printi(b);
    prints("\n");
    a = f(e);
    prints("Value returned from function s is: ");
    printi(a);
    prints("\n");
    
    prints("Read an integer!!");
    prints("\n");
    b = readi(e);
    prints("The integer that was read is:");
    printi(b);
    prints("\n");
    
    return 0;
}
예제 #5
0
void main()
{
	// chaines pour l'affichage
	char s1[5] = {'t', 'a', 'b', '(','\0'};
	char s1f[3] = {')', '=','\0'};
	char s2[11] = {'n', 'o', 'n', ' ', 't', 'r', 'i', 'e', ':', '\n', '\0'};
	char s3[7] = {'t', 'r', 'i', 'e', ':', '\n', '\0'};
	char s4[8] = {'d', 'a', 'n', 's', ' ', 'i', 'f', '\0'};
	char s5[10] = {'d', 'a', 'n', 's', ' ', 'e', 'l', 's', 'e', '\0'};

	//  tableaux de même taille
	int tab1[5] = {18, 8, 24, 36, 7};
	int tab2[5] = {3, 2, 6, 120, 6};
	// petite addition qui prend plus de 10 registres
	tab2[2] = (1+(2+(3+(4+(5+(6+(7+(8+(9+(10+(11+12)))))))))));
	
	// un nombre et 2 pointeurs
	int nb = 42;
	int * p1 = &nb;
	int ** p2 = &p1;

	// on fait le pgcd sur les 2 tableaux
	int i;
	for(i=0; i<5; i=i+1)
	{
		tab[i] = pgcd(tab1[i],tab2[i]);
		print(s1);
		printi(i);
		print(s1f);
		printi(tab[i]);
		printc('\n');
		printc('\n');
	}
	
	// on affiche les pgcd pas triés
	print(s2);
	afficheTABLEAU();
	
	// on trie les pgcd (tri sélection)
	triSelection(5);
	
	// on affiche les pgcd triés
	print(s3);
	afficheTABLEAU();
	
	// test avec evaluation paresseuse
	if(1!=1 && 1==1)
	{
		print(s4);
	}
	else
	{
		print(s5);
	}
	printc('\n');
	printi(**p2);
}
예제 #6
0
int main(){
  int mat[100][100];
  char *c="\nPlease Enter Dimension of matrixr: ";
  char *d="\nPlease Enter the matrix row-wise: ";
  char *e="\nThe Entered matrix is: ";
  char *f="\nThe Transposed matrix is: ";
  char *sp=" ";
  char *ne="\n";
  prints(c);
  int err,n,i,j,k;
  n = readi(&err);
  int temp;
  prints(d);
  for (i = 0; i < n; ++i)
  {
    for (j = 0; j < n; ++j)
    {
      mat[i][j]=readi(&err);
    }
  }
  prints(e);
  prints(ne);
  for (i = 0; i < n; ++i)
  {
    prints(ne);
    for (j = 0; j < n; ++j)
    {
      printi(mat[i][j]);
      prints(sp);
    }
  }
  prints(f);
  prints(ne);

  for (i = 0; i < n; ++i)
  {
    for (j = i+1; j < n; ++j)
    {
      temp=mat[j][i];
      mat[j][i]=mat[i][j];
      mat[i][j]=temp;
    }
    
  }
  for (i = 0; i < n; ++i)
  {
    prints(ne);
    for (j = 0; j < n; ++j)
    {
      printi(mat[i][j]);
      prints(sp);
    }
  }
  prints(ne);
return 0;
}
int main() {
    prints("Fibonacci Number using Matrix Multiplication O(logn)\n");
    int i;
    for(i = 0; i < 45; i++) {
        printi(i); prints(".\t"); 
        printi(getFib(i)); 
        prints("\n");
    }
    return 0;
}
예제 #8
0
void affichePGCD(int x, int y)
{
	char s6[6] = {'p','g','c','d','(','\0'};
	print(s6);
	printi(x);
	printc(',');
	printi(y);
	printc(')');
	printc('\n');
}
예제 #9
0
파일: t19.c 프로젝트: ChanderG/c-compiler
int main()
{
  int p[10],a,b;
  b = 7;
  a = 4;
  p[b] = a;
  printi(p[b]);
  printi(b);
  return 0;
}
예제 #10
0
//Hmm... let's try to build a really decent...
//.... in-memory multipilication table!
int main()
{
  int mtable[10][10][10];
  int a;
  int b;
  int c;
  int result;
  for(a = 0;a < 10; a = a + 1)
    {
      for(b = 0;b < 10; b = b + 1)
	{

	  for(c = 0;c < 10; c = c + 1)
	    {
	      
	      mtable[a][b][c] = a*b*c;
		   
	       
	    }
	}
      
    }
  //now let's try some math!
  result = mtable[2][5][6];
  //expect 60
  printi(result);
  printn();
 

  result = mtable[5][6][2];
  //expect 60
  printi(result);
  printn();

  result = mtable[4][3][5];
  //expect 60
  printi(result);
  printn();
 
  result = mtable[2][5][6] * mtable[5][6][2];
  //expect 3600
  printi(result);
  printn();

  result = mtable[1][1][7];
  //expect 60
  printi(result);
  printn();
 
 
  


}
예제 #11
0
파일: printf.c 프로젝트: anchorz/dosprg
void printi(int i)
{
	int a=i;

	if (i<0) {
		putchar('-');
		a=-(a%10);
		printi(-(i/10));
	}
	if (i>9) {
		printi(i/10);
		a=i%10;
	}
	putchar('0'+ a );
}
예제 #12
0
파일: t0.c 프로젝트: ChanderG/c-compiler
int main()
{
  int p[10],a,b;
  //p[a] = 3;
  b = 7;
  a = 4;
  //a = p[b];
  p[b] = a;
  printi(p[b]);
  printi(b);
  a = 3;
  a = p[b];
  printi(a);
  return 0;
}
예제 #13
0
파일: q7.c 프로젝트: eokeeffe/C-code
int print_some_integers()//simply print the integers
{
	int loop_count=0,number;
	int array[30];
	
	printf("How many numbers are you entering 0-30\r\n");
	number=get_number();
	
	if(number > 30 && number < 0)
	{
		main();
	}
	else
	{
		while(loop_count < number)
		{
			printf("Please enter a number\r\n");
			array[loop_count]=get_number();
			loop_count++;
		}
		
		printi(number,array);
		return 0;
	}
}
//A test file to test the library functions written
int main()
{
    int n,err=0;
    prints("Write the integer n:");
    n = readi(&err);
    if(err!=ERR)
    {
        prints("The integer read is : ");
        printi(n);
    }
    else
    {
        prints("Wrong Input\n");
    }
    float x;

    prints("\nEnter the decimal number: ");
    err = readf(&x);
    if(err==OK)
    {
        prints("The floating number is :");
        printd(x);
    }
    else
    {
        prints("Wrong Input\n");
    }
    prints("\n");
    return 0;
}
예제 #15
0
파일: for.c 프로젝트: steshaw/babycc
int main()
{
    int i;

    for (i=0; i<10; i = i + 1) {
        printi(i);
        println();
    }
}
예제 #16
0
void afficheTABLEAU(){
	int i;
	for(i=0;i<5;i=i+1)
	{
		printi(tab[i]);
	}
	printc('\n');
	printc('\n');
}
int main(){
	int n1,result;int *ep;int temp;
	prints("Program to calculate factorial of a number:\n");
	prints("Enter n1:");
	n1=readi();
	result=factorial(n1);
	prints("The factorial of the given number is:");
	printi(result);
	prints("\n");
	return 0;
}
/* Driver program to test above function */
int main()
{
  int arr[50], n, i, err;
  prints("Longest Increasing Subsequence\n");
  prints("Enter number of elements ( < 50)\n");
  n = readi(&err);
  prints("Enter array elements\n");
  for(i = 0; i < n; i++) arr[i] = readi(&err);
  prints("Length of LIS is "); printi(lis( arr, n ) ); prints("\n");
  return 0;
}
void printMat(int a[][2]) {
    int i, j;
    for(i = 0; i < 2; i++) {
        for(j = 0; j < 2; j++) {
            printi(a[i][j]);
            prints(" ");
        }
        prints("\n");
    }
    prints("\n");
}
int main()
{
	prints("Enter a number whose factorial you want to know: ")	;
	int n,err;
	n = readi(&err);
	int fact;
	fact = factorial(n);
	prints("The value is: ");
	printi(fact);
	prints("\n");

	prints("Enter a number n whose fibonacci(n) you want to know: ");
	n = readi(&err);
	int fib;
	prints("The value is: ");
	fib = fibonacci(n);
	printi(fib);
	prints("\n");
	return 0;

}
예제 #21
0
파일: cli.c 프로젝트: idaohang/gpsr-1
static void pprinti(const char *line )
{
	int g;

	if ( sscanf( line, "%*s %d", &g )!=EOF ) {
		if ( 0 < g && g <= status.curgen ) {
			printi( run[g-1].besti );
		} else
			fprintf( stderr, "individual must lie in [1,%d]\n", status.curgen );
	} else
		p_error( "no individual" );
}
int main(){
	int a[10];
	int i=1,j,x,t;int m,n;

	prints("Enter 10 numbers\n");
	for(i=0;i<10;i=i+1){
		x=readi();
		a[i]=x;
	}

	prints("You entered:\n");
	for(i=0;i<10;i=i+1){
		j=a[i];
		printi(j);prints("\n");
	}
	
	for(i=0;i<10;i=i+1){
		for(j=i+1;j<10;j=j+1){
			m=a[i];
			n=a[j];
			if(m>n){
				a[i]=n;
				a[j]=m;
			}
			else{
				i=i;
			}
			i=i;		
		}
		i=i;
	}
	prints("Sorted array is:\n");
	for(i=0;i<10;i=i+1){
		j=a[i];
		printi(j);prints("\n");
	}
	return 0;
}
예제 #23
0
int
out_write_mjpeg( void )
{
    int err;
    const char str[] =
        "fmfconv created M-JPEG file (http://fuse-emulator.sourceforge.net)\n";

    if( ( err = write_jpeg_img( FALSE, out_header_ok ? NULL : (void *)str ) ) )
        return err;
    out_header_ok = jpeg_header_ok;

    printi( 2, "out_write_mjpeg()\n" );
    return 0;
}
int main()
{
	prints("Enter three numbers whose maximum among them you want to know\n");
	int a,b,c,err;
	prints("Enter the first number: ");
	a = readi(&err);
	prints("Enter the second number: ");
	b = readi(&err);
	prints("Enter the third number: ");
	c = readi(&err);

	int max;
	max = findmax(a,b,c);

	prints("The max value is: ");
	printi(max);
	prints("\n");

	prints("Lets do expression tests:\n");
	prints("a = b*c*a = ");
	a = b*c*a;
	printi(a);
	prints("\n");

	prints("b = a/c = ");
	b = a/c;
	printi(b);
	prints("\n");
	
	prints("c = a%b = ");
	c = a%b;
	printi(c);
	prints("\n");
		
	return 0;
}
예제 #25
0
int
out_write_jpg( void )
{
    int err;
    const char str[] =
        "fmfconv created JPEG file (http://fuse-emulator.sourceforge.net)\n";

    if( ( err = write_jpeg_img( TRUE, (void *)str ) ) ) return err;
    jpeg_header_ok = 0;
    jpeg_destroy_compress( &cinfo );

    printi( 2, "out_write_jpg()\n" );

    return 0;
}
예제 #26
0
// params: int pid
void
proc_info(int argc, char *argv[])
{
  int             pid, err, i;
  pcbinfo         res;

  pid = stoi(get_arg(argv, 1));
  err = get_proc_info(pid, &res);
  if (err == 0)
  {
    print("Information about process pid = ");
    printi(pid);
    print("\n\tname:\t\t\t");
    print(res.name);
    print("\n\tpriority:\t\t");
    printi(res.pri);
    print("\n\tsupervised processes:\t");
    for (i = 0; i < MAXPCB; i++)
    {
      if (res.supervised[i] != -1)
      {
        printi(res.supervised[i]);
        print(" ");
      }
    }
    print("\n\tsupervisor process:\t");
    printi(res.supervisor);
    print("\n\tprocess state:\t\t");
    printi(res.state);
    print("\n\ttime to sleep:\t\t");
    printi(res.sleep);
    print("\n\twaiting for process:\t");
    printi(res.waitfor);
    //print("\n\tlast error:\t\t");
    //printi(res.error);
    printn();
  }
  else
  {
    print("An error occured! (code:");
    printi(err);
    print(")\n");
  }
  exit(0);
}
예제 #27
0
int main()
{
	float x;
	int y;
	prints("Enter a floating point number :");
	if(!readf(&x))
		printd(x);
	else
		prints("Invalid floating point number!");
	prints("\nEnter an integer :");
	if(!readi(&y))
		printi(y);
	else
		prints("Invalid integer!");
	prints("\n");
	return 0;
}
예제 #28
0
int main()
{
	prints("Enter 10 integers to sort:\n");
	int a[10];
	int i;
	int ep;
	for(i = 0; i<10; i++) a[i] = readi(&ep);
	// for(i = 0; i<10; i++) printi(a[i]);
	sort(a,10);
	prints("The sorted integers are:\n");
	for(i = 0; i<10; i++)
	{
		printi(a[i]);
		prints(" ");
	}
	prints("\n");
	return 0;
}
예제 #29
0
static int
out_write_jpegheader( void )
{
    size_t y;

    for( y = 0; y < frm_h; y++ )
        row_pointers[y] = &pix_rgb[ ( greyscale ? 1 : 3 ) * y * frm_w ];

    cinfo.err = jpeg_std_error( &jerr );
    jpeg_create_compress( &cinfo );
    cinfo.image_height = frm_h;
    cinfo.image_width  = frm_w;
    cinfo.input_components = greyscale ? 1 : 3;
    cinfo.in_color_space = greyscale ? JCS_GRAYSCALE : JCS_RGB;
    jpeg_set_defaults( &cinfo );
    cinfo.dct_method = jpg_dctfloat ? JDCT_FLOAT :
                       ( jpg_idctfast ? JDCT_IFAST : JDCT_ISLOW );
    cinfo.optimize_coding = jpg_optimize ? TRUE : FALSE;
    cinfo.smoothing_factor = jpg_smooth < 0 || jpg_smooth > 100 ?
                             0 : jpg_smooth;
    cinfo.write_JFIF_header = TRUE;

    if( out_t != TYPE_JPEG )
        jpeg_set_colorspace( &cinfo, JCS_YCbCr );
    if( greyscale ) /* override AVI YCbCr... */
        jpeg_set_colorspace( &cinfo, JCS_GRAYSCALE );
    if( progressive )
        jpeg_simple_progression( &cinfo );
    jpeg_set_quality( &cinfo,
                      ( jpg_quality < 0 || jpg_quality > 100 ? 75 : jpg_quality ),
                      0 );
    if( out_t == TYPE_AVI )
        jpeg_avi_mem_dest( &cinfo, &mem_dest, &mem_size );
    else
        jpeg_stdio_dest( &cinfo, out );

    if( jpeg_header_ok >= 0 )
        printi( 1, "out_write_jpegheader(): W=%d H=%d\n", frm_w, frm_h );
    jpeg_header_ok = 1;

    return 0;
}
int main()
{
	int a[100];
	int i;
	int j;
	int n;
	int err;
	prints("Enter the total number of integers to sort :");
	n = readi(&err);
	prints("Enter the number one by one:\n");
	for(i=0;i<n;i++)
	{
		a[i] = readi(&err);
	}

	prints("Sorting the array. \n");
	int temp;
	for(i=n;i>0;i--)
	{
		for(j=0;j<i-1;j++)
		{
			if(a[j+1]<a[j])
			{
				temp = a[j];
				a[j] = a[j+1];
				a[j+1]=temp;
			}
		}
	}
	prints("Printing the sorted array. \n");
	for(i=0;i<n;i++)
	{
		printi(a[i]);
		prints(" ");
	}
	prints("\n");

	return 0;


}