#include<stdio.h>intmain(int argc,char*argv[]){int bugs =100;double bug_rate =1.2;printf("You have %d bugs at the imaginary rate of %f.\n",
bugs, bug_rate);long universe_of_defects =1L*1024L*1024L*1024L;printf("The entire universe has %ld bugs.\n",
universe_of_defects);double expected_bugs = bugs * bug_rate;printf("You are expected to have %f bugs.\n",
expected_bugs);double part_of_universe = expected_bugs / universe_of_defects;printf("That is only a %e portion of the universe.\n",
part_of_universe);// this makes no sense, just a demo of something weirdchar nul_byte ='\0';int care_percentage = bugs * nul_byte;printf("Which means you should care %d%%.\n",
care_percentage);return0;}
You have 100 bugs at the imaginary rate of 1.200000.
The entire universe has 1073741824 bugs.
You are expected to have 120.000000 bugs.
That is only a 1.117587e-007 portion of the universe.
Which means you should care 0%.
C语言中的循环
for循环
for(INITIALIZER; TEST; INCREMENTER){
CODE;}
#include<stdio.h>intmain(int argc,char*argv[]){}
#include<stdio.h>intmain(int argc,char*argv[]){int i =0;// go through each string in argv// why am I skipping argv[0]?for(i =1; i < argc; i++){printf("arg %d: %s\n", i, argv[i]);}// let's make our own array of strings char*states[]={"California","Oregon","Washington","Texas"};int num_states =4;for(i =0; i < num_states; i++){printf("state %d: %s\n", i, states[i]);}return0;}
state 0: California
state 1: Oregon
state 2: Washington
state 3: Texas
while循环
#include<stdio.h>intmain(int argc,char*argv[]){// go through each string in argvint i =0;while(i < argc){printf("arg %d: %s\n", i, argv[i]);
i++;}// let's make our own array of strings char*states[]={"California","Oregon","Washington","Texas"};int num_states =4;
i =0;// watch for thiswhile(i < num_states){printf("state %d: %s\n", i, states[i]);
i++;}return0;}
arg 0: c:\Users\17899\openairinterface5g\hello
state 0: California
state 1: Oregon
state 2: Washington
state 3: Texas
if语句
if(TEST){
CODE;}elseif(TEST){
CODE;}else{
CODE;}
#include<stdio.h>intmain(int argc,char*argv[]){int i =0;if(argc ==1){printf("You only have one argument. You suck.\n");}elseif(argc >1&& argc <4){printf("Here's your arguments:\n");for(i =0; i < argc; i++){printf("%s ", argv[i]);}printf("\n");}else{printf("You have too many arguments. You suck.\n");}return0;}