move exercises and lectures into subfolders
This commit is contained in:
20
Exercises/C7/Getchar/getchar_example.c
Normal file
20
Exercises/C7/Getchar/getchar_example.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// declare variable
|
||||
char c;
|
||||
|
||||
printf("Input a character: ");
|
||||
// Wait for a kepypress, store result in c
|
||||
c = getchar();
|
||||
|
||||
// Display on the screen using printf
|
||||
printf ("The charcter pressed was %c\n", c);
|
||||
|
||||
// Display the charcter using putchar()
|
||||
putchar(c);
|
||||
|
||||
return 0; // Exit from main
|
||||
}
|
28
Exercises/C7/Scanf1/scanf_example_1.c
Normal file
28
Exercises/C7/Scanf1/scanf_example_1.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int a; // Declare some variables
|
||||
float f;
|
||||
|
||||
// Use printf to prompt the use to enter an integer
|
||||
printf ("Please enter an integer\n");
|
||||
|
||||
// use scanf with %d to read into 'a'
|
||||
scanf ("%d",&a); // note the important &
|
||||
|
||||
// And display on the screen
|
||||
printf ("The value you entered for a is %d\n", a);
|
||||
|
||||
// Use printf to prompt the use to enter an float
|
||||
printf ("Please enter a float\n");
|
||||
|
||||
// use scanf with %f to read into 'f'
|
||||
scanf ("%f",&f); // note the important &
|
||||
|
||||
// And display on the screen
|
||||
printf ("The value you entered for f is %f\n", f);
|
||||
|
||||
return 0; // Exit from main
|
||||
}
|
28
Exercises/C7/Scanf2/scanf_example_2.c
Normal file
28
Exercises/C7/Scanf2/scanf_example_2.c
Normal file
@@ -0,0 +1,28 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Declare some variables
|
||||
int a,b,c;
|
||||
float f,g;
|
||||
|
||||
// Use printf to prompt the use to enter 3 integers
|
||||
printf ("Please enter three integer\n");
|
||||
|
||||
// use scanf with %d to read into a, b and c
|
||||
scanf ("%d %d %d",&a, &b, &c); // note the important &
|
||||
|
||||
// And display on the screen
|
||||
printf ("The values entered were %d %d %d\n", a, b, c);
|
||||
|
||||
// Use printf to prompt the use to enter an float
|
||||
printf ("Please enter two floats\n");
|
||||
|
||||
// use scanf with %f to read into f ang g
|
||||
scanf ("%f %f",&f, &g); // note the important &
|
||||
|
||||
// And display on the screen
|
||||
printf ("The value you entered were %f and %f \n", f,g);
|
||||
|
||||
return 0; // Exit from main
|
||||
}
|
11
Exercises/C7/ex2.c
Normal file
11
Exercises/C7/ex2.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
float r;
|
||||
printf("Enter radius: ");
|
||||
scanf("%f", &r);
|
||||
|
||||
printf("Area of circle: %f\n", M_PI*r*r);
|
||||
printf("Volume of sphere: %f\n", M_PI*r*r*r*4.0/3.0);
|
||||
}
|
13
Exercises/C7/ex3.c
Normal file
13
Exercises/C7/ex3.c
Normal file
@@ -0,0 +1,13 @@
|
||||
#include <stdio.h>
|
||||
#include <math.h>
|
||||
|
||||
int main() {
|
||||
float radius, height;
|
||||
|
||||
printf("Enter radius: ");
|
||||
scanf("%f", &radius);
|
||||
printf("Enter height: ");
|
||||
scanf("%f", &height);
|
||||
|
||||
printf("Surface area: %f\n", 2*M_PI*radius*radius + 2*M_PI*radius*height);
|
||||
}
|
11
Exercises/C7/ex4.c
Normal file
11
Exercises/C7/ex4.c
Normal file
@@ -0,0 +1,11 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char name[200] = { 0 };
|
||||
|
||||
printf("What is your name? ");
|
||||
scanf("%s", name);
|
||||
|
||||
printf("Hello %s\n", name);
|
||||
|
||||
}
|
15
Exercises/C7/ex5.c
Normal file
15
Exercises/C7/ex5.c
Normal file
@@ -0,0 +1,15 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main() {
|
||||
char name[200] = { 0 };
|
||||
int age = 0;
|
||||
|
||||
printf("What is your name? ");
|
||||
scanf("%s", name);
|
||||
|
||||
printf("What is your age? ");
|
||||
scanf("%ud", &age);
|
||||
|
||||
printf("Hello %s\nYou are %d years old\n", name, age);
|
||||
|
||||
}
|
19
Exercises/C7/string_with_gets.c
Normal file
19
Exercises/C7/string_with_gets.c
Normal file
@@ -0,0 +1,19 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
int main()
|
||||
{
|
||||
// Declare variable - maximum 99 characters
|
||||
char str[100];
|
||||
|
||||
// Prompt for text
|
||||
printf("enter some text\n");
|
||||
|
||||
// Store intput in str
|
||||
gets(str);
|
||||
|
||||
// Display a message on the screen
|
||||
printf("you entered : %s\n", str);
|
||||
|
||||
// Exit from main
|
||||
return 0;
|
||||
}
|
20
Exercises/C7/string_with_scanf.c
Normal file
20
Exercises/C7/string_with_scanf.c
Normal file
@@ -0,0 +1,20 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Declare some variables
|
||||
char name[50];
|
||||
|
||||
// Wait for a kepypress, store result in c
|
||||
printf ("Please enter your name");
|
||||
|
||||
// read in using scanf with %s
|
||||
scanf ("%s",name);
|
||||
|
||||
// Display on the screen using printf
|
||||
printf ("Hello %s\n", name);
|
||||
|
||||
// Exit from main
|
||||
return 0;
|
||||
}
|
Reference in New Issue
Block a user