Obračanje znakov...
 
nokaut240 18. mar 2011 17:18:35 Pridružen od:
29. apr 2008
50 objav
8 23 1
#1

Imam program, v katerem vnesem število, napr 12, on mi pa izpiše v dvojiškem 0011, kar seveda ni prav, saj bi moral 1100. Se pravi, je treba te številke obrniti. Pa poskušam, in mi ne rata. Koda je v C-ju.



#include <stdio.h>

#include <stdlib.h>

#include <string.h>



int main(int argc, char *argv[])

{

int vnos;

int x;

char tabela[100];

int i=0;

scanf("%d",&vnos);


while(vnos>0)
{
x=vnos%2;
vnos=vnos/2;
tabela*=x;
printf("%d",x);
}
for(i=strlen(tabela)-1; i>=0; i--)
{
printf("%c",tabela*);
}

}**


všeč(0) ni všeč(0) spam(0)
 
gnome 18. mar 2011 17:35:37 Pridružen od:
27. apr 2010
829 objav
412 47 10
#2

Pred časom smo na faksu delali podobno nalogo.. in to isto težavo sem rešil z klicom metode Array.Reverse (C#). Pogooglaj mogoče za C tudi obstaja..


všeč(0) ni všeč(0) spam(0)
Adobe Commerce/Magento 2 & Laravel + {VueJS/React} razvijalec | Moj #1 resource za Laravel & PHP | Claude Code alternative 10% OFF
 
nokaut240 19. mar 2011 11:31:43 Pridružen od:
29. apr 2008
50 objav
8 23 1
#3

Kako bi lahko izpisal dolžino vnesenega niza ? naprimer če vnesem 100110, mi vrne 6 ? Ker mi vedno zateži zradi charov pa int...


všeč(0) ni všeč(0) spam(0)
 
nokaut240 19. mar 2011 14:14:51 Pridružen od:
29. apr 2008
50 objav
8 23 1
#4

Pa kako sploh izpišeš nek znak v besedi ? Recimo Abeceda rečem izpiši znak[2] in izpiše "e".


všeč(0) ni všeč(0) spam(0)
 
G-force 19. mar 2011 15:16:50 Pridružen od:
31. mar 2008
828 objav
516 60 3
#5

http://www.roseindia.net/c-tutorials/c-string-reverse.shtml




#include <stdio.h>

#include <conio.h>

#include <string.h>

int reverse(int i);

char st[]="Hello World";

void main() {

printf("\nThe string is: %s", st);

reverse(0);

printf("\nReversed string is: %s", st);

getch();

}

int reverse(int i) {

if (i<(strlen(st)/2)) {

char c;

c= st;

st
=st[strlen(st)-i-1];

st[strlen(st)-i-1]=c;

}

return 0;

}**




al pa pač v google vpiši C String reverse...


všeč(0) ni všeč(0) spam(0)
 
 

🔒 Za odgovor na to temo se moraš prijaviti.

Prijavi se