Summary of small problems in C language learning! ! !

String to Integer

#include <stdlib.h>
...
char cs[] = "123";
int num = atoi(cs);

delimited string

#include<string.h>
...
char str[] = "I am student";
char *ptr;  
ptr = strtok(str, " "); 
while (ptr != NULL) {  
     print("%s",ptr);
     //输出每一个字符/字符串
     ptr = strtok(NULL, " ");  
}  

The console determines the number of input integers, and counts the number of odd and even numbers after inputting integers

int n ,num,odd=0,even=0;
    scanf("%d",&n);
    for(int i =0;i<n;i++){
        scanf("%d",&num);
        if((num%2)!=0) {
                ++odd;
            }
            else {
                ++even;
            }
    }
    printf("%d %d",odd,even);

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325980715&siteId=291194637