So is it 8 or 15?
printf ("%-15u", state); or
printf ("%-8u", state);
So is it 8 or 15?
printf ("%-15u", state); or printf ("%-8u", state);
printf is declared in stdio.hFormat specifier for an integer value is %d.
#include#includevoid main(){unsigned long int num;int i=0;clrscr();printf("Enter the digit\n");scanf("%lu",&num);while(num!=0){num=num/10;++i;}printf("Length=%d",i);getch();}
#include<stdio.h> unsigned sum_row (unsigned* sq, const unsigned width, const unsigned row) { unsigned sum, col; sum = 0; for (col=0; col<width; ++col) sum += sq[row*width+col]; return sum; } unsigned sum_col (unsigned* sq, const unsigned width, const unsigned col) { unsigned sum, row; sum = 0; for (row=0; row<width; ++row) sum += sq[row*width+col]; return sum; } unsigned sum_diag (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=0; row<width; ++row, ++col) sum += sq[row*width+col]; return sum; } unsigned sum_anti (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=width-1; row<width; ++row, --col) sum += sq[row*width+col]; return sum; } bool is_magic (unsigned* sq, const unsigned width) { unsigned magic, row, col; magic = sum_row (sq, width, 0); for (row=1; row<width; ++row) if (magic!=sum_row(sq, width, row)) return false; for (col=0; col<width; ++col) if (magic!=sum_col(sq, width, col)) return false; if (magic!=sum_diag(sq, width)) return false; if (magic!=sum_anti(sq, width)) return false; return true; } int main () { const unsigned width = 3; unsigned a[width][width] {{2,7,6},{9,5,1},{4,3,8}}; unsigned row, col; printf ("Square:\n\n"); for (row=0; row<width; ++row) { for (col=0; col<width; ++col) { printf ("%d ", a[row][col]); } printf ("\n"); } printf ("\n"); if (is_magic((unsigned*)&a, width)) printf ("The square is magic with a magic constant of %d\n", sum_row((unsigned*)&a, 3,0)); else printf ("The square is not magic\n"); return 0; }
main() { int i,n,p,v; printf("enter the number of terms"); scanf("%d",&n); for(i=2;i<=n;i++) { for(j=1;j<i;j++) { if(i%j==0) v=v+1; else p=p+1; } } printf("%d is a prime",i); } check this out
int number; int i=2; while (i<number) { if(number%i==0) { printf("Not a prime no."); break; } else printf("number entered is prime"); getch(); }
%u is a printf format specifier that says to take the next argument and display it as an unsigned decimal number, assuming standard integer length.
printf is declared in stdio.hFormat specifier for an integer value is %d.
unsigned reverse (unsigned n) { unsigned r = 0; while (n) { r *= 10; r += (n%10); n /= 10; } return r; } bool is_palindrome (unsigned n) { return n == reverse (n); } int main () { unsigned num; printf ("Enter a number: "); scanf ("%d", num); if (is_palindrome (num)) printf ("%d is a palindrome\n"); else printf ("%d is not a palindrome\n"); return 0; }
#include#includevoid main(){unsigned long int num;int i=0;clrscr();printf("Enter the digit\n");scanf("%lu",&num);while(num!=0){num=num/10;++i;}printf("Length=%d",i);getch();}
#include<stdio.h> #include<math.h> bool is_prime (unsigned num) { if (num<2) // 0 and 1 are composite return false; if (!(num%2)) // 2 is the only even prime return num==2; const unsigned max_div = sqrt (num) + 1; for (unsigned div=3; div<max_div; div+=2) { if (!(num%div)) // the number is composite return false; } // if we get this far, the number is prime return true; } int main (void) { unsigned num; printf ("Enter a positive integer: "); scanf ("%u", &num); printf ("\n%u is %s\n", num, is_prime (num) ? "prime" : "composite"); return 0; }
It is a flag character that precedes the variable type place holder. %d %i Decimal signed integer. %o Octal integer. %x %X Hex integer. %u Unsigned integer. %c Character. %s String. See below. %f double %e %E double. %g %G double. %p pointer. %% %. No argument expected.
#include<stdio.h> unsigned sum_row (unsigned* sq, const unsigned width, const unsigned row) { unsigned sum, col; sum = 0; for (col=0; col<width; ++col) sum += sq[row*width+col]; return sum; } unsigned sum_col (unsigned* sq, const unsigned width, const unsigned col) { unsigned sum, row; sum = 0; for (row=0; row<width; ++row) sum += sq[row*width+col]; return sum; } unsigned sum_diag (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=0; row<width; ++row, ++col) sum += sq[row*width+col]; return sum; } unsigned sum_anti (unsigned* sq, const unsigned width) { unsigned sum, row, col; sum = 0; for (row=0, col=width-1; row<width; ++row, --col) sum += sq[row*width+col]; return sum; } bool is_magic (unsigned* sq, const unsigned width) { unsigned magic, row, col; magic = sum_row (sq, width, 0); for (row=1; row<width; ++row) if (magic!=sum_row(sq, width, row)) return false; for (col=0; col<width; ++col) if (magic!=sum_col(sq, width, col)) return false; if (magic!=sum_diag(sq, width)) return false; if (magic!=sum_anti(sq, width)) return false; return true; } int main () { const unsigned width = 3; unsigned a[width][width] {{2,7,6},{9,5,1},{4,3,8}}; unsigned row, col; printf ("Square:\n\n"); for (row=0; row<width; ++row) { for (col=0; col<width; ++col) { printf ("%d ", a[row][col]); } printf ("\n"); } printf ("\n"); if (is_magic((unsigned*)&a, width)) printf ("The square is magic with a magic constant of %d\n", sum_row((unsigned*)&a, 3,0)); else printf ("The square is not magic\n"); return 0; }
main() { int i,n,p,v; printf("enter the number of terms"); scanf("%d",&n); for(i=2;i<=n;i++) { for(j=1;j<i;j++) { if(i%j==0) v=v+1; else p=p+1; } } printf("%d is a prime",i); } check this out
void print_num_as_word (unsigned num) { switch (num) { case 0: printf ("zero"); break; case 1: printf ("one"); break; case 2: printf ("two"); break; case 3: printf ("three"); break; case 4: printf ("four"); break; case 5: printf ("five"); break; case 6: printf ("six"); break; case 7: printf ("seven"); break; case 8: printf ("eight"); break; case 9: printf ("nine"); break; } }
int number; int i=2; while (i<number) { if(number%i==0) { printf("Not a prime no."); break; } else printf("number entered is prime"); getch(); }
i ll give you the logic and if u know a lil bit of c u can make it.. accept the two no's from user==> use scanf if the 1st no is 2 print that using printf like>>1st no is prime then put a nested for loop i.e. for (int i = 1st no ;i <=2nd no; i ++) { for (int j= 2 ; j <i; j++) now check for condition if i/j==0 then printf not prime else printf prime so its over u see.....
main() { int i, n; printf("Enter a positive integer\n"); scanf("%d", &n); for(i=1;i<=n;i++) printf("%d-",i); printf("\b\n"); }