Δημοσιεύτηκε: 27 Ιούλ 2011, 19:25
migf1 έγραψε:Για δείξε τον κώδικα που έχεις γράψει και σου κάνει τα παραπάνω.
- Κώδικας: Επιλογή όλων
#include <stdio.h>
#include <stdlib.h>
char *s_get(char *s, size_t len)
{
char *cp;
for (cp=s; (*cp=getc(stdin)) != '\n' && (cp-s) < len-1; cp++ );
*cp = '\0';
return s;
}
int main() {
char c[1],i1[1],i2[1],f1[1],f2[1],l1[1],l2[1];
printf("Insert a char: ");
scanf("
fflush(stdin);
printf("\nYou inserted %c",c);
printf("\nInsert an int: ");
s_get(i1,1);
printf("\nInsert the second int: ");
s_get(i2,1);
printf("\n%d * %d = %d",(atoi(i1)),(atoi(i2)),((atoi(i1)) * (atoi(i2))));
printf("\nInsert a float: ");
s_get(f1,1);
printf("\nInsert the second float: ");
s_get(f2,1);
printf("\n%f * %f = %f",(atof(f1)),(atof(f2)),((atof(f1)) * (atof(f2))));
return 0;
}