write a c program to print magic square of order n when n>3
and n is odd?
Answer / v p p
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j=1,k,n,a[22][22],p,q,r,count=0;
clrscr();
A:
printf("Enter No. Of Rows Or Columns(Should Be Odd) : ");
scanf("%d",&n);
printf("\n");
if(n%2==0)
{
printf("Enter Odd No.s Only\n\n");
goto A;
}
k=(n+1)/2;
for(p=1;p<=n;p++)
{ for(q=1;q<=n;q++)
{
a[p][q]=NULL;
}
}
for(i=1;i<=(n*n);i++)
{
if(a[j][k]==NULL)
{
a[j][k]=i;
}
else
{
j=j+2;
k--;
if(j==n+2)
j=2;
if(k==0)
k=n;
if(j==0)
j=n;
if(k==n+1)
k=1;
a[j][k]=i;
}
j--;
k++;
if(j==0)
j=n;
if(k==n+1)
k=1;
}
for(p=1;p<=n;p++)
{
for(q=1;q<=n;q++)
{
r=a[p][q];
while(r>0)
{
r=r/10;
count++;
}
if(count==1)
printf(" 0%d",a[p][q]);
else
printf(" %d",a[p][q]);
if(q%n==0)
printf("\n\n");
count=0;
}
}
for(p=1;p<=n;p++)
{
for(q=1;q<=n;q++)
{
}
}
getch();
}
| Is This Answer Correct ? | 18 Yes | 6 No |
Ramesh’s basic salary is input through the keyboard. His dearness allowance is 40% of basic salary, and house rent allowance is 20% of basic salary. Write a program to calculate his gross salary.
Which one is taking more time and why ? :/home/amaresh/Testing# cat time.c //#include <stdio.h> #define EOF -1 int main() { register int c; while ((c = getchar()) != EOF) { putchar(c); } return 0; } ------------------- WIth stdio.h:- :/home/amaresh/Testing# time ./time_header hi hi hru? hru? real 0 m4.202s user 0 m0.000s sys 0 m0.004s ------------------ Witout stdio.h and with #define EOF -1 =================== /home/amaresh/Testing# time ./time_EOF hi hi hru? hru? real 0 m4.805s user 0 m0.004s sys 0 m0.004s -- From above two case , why 2nd case is taking more time ?
To Write a C program to remove the repeated characters in the entered expression or in entered characters(i.e) removing duplicates. String contains only lowercase characters ['a'-'z']
Is it possible to print a name without using commas, double quotes,semi-colons?
main() { char str1[] = {‘s’,’o’,’m’,’e’}; char str2[] = {‘s’,’o’,’m’,’e’,’\0’}; while (strcmp(str1,str2)) printf(“Strings are not equal\n”); }
#define DIM( array, type) sizeof(array)/sizeof(type) main() { int arr[10]; printf(“The dimension of the array is %d”, DIM(arr, int)); }
Set up procedure for generating a wire frame display of a polyhedron with the hidden edges of the object drawn with dashed lines
main() { int i=_l_abc(10); printf("%d\n",--i); } int _l_abc(int i) { return(i++); }
To reverse an entire text file into another text file.... get d file names in cmd line
main() { int i=1; while (i<=5) { printf("%d",i); if (i>2) goto here; i++; } } fun() { here: printf("PP"); }
enum colors {BLACK,BLUE,GREEN} main() { printf("%d..%d..%d",BLACK,BLUE,GREEN); return(1); }
code of a program in c language that ask a number and print its decremented and incremented number.. sample output: input number : 3 321123