Skip to content

Instantly share code, notes, and snippets.

@ricardosiri68
Last active March 23, 2016 20:36
Show Gist options
  • Save ricardosiri68/3c4189f8d16d9a6f4298 to your computer and use it in GitHub Desktop.
Save ricardosiri68/3c4189f8d16d9a6f4298 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int main(int argc, char **argv)
{
int a, b, c;
a = 13;
b = a + 12;
printf("%d %d\n", a, b);
c = a + b;
a = a + 11;
printf("a = %d b = %d c = %d\n", a, b, c);
return 0;
}
#include <stdio.h>
int main(int argc, char **argv)
{
int a = 75;
printf(" $ %d |\n", a);
printf(" $ %5d |\n", a);
printf(" $ %-5d |\n", a);
printf(" $ %05d |\n", a);
return 0;
}
#include <stdio.h>
int remanents_9()
{
/**
* Give the value of (a) 39 % 7 (b) 88 % 4 (c) 100 % 11 (d) -25 % 9
*/
char out_format[8] = "|%3d|\n";
int a = 39 % 7;
int b = 88 % 4;
int c = 100 % 11;
int d = -25 % 9;
printf("#09 remanentes\n");
printf(out_format, a);
printf(out_format, b);
printf(out_format, c);
printf(out_format, d);
return 0;
}
int divisions_10()
{
/**
* Give the value of (a) 39 / 7 (b) 88 / 4 (c) 100 / 11 (d) -25 / 9
*/
char out_format[8] = "|%3d|\n";
int a = 39 / 7;
int b = 88 / 4;
int c = 100 / 11;
int d = -25 / 9;
printf("\n#10 divisiones\n");
printf(out_format, a);
printf(out_format, b);
printf(out_format, c);
printf(out_format, d);
return 0;
}
int sum_11()
{
/**
* Write a statement that prints the value of the int variable sum, right
* justified in a field width of 6.
*/
char out_format[8] = "|%5d|\n";
int sum = 10 + 40;
printf("\n#11 sum\n");
printf(out_format, sum);
return 0;
}
int rightmost_12()
{
/**
* You are required to print the values of the int variables b, h, and n.
* Write a statement that prints b with its rightmost digit in column 10,
* h with its rightmost digit in column 20, and n with its rightmost digit
* in column 30.
*/
int b = 10;
int h = 123;
int n = -2345;
printf("\n#12 rightmost\n");
printf("%-10d%-10d%-10d|\n", b, h, n);
return 0;
}
int rightmost_13()
{
/**
* Write statements that print the values of b, h, and n lined up one
* below the other with their rightmost digits in column 8.
*/
char out_format[7] = "%-8d|\n";
int b = 10;
int h = 123;
int n = -2345;
printf("\n#13 rightmost\n");
printf(out_format, b);
printf(out_format, h);
printf(out_format, n);
return 0;
}
int scientific_notation_14()
{
/**
* Using scientific notation, write the number 345.72 in four different
* ways.
*/
float n = 345.72;
printf("\n#14 scientific_notation\n");
printf("%6.3f x 10²\n", n / 10);
printf("%6.3f x 10³\n", n / 100);
printf("%6.3f x 10⁴\n", n / 1000);
printf("%6.3f x 10⁵\n", n / 10000);
return 0;
}
int decimal_places_15()
{
/**
* Write a statement that prints the value of the double variable total to
* 3 decimal places, right justified in a field width of 9.
*/
float total = 1234.123;
printf("\n#15 decimal places\n");
printf("%9.3f\n", total);
return 0;
}
int rightmost_float_16()
{
/**
* You need to print the values of the float variables a, b, and c to 1
* decimal place. Write a statement that prints a with its rightmost
* digit in column 12, b with its rightmost digit in column 20, and c with
* its rightmost digit in column 32.
*/
char out_format[32] = "%11.1f%19.1f%31.1f\n";
float a = 123.4;
float b = 567.8;
float c = 910.1;
printf("\n#16 rightmost_float\n");
printf(out_format, a, b, c);
return 0;
}
int rightmost_double_18()
{
/**
* Write statements to print the values of 3 double variables a, b, and c,
* to 2 decimal places, The values must be printed one below the other,
* with their rightmost digits in column 12.
*/
char out_format[36] = "%12.2f%12.2f%12.2f\n";
float a = 123.45;
float b = 657.91;
float c = 112.13;
printf("\n#18 rightmost double\n");
printf(out_format, a, b, c);
}
int nearest_whole_number_19()
{
/**
* How can you print the value of a double variable, rounded to the
* nearest whole number?
*/
double a = 12.9;
double b = 12.5;
double c = 12.1;
printf("\n#19 nearest_whole_number\n");
printf("a = %2.0f b = %2.0f c = %2.0f\n", a, b, c);
}
int main(int argc, char **argv)
{
remanents_9();
divisions_10();
sum_11();
rightmost_12();
rightmost_13();
scientific_notation_14();
decimal_places_15();
rightmost_float_16();
rightmost_double_18();
nearest_whole_number_19();
return 0;
}
#include <stdio.h>
int main() {
char out_format[] = "%3d %-3d\n";
int a = 15;
int b = 24;
printf(out_format, b - a + 7, b - (a + 7));
printf(out_format, b - a - 4, b - (a - 4));
printf(out_format, b % a / 2, b % (a / 2));
printf(out_format, b * a / 2, b * (a / 2));
printf(out_format, b / 2 * a, b / (2 * a));
}
#include <stdio.h>
int main() {
int max_int, min_int;
max_int = 2147483713;
min_int = 2147483649;
}
#include <stdio.h>
int main() {
int a, s;
printf("Ingresar la longitud de un lado:");
scanf("%d", &s);
a = s * s;
printf("El area del cuadrado es %d\n" , a);
}
#include <stdio.h>
int main() {
printf("Bienvenido a Trinidad & Tobago\n");
}
#include <stdio.h>
int main() {
printf("Where the is without fear\n");
printf("And the head is held high\n");
}
#include <stdio.h>
int main() {
int a, b, sum;
a = 14;
b = 25;
sum = a + b;
printf("%d + %d = %d\n", a, b, sum);
}
#include <stdio.h>
#include <string.h>
int copiar() {
char name[50];
strcpy(name, "Alicia en el pais de las maravillas");
printf("Hola, %s\n", name);
}
int concatenar() {
char name[35] = "Alicia";
char last[23] = "pais de las maravillas";
strcat(name, " en el ");
strcat(name, last);
printf("Hola, %s\n", name);
}
int main() {
copiar();
concatenar();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment