c語言4-16 輸入一個整數值,顯示該整數值以下的所有奇數


 

1、while語句

#include <stdio.h>

int main(void) { int i; puts("please input an integer."); do { printf("i = "); scanf("%d", &i); if (i <= 0) puts("the range of i is : > 0 "); } while (i <= 0); while (i > 0) { if (i % 2) printf("%d ", i); i--; } return 0; }

 

2、while語句

#include <stdio.h>

int main(void) { int i = 1, j; puts("please input an integer."); do { printf("j = "); scanf("%d", &j); if (j <= 0) puts("the range of j is : > 0"); } while (j <= 0); while (i <= j) { printf("%d ", i); i += 2; } return 0; }

 

3、while語句

#include <stdio.h>

int main(void) { int i = 1, j; puts("please input an integer."); do { printf("j = "); scanf("%d", &j); if (j <= 0) puts("the range of j is : > 0 "); } while (j <= 0); while (i <= j) { if (i % 2) printf("%d ", i); i++; } return 0; }

 

4、for語句

#include <stdio.h>

int main(void) { int i; puts("please input an integer."); do { printf("i = "); scanf("%d", &i); if (i <= 0) puts("the range of i is: > 0 "); } while (i <= 0); while (i > 0) { if (i % 2) printf("%d ", i); i--; } putchar('\n'); return 0; }

 

5、for語句

#include <stdio.h>

int main(void) { int i, j; puts("please input an integer."); do { printf("j = "); scanf("%d", &j); if (j <= 0) puts("the range of j is > 0 "); } while (j <= 0); for (i = 1; i <= j; i+=2) { printf("%d ", i); } putchar('\n'); return 0; }

 

6、for語句

#include <stdio.h>

int main(void) { int i, j; puts("please input an integer."); do { printf("j = "); scanf("%d", &j); if (j <= 0) puts("the range of j is: > 0"); } while (j <= 0); for (i = 1; i <= j; i++) { if (i % 2) printf("%d ", i); } putchar('\n'); return 0; }

 

7、do語句

#include <stdio.h>

int main(void) { int i; puts("please input an integer."); do { printf("i = "); scanf("%d", &i); if (i <= 0) puts("the range of i is : > 0"); } while (i <= 0); do { if (i % 2) printf("%d ", i); i--; } while (i > 0); putchar('\n'); return 0; }

 

8、do語句

#include <stdio.h>

int main(void) { int i = 1, j; puts("please input an integer."); do { printf("j = "); scanf("%d", &j); if (j <= 0) puts("the range of j is > 0"); } while (j <= 0); do { printf("%d ", i); i += 2; } while (i <= j); putchar('\n'); return 0; }

 

9、do語句

#include <stdio.h>

int main(void) { int i = 1, j; puts("please input an integer."); do { printf("j = "); scanf("%d", &j); if (j <= 0) puts("the range of j is : > 0 "); } while (j <= 0); do { if (i % 2) printf("%d ", i); i++; } while (i <= j); putchar('\n'); return 0; }

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM