sample
-
-
Save matchey/fecfb4f3ea746cc87c80590078864ae4 to your computer and use it in GitHub Desktop.
情報処理実習 Lecture 6 データ型
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char switch_case(char c) | |
{ | |
return c + ('a' - 'A') * (('A' <= c && c <= 'Z') - ('a' <= c && c <= 'z')); | |
} | |
int main() | |
{ | |
char c; | |
printf("input charactor : "); | |
scanf("%c", &c); | |
printf("%c --> %c\n", c, switch_case(c)); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
char toascii(int number) | |
{ | |
return (unsigned int)number < 10 ? '0' + number : '0'; | |
} | |
int main() | |
{ | |
for(int i=0; i<10; i++){ | |
char c = toascii(i); | |
printf("%c", c); | |
} | |
printf("\n"); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
struct Point3d | |
{ | |
double x; | |
double y; | |
double z; | |
void print(); | |
}; | |
double dot_product(const Point3d& p1, const Point3d& p2) | |
{ | |
return p1.x*p2.x + p1.y*p2.y + p1.z*p2.z; | |
} | |
Point3d cross_product(const Point3d& p1, const Point3d& p2) | |
{ | |
Point3d rtn; | |
rtn.x = p1.y*p2.z - p1.z*p2.y; | |
rtn.y = p1.z*p2.x - p1.x*p2.z; | |
rtn.z = p1.x*p2.y - p1.y*p2.x; | |
return rtn; | |
} | |
void Point3d::print() | |
{ | |
printf("(%.2f, %.2f, %.2f)\n", x, y, z); | |
} | |
int main() | |
{ | |
Point3d p1 = {1, 0, 0}; | |
Point3d p2 = {0, 1, 0}; | |
printf("p1 = "); | |
p1.print(); | |
printf("p2 = "); | |
p2.print(); | |
printf("p1·p2 = %f\n", dot_product(p1, p2)); //⇧ + ⌥ + 9 | |
printf("p1 × p2 = "); | |
cross_product(p1, p2).print(); | |
printf("p2 × p1 = "); | |
cross_product(p2, p1).print(); | |
return 0; | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int atoi(char c) | |
{ | |
int x = c - 0x30; | |
return x; | |
} | |
int cubic(int n) | |
{ | |
return n*n*n; | |
} | |
int main(void) | |
{ | |
char c = 0; | |
printf("Input a number: "); | |
scanf("%c", &c); | |
int n = atoi(c); | |
int x = cubic(n); | |
printf("%d powered by 3 is %d\n", n, x); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment