#include <stdio.h>
int main(void){
int age;
float assets;
char pet[30];// string
printf("Enter your age, assets, and favorite pet.\\n");
#include <stdio.h>
int main(void)
{
int n;
printf("Please enter three integers:\\n");
scanf("%*d %*d %d", &n);
#include <stdio.h>
int main(void)
{
char fname[40];
char lname[40];
printf("Enter your first name: ");
#include <stdio.h>
double power(double n, int p); // ANSI prototype
int main(void)
{
double x, xpow;
#include <stdio.h>
int main( void )
{
int lower, upper, index;
int square, cube;
printf("Enter starting integer: ");
#include <stdio.h>
#define SIZE 8
int main( void )
{
int vals[SIZE];
int i;
printf("Please enter %d integers.\\n", SIZE);
#include <stdio.h>
#include <stdbool.h>
void flush_input_buffer(void);
int main(void){
bool prime_flag;
#include <stdio.h>
#include <ctype.h>
#define STOP 0
int main(void){
int even_count = 0, even_sum = 0, odd_count = 0, odd_sum = 0;
读取下限和上限整数,计算从下限的平方到上限的平方的所有整数的平方和,并显示结果。
#include <stdio.h>
int main(void)
{
long upper = -1, lower=0;
int reads;
do{
printf("Enter lower and upper integer limits (in that order): ");
#include <stdio.h>
int main(void){
int sum, count, max_count;
sum = 0;
count = 1;
printf("How many squares would you like to sum? ");
如果输入为5,则输出从5到15。
#include <stdio.h>
int main(void)
{
int input;
int i = 0;
printf("Enter an integer: ");
#include <stdio.h>
#include <stdlib.h>
void print(const int array[], int limit);
void sort(int array[], int limit);
编写一个将二进制字符串转换为数字值的函数。
#include <stdio.h>
int convertBinaryStringToInt(const char * string);
以下符号表示整数类型的范围限制。
类型
最低限制
最高限制
char
CHAR_MIN
CHAR_MAX
short
如果将F附加到数字文字,则该数字将被视为浮点数。如果将L附加到数字文字,则该数字将变为长双精度数。对于整数类型,U后缀表示无符号,L表示长整数。类型后缀可以是上下两种情况。例如,F和f都指定浮点常量。
转换说明符有两部分:
第一个字符是百分号(%),第二个是一个特殊字符,告诉程序如何转换数据。
要打印变量的内容,请使用printf()函数并指一些新格式选项。
#include <stdio.h>
以下代码声明了两个变量:一个整数和一个字符数据类型。创建两个变量后,代码会将它们初始化为特定值。\\0称为NULL字符。
字符数据类型是整数值的表示形式,数字作为字符代码。例如,字符代码90代表字母Z。
浮点数包括有符号和无符号的小数和小数。
有符号包括正数和负数。无符号数字只能包含正值。
#include <stdio.h>
#define MAXLINE 1000
long htoi(char s[]);
int main(void) {
int len;
char line[MAXLINE] = "0Xdead1234";
#include <stdio.h>
int main(void)
{
int a, b;
a = 5;
b = 2;/* line 7 */
b = a;/* line 8 */
a = b;/* line 9 */
#include <stdio.h>
int main(void)
{
int a, b;
a = 5;
b = 2;/* line 7 */
b = a;/* line 8 */
a = b;/* line 9 */
这里是一些例子。
数字值
指数表示法
1,000,000,000
1.0e9
123,000
1.23e5
322.56
3.2256e2
0.000056
#include <stdio.h>
#include <inttypes.h> // supports portable types
int main(void){
int32_t me32;// me32 a 32-bit signed variable
#include <stdio.h>
int main(void){
char ch;
printf("Please enter a character.\\n");
scanf("%c", &ch);/* user inputs character */
#include <stdio.h>
int main(void)
{
unsigned int un = 3000000000; /* system with 32-bit int */
short end = 200;/* and 16-bit short*/
#include <stdio.h>
int main(void)
{
int i = 3147483647;
unsigned int j = 9294967999;
printf("%d %d %d\\n", i, i+1, i+2);
#include <stdio.h>
int main(void)
{
long int a;
long b;
short int c;
short d;
unsigned int e;
unsigned f;