Ну-да, ну-да)) Классическая ошибка при обмене двух переменных.u=v;
v=u;
А вообще нужен один цикл от 0 до N/2. Меняется элемент I с элементом Length - I, вот и все
Модераторы: Hawk, Romeo, Absurd, DeeJayC, WinMain
Ну-да, ну-да)) Классическая ошибка при обмене двух переменных.u=v;
v=u;
somewhere писал(а):Ну-да, ну-да)) Классическая ошибка при обмене двух переменных.
А вообще нужен один цикл от 0 до N/2. Меняется элемент I с элементом Length - I, вот и все
Код: Выделить всё
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#define N 200
struct NumberInfo
{
long int num;
char conv[42];
}
numbers[N];
int i;
void show(int num, char *result,int count);
void convertNumber(int, char *);
int main (void)
{
printf("Number to convert? '0'-end" );
for (i=0;i<N;i++)
{
scanf("%li",&numbers[i].num);
if(numbers[i].num =='\0')
break;
else
convertNumber(numbers[i].num, numbers[i].conv);
}
show(numbers[i].num, numbers[i].conv,i);
return 0;
}
void convertNumber(int num, char *result)
{
int base=3;
int k=0,n;
do
{
result[k]=(num%base)+'0';
k++;
num=num/base;
}
while(num!=0);
//int count=0;
/*char *u=result;;
while(*u!='\0')
{
u++;
}
//printf("%d",(int)(u-result));
char l;
for(l=0;l<=((int)(u-result));l++)
{
l=*(result+u);
*(result+u)=(*(result+u))-l);
//printf("%c",);
}*/
}
void show(int num, char *result,int count)
{
int i;
printf("\n\t===============================================\n");
printf("\t| | |\n");
for(i=0;i<count;i++)
{
printf("\t| %4.li | %s |\n ", numbers[i].num,numbers[i].conv);
}
printf("\t===============================================\n");
}
Код: Выделить всё
#include <stdio.h>
void reverse(char* str)
{
if (str[0] == '\0' || str[1] == '\0')
{
// If the string is empty or has got one character
// then it should not be reversed
return;
}
// At the beginning both indexes are zero
int left = 0, right = 0;
// Move 'right' to the end of the string
while (str[right + 1] != '\0') ++right;
// Move 'left' forward and 'right' backward, exchanging appropriate symbols
// Cycle works till left-right correspondence is correct ('left' is really left and 'right' is really right)
for (; left < right; left++, right--)
{
int temp = str[align=left];
str[align=left] = str[align=right];
str[align=right] = temp;
}
}
int main()
{
char str[] = "ykketnoM oemoR";
reverse(str);
printf("%s\n", str);
return 0;
}
Код: Выделить всё
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#define N 200
// структура, хранящая информацию об одном числе
struct NumberInfo
{
long int num; // само число
char conv[42]; // сконвертированное число
}
numbers[N];
// массив структур, хранящий информацию о всех исходных и сконвертированных числах
int i;
void show(int, char* ,int );
void convertNumber(int, char *);
void reverse(char* );
int main (void)
{
printf("Number to convert? '0'-end" );
for (i=0;i<N;i++)
{
scanf("%li",&numbers[i].num);
if(numbers[i].num =='\0')
break;
else
convertNumber(numbers[i].num, numbers[i].conv);
}
show(numbers[i].num, numbers[i].conv,i);
return 0;
}
void convertNumber(int num, char *result)
{
int base=3;
int k=0,n;
do
{
numbers[i].conv[k]=(num%base)+'0';
k++;
num=num/base;
}
while(num!=0);
reverse(result);
}
void reverse(char* result)
{
if (result[0] == '\0' || result[1] == '\0')
{
// If the string is empty or has got one character
// then it should not be reversed
return;
}
// At the beginning both indexes are zero
int left = 0, right = 0;
// Move 'right' to the end of the string
while (result[right + 1] != '\0')
++right;
// Move 'left' forward and 'right' backward, exchanging appropriate symbols
// Cycle works till left-right correspondence is correct ('left' is really left and 'right' is really right)
for (; left < right; left++, right--)
{
int temp = result[align=left];
result[align=left] = result[align=right];
result[align=right] = temp;
}
//printf("%s\n", result);
}
void show(int num, char *result,int count)
{
int i;
printf("\n\t===============================================\n");
printf("\t| | |\n");
for(i=0;i<count;i++)
{
printf("\t| %4.li | %s |\n ", numbers[i].num,numbers[i].conv);
}
printf("\t================================================\n");
}
Код: Выделить всё
#include "stdafx.h"
#include <stdio.h>
#include <string.h>
#define N 200
// структура, хранящая информацию об одном числе
struct NumberInfo
{
long int num; // само число
char conv[42]; // сконвертированное число
}
numbers[N];
int i;
void show(int, char* ,int );
void convertNumber(int, char *);
void reverse(char* );
int main (void)
{
printf("Number to convert? '0'-end" );
for (i=0;i<N;i++)
{
scanf("%li",&numbers[i].num);
if(numbers[i].num =='\0')
break;
else
convertNumber(numbers[i].num, numbers[i].conv);
}
show(numbers[i].num, numbers[i].conv,i);
return 0;
}
void convertNumber(int num, char *result)
{
int base=3;
int k=0,n;
do
{
numbers[i].conv[k]=(num%base)+'0';
k++;
num=num/base;
}
while(num!=0);
reverse(result);
}
void reverse(char* result)
{
if (result[0] == '\0' || result[1] == '\0')
{
// If the string is empty or has got one character
// then it should not be reversed
return;
}
// At the beginning both indexes are zero
int left = 0, right = 0;
// Move 'right' to the end of the string
while (result[right + 1] != '\0')
++right;
// Move 'left' forward and 'right' backward, exchanging appropriate symbols
// Cycle works till left-right correspondence is correct ('left' is really left and 'right' is really right)
for (; left < right; left++, right--)
{
int temp = result[align=left];
result[align=left] = result[align=right];
result[align=right] = temp;
}
//printf("%s\n", result);
}
void show(int num, char *result,int count)
{
int i;
printf("\n\t===============================================\n");
printf("\t| | |\n");
for(i=0;i<count;i++)
{
printf("\t| %4.li | %s |\n ", numbers[i].num,numbers[i].conv);
}
printf("\t================================================\n");
}