#include %26lt;stdio.h%26gt;
int main(void){
int j,Lim,i,flag;
printf("Please enter a limit number : ");
scanf("%d",%26amp;Lim);
for(i=2;i%26lt;=Lim;i++){
for(j=2;j%26lt;=i-1;j++){
if(i%j==0){
flag=0;
break;}
flag=1;
}
if(flag==1)
printf("%5",i, "%5d",i);
}
return 0;
}
this is my code it get a number and print prime numbers between 2 and entered number i have to print that numbers in this vay
3 5 7 and in each row must be ten it means if we enter 100 the first line will continue till 31 then next line will start with 37 i try \t but it changes spacing to 8
Table drawing in c++?
Your printf statement is wrong. The printf function takes a format string followed by 0 or more values to use for % directives in the format string.
To get you started, try changing your printf to this:
printf("%5d", i);
Then look into using \n in your printf (or a separate printf). If you want to print 10 primes per line, you'll need to keep track of how many primes have been printed on the current line, and when that number reaches 10 it is time to do this:
printf("\n");
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment