priyanshu911
BAN USER/*
Excel columns are labelled alphabetically in length-lexicographic order, i.e., A, B, C, ..., Z, AA, AB, ....
Given the 1-based numeric index of a column, return the corresponding label.
Example 1:
1
Output 1:
A
Example 2:
54
Output 2:
BB
*/
#include<stdio.h>
#include<conio.h>
#define MAX 30
void main()
{
int i, input,newi;
int q,r,arr[MAX],count;
printf("Enter the index of column : ");
scanf("%d",&input);
count = 0;
do{
r = input%26;
if(r == 0){
newi = input-1;
q = newi/26;
r = (newi%26)+1;
input = newi/26;;
}
else{
q = input/26;
r = input%26;
input = input/26;
}
arr[count] = r;
count++;
}while(input > 0);
for(i=count-1; i>=0; i--){
printf("%c",(char)(arr[i]+64));
}
getch();
}
This is for general matrix
i.e. it would work for any (n x m) matrix
#include<stdio.h>
#include<conio.h>
#define MAX 30
void display(int[MAX][MAX],int,int);
void spiral (int[MAX][MAX],int,int);
void main()
{
int i,j,n,m,a[MAX][MAX];
printf("Enter the number of rows : ");
scanf("%d",&n);
printf("Enter the number of columns : ");
scanf("%d",&m);
printf("Enter the Matrix Elements ");
for(i=0;i<n;i++){
printf("\n\nRow : %d \n",(i+1));
for(j=0;j<m;j++){
scanf("%d",&a[i][j]);
}
}
printf("Entered Matrix is : \n");
display(a,n,m);
printf("\n\nSpiral Matrix output: \n\n");
spiral(a,n,m);
getch();
}
void display(int a[MAX][MAX],int n, int m)
{
int i,j;
for(i=0;i<n;i++){
printf(" \n__________________________________________________\n");
for(j=0;j<m;j++){
printf("%d\t",a[i][j]);
}
}
printf(" \n__________________________________________________\n");
}
void spiral(int a[MAX][MAX],int n, int m)
{
int i,j,temp;
int count = 0;
for(i=0; i<n; i++,count++){
// 1. Horizontal upper row
for(j=count; j<(m-count); j++){
printf("%d ", a[i][j]);
}
// 2. Vertical right column
for(temp = (i+1); temp<(n-count); temp++){
printf("%d ", a[temp][j-1]);
}
temp--;
//reverse the above 2-steps
// 3.Horizontal lower row
for(j=j-2; j>=(count); j--){
printf("%d ", a[temp][j]);
}
// 4. Vertical left column
j++;
for(temp = temp-1; temp>count; temp--){
printf("%d ", a[temp][j]);
}
printf("\n");
}
}
Output :
Entered Matrix is :
____________________
1 2 3 4 5 6 7
____________________
8 9 10 11 12 13 14
____________________
15 16 17 18 19 20 21
____________________
22 23 24 25 26 27 28
____________________
29 30 31 32 33 34 35
____________________
Spiral Matrix output:
1 2 3 4 5 6 7 14 21 28 35 34 33 32 31 30 29 22 15 8
9 10 11 12 13 20 27 26 25 24 23 16
17 18 19 18 17
25
.
- priyanshu911 August 02, 2013