Functii de intrare si iesire in C
1.3. Programul citeste numele si prenumele unei persoane ( cu gets() ), apoi afiseaza ( cu putchar() ) initialele respective pe un rand, fiecare initiala fiind urmata de un punct, executa newline ( cu putchar( '\n' ) ), afiseaza ( cu puts() ) mesajul "Pentru a continua actionati o tasta oarecare" si asteapta ( cu getch() ) actionarea unei taste.
#include
#include
void main(void)
{ char s[15], n[15];
gets(s);
gets(n);
clrscr();
putchar(s[0]);
putchar('.');
putchar(' ');
putchar(n[0]);
putchar('.');
putchar('\n');
puts("Pentru a continua actionati o tasta oarecare");
getch();
}
1.9. Programul afiseaza in zecimal, octal si hexazecimal constanta 12345 definita prin directiva #define.
#include
#include
#define a 12345
void main(void)
{clrscr();
printf("zecimal=%d\n",a);
printf("octal=%o\n",a);
printf("hexazecimal=%0x\n",a);
getch();
}
1.10. Programul afiseaza in zecimal, octal si hexazecimal constanta 123456789 definita prin directiva #define.
#include
#include
#define constanta 123456789l
void main(void)
{clrscr();
printf("zecimal=%ld\n",constanta);
printf("octal=%lo\n",constanta);
printf("hexazecimal=%0lx\n",constanta);
getch();
}
1.14. Programul citeste ( cu scanf() ) un caracter ASCII si apoi afiseaza ( cu printf() ) caracterul citit si codul lui.
#include
#include
void main(void)
{char a;
scanf("%c",&a);
printf("cod %d",a);
getch();
}
1.17. Programul citeste ( cu scanf() ) un numar intreg zecimal format din cel mult patru cifre si apoi afiseaza ( cu printf() ) numarul citit in zecimal, octal si hexazecimal.
#include
#include
void main(void)
{ int a;
clrscr();
scanf ("%d",&a);
printf("zecimal %d\n",a);
printf("octal %o\n",a);
printf("hexazecimal %0x\n",a);
getch();
}
1.21. Programul determina cu operatorul sizeof si afiseaza cata memorie este rezervata pentru fiecare tip de date ( char, signed char, unsigned char, short, signed short, unsigned short, int, signed int, unsigned int, long int, long signed int, long unsigned int, float, double, long double ).
void main(void)
{
char c;
signed char sc;
unsigned char uc;
short sh;
signed short ssh;
unsigned short ush;
int i;
signed int si;
unsigned int ui;
long int li;
long signed int lsi;
long unsigned int lui;
float f;
double d;
long double ld;
printf("bytes memorie:\n");
printf("char %d\n", sizeof(c));
printf("signed char %d\n", sizeof(sc));
printf("unsigned char %d\n", sizeof(uc));
printf("short %d\n", sizeof(sh));
printf("signed short %d\n", sizeof(ssh));
printf("unsigned short %d\n", sizeof(ush));
printf("int %d\n", sizeof(i));
printf("signed int %d\n", sizeof(si));
printf("unsigned int %d\n", sizeof(ui));
printf("long int %d\n", sizeof(li));
printf("long signed int %d\n", sizeof(lsi));
printf("long unsigned int %d\n", sizeof(lui));
printf("float %d\n", sizeof(f));
printf("double %d\n", sizeof(d));
printf("long double %d\n", sizeof(ld));
getch();
}
#include
#include
void main(void)
{ char s[15], n[15];
gets(s);
gets(n);
clrscr();
putchar(s[0]);
putchar('.');
putchar(' ');
putchar(n[0]);
putchar('.');
putchar('\n');
puts("Pentru a continua actionati o tasta oarecare");
getch();
}
1.9. Programul afiseaza in zecimal, octal si hexazecimal constanta 12345 definita prin directiva #define.
#include
#include
#define a 12345
void main(void)
{clrscr();
printf("zecimal=%d\n",a);
printf("octal=%o\n",a);
printf("hexazecimal=%0x\n",a);
getch();
}
1.10. Programul afiseaza in zecimal, octal si hexazecimal constanta 123456789 definita prin directiva #define.
#include
#include
#define constanta 123456789l
void main(void)
{clrscr();
printf("zecimal=%ld\n",constanta);
printf("octal=%lo\n",constanta);
printf("hexazecimal=%0lx\n",constanta);
getch();
}
1.14. Programul citeste ( cu scanf() ) un caracter ASCII si apoi afiseaza ( cu printf() ) caracterul citit si codul lui.
#include
#include
void main(void)
{char a;
scanf("%c",&a);
printf("cod %d",a);
getch();
}
1.17. Programul citeste ( cu scanf() ) un numar intreg zecimal format din cel mult patru cifre si apoi afiseaza ( cu printf() ) numarul citit in zecimal, octal si hexazecimal.
#include
#include
void main(void)
{ int a;
clrscr();
scanf ("%d",&a);
printf("zecimal %d\n",a);
printf("octal %o\n",a);
printf("hexazecimal %0x\n",a);
getch();
}
1.21. Programul determina cu operatorul sizeof si afiseaza cata memorie este rezervata pentru fiecare tip de date ( char, signed char, unsigned char, short, signed short, unsigned short, int, signed int, unsigned int, long int, long signed int, long unsigned int, float, double, long double ).
void main(void)
{
char c;
signed char sc;
unsigned char uc;
short sh;
signed short ssh;
unsigned short ush;
int i;
signed int si;
unsigned int ui;
long int li;
long signed int lsi;
long unsigned int lui;
float f;
double d;
long double ld;
printf("bytes memorie:\n");
printf("char %d\n", sizeof(c));
printf("signed char %d\n", sizeof(sc));
printf("unsigned char %d\n", sizeof(uc));
printf("short %d\n", sizeof(sh));
printf("signed short %d\n", sizeof(ssh));
printf("unsigned short %d\n", sizeof(ush));
printf("int %d\n", sizeof(i));
printf("signed int %d\n", sizeof(si));
printf("unsigned int %d\n", sizeof(ui));
printf("long int %d\n", sizeof(li));
printf("long signed int %d\n", sizeof(lsi));
printf("long unsigned int %d\n", sizeof(lui));
printf("float %d\n", sizeof(f));
printf("double %d\n", sizeof(d));
printf("long double %d\n", sizeof(ld));
getch();
}