Форум программистов
 

Восстановите пароль или Зарегистрируйтесь на форуме, о проблемах и с заказом рекламы пишите сюда - alarforum@yandex.ru, проверяйте папку спам!

Вернуться   Форум программистов > IT форум > Помощь студентам
Регистрация

Восстановить пароль

Купить рекламу на форуме - 42 тыс руб за месяц

Ответ
 
Опции темы Поиск в этой теме
Старый 16.01.2015, 20:02   #1
alikalik373
 
Регистрация: 12.11.2014
Сообщений: 6
По умолчанию navichok v C, delenia ochen bolshix chisel

privet vsem, zadacha takaia delenia bolshix chisel, s pomashiu masivvov tipa char, do etogo bilo umnajenia i slojenia eta poluchilos, no s deleniem nikak, nadeius razbiriotes :D
Вложения
Тип файла: txt delenie chisel.txt (1.6 Кб, 139 просмотров)
alikalik373 вне форума Ответить с цитированием
Старый 17.01.2015, 12:49   #2
nikolay1982
Пользователь
 
Регистрация: 31.12.2013
Сообщений: 47
По умолчанию

пробуйте это:
Код:
#include <stdio.h>
#include <string.h>
#define LEN 100

//int sum (char *a, char *b, char *c, char *f);
typedef int boolint;

boolint delenie(char *a,char *b,char *tsel, char *ost); 
int main ()
{
  int l=0;
  //char shesakrebi1[LEN], shesakrebi2[LEN], jami[LEN+1],damxmare[LEN];  //shesakrebi1- eta pervoe cheslo a shesakrebi2- eto vtaroe cheslo, jami-toest summa, damxmare-spomagatelnaia
  char a[LEN], b[LEN], ret[LEN+1],ost[LEN];
  printf("\ndelimoe:");
  scanf("%s",a);
  printf("\ndeliteli:");
  scanf("%s",b);
  //l=sum(shesakrebi1,shesakrebi2,jami,damxmare);
  //l=sum(shesakrebi1,shesakrebi2,jami,damxmare);
  if (delenie(a,b,ret,ost)){
	printf("Tselaia 4asti:%s\n",ret);
  	printf("Ostatok:%s\n",ost);
	}else 
		printf("\nProizoshla osibka. Nelizia deliti na 0 i ispolzovati otretsatelinie 4isla");
  return 0;
}
//a/b=tsel; a % b= ost
boolint delenie(char *a,char *b,char *tsel, char *ost){
	int len_a,len_b;
	int i,j,cur,bi,osti;
	char c,*s,*s2;
	len_a=strlen(a);
	len_b=strlen(b);
	if ((len_a==0)||(len_b==0)) return 0;
	j=0;
	s=a;
	cur=0;
	s2=tsel;
	sscanf(b,"%i",&bi);
	if (bi<=0) return 0;
	while (c=*s++){
	 	cur=cur*10+(c-'0');
		if (cur>=bi){
			*s2='0'+cur/bi;
			s2++;
			osti=cur % bi;
			cur=osti;
			}
	}
	if (cur>0){
		sprintf(ost,"%i",cur);
		}
	return 1;
}
nikolay1982 вне форума Ответить с цитированием
Ответ


Купить рекламу на форуме - 42 тыс руб за месяц

Опции темы Поиск в этой теме
Поиск в этой теме:

Расширенный поиск


Похожие темы
Тема Автор Раздел Ответов Последнее сообщение
Prosta no ochen trudnaya alisadiq Общие вопросы Delphi 3 16.06.2010 13:34