#include<stdio.h> #include<conio.h> void main() { unsigned int n=0; unsigned int i=0; clrscr(); while(n<=10) { if(i%15==0 && i%27==0) { printf("%d\n",i); ++n; } ++i; } getch(); }
if
i
#include<stdio.h> #include<conio.h> void main() { unsigned int n=0; unsigned int i=0,x[10]; clrscr(); while(n<=10) { if(i%15==0 && i%27==0) { x[n]=i; //i value is saved in array of x[n] ++n; } ++i; } //print array elements for(n=1;n<=10;n++) printf("\t %d",x[n]); getch(); }
#include<stdio.h> #include<conio.h> //define the constant as a macro instead of hard-coding it #define MAX_N 10 void main() { unsigned int n = 0; unsigned int i = 0; //the array will contain MAX_N + 1 elements unsigned int arr[MAX_N + 1]; clrscr(); while (n <= MAX_N) { if(i % 15 == 0 && i % 27 == 0) { //store the result in the array at the current position arr[n] = i; ++n; } ++i; } //prints the array for (i = 0; i <= MAX_N; i++) printf("%d\n", arr[i]); getch(); }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)