Lecture memo for the second half of the year (C language) Part 1

Introduction

Since there was a C language lecture in the second half of the year, I will summarize the code I wrote there. This is the teaching material used. Basic programming in C language

environment

MacBook Pro(Retina, 13-inch, Late 2013) Xcode Version 10.2.1 When I asked the professor in charge by e-mail, I started using it because I was told that it was okay.

Issues and codes

I was thinking of displaying Hello World! At first, but I didn't. Omitted because of that. The task is basically that the outline of the program has already been created and each person thinks about the ??? part and completes it.

The first

Omitted because it was only environment construction and operation check Windows people are TeraPad? It seems that he is using something like that.

Second time

  1. Create a program that stores the last 3 digits of your student ID number and your friend's student ID number in a variable and displays the value obtained by adding them.

Enter your student ID number appropriately.

#include <stdio.h>

int main()
{
    int a, b, c;
    
    a = 1;
    b = 2;
    c = a + b;
    printf( "My student ID number%d,Student ID number of a friend%d,total%d\n", a, b, c );
    
    return 0;
}

Execution result


My student ID number 1,Student ID number 2 of a friend,3 in total
Program ended with exit code: 0

Suddenly, I have faced a tough task for those who have no friends. Is it Akahara? I endured.

3rd

It was a lecture about operators.

python


#include <stdio.h>

int main()
{
    int a = 2 ;
    
    a += 10 ;  // a = a + 10  
    a += 1 ;   // a = a + 1 
    a %= 5 ;   // a = a % 5
        
    printf("%d\n", a) ;
    
    return 0;
    
}

Execution result


3
Program ended with exit code: 0
  1. Pay attention to the type of the variable and create the following program. (a). Prepare variables that represent the radius and pi, and substitute the values. (b). Prepare a variable that represents the circumference, and calculate using the variable in 1. (c). Display the circumference calculated in (b)

python


#include <stdio.h>
#include <float.h>
int main()
{
    double r = 2.0; //r is the radius
    double pi = 3.14; //pi is pi
    double l = 2*r*pi; //l is the circumference
    printf("The circumference is%g\n", l);
    
    return 0;
}

Execution result


The circumference is 12.56
Program ended with exit code: 0

Finally

This article is up to this point for the time being. ~~ It's not that it's a hassle to put together. ~~ I think there will be more lectures using C language in the future, so I will summarize them so that I will not forget them.

Recommended Posts