ALLInterview.com :: Home Page KalAajKal.com
 Advertise your Business Here     
Browse  |   Placement Papers  |   Company  |   Code Snippets  |   Certifications  |   Visa Questions
Post Question  |   Post Answer  |   My Panel  |   Search  |   Articles  |   Topics  |   ERRORS new
   Refer this Site  Refer This Site to Your Friends  Site Map  Bookmark this Site  Set it as your HomePage  Contact Us     Login  |  Sign Up                      
tip       Ask Questions on ANYTHING, that arise in your Daily Life at     FORUM9.COM
Google
 
Categories  >>  Software  >>  Programming Languages  >>  C
 
 


 

 
 C interview questions  C Interview Questions
 C++ interview questions  C++ Interview Questions
 VC++ interview questions  VC++ Interview Questions
 Delphi interview questions  Delphi Interview Questions
 Programming Languages AllOther interview questions  Programming Languages AllOther Interview Questions
Question
write a code for large nos multilication (upto 200 digits)
 Question Submitted By :: Atul Kabra
I also faced this Question!!     Rank Answer Posted By  
 
  Re: write a code for large nos multilication (upto 200 digits)
Answer
# 1
#include<stdio.h>
#include <conio.h>
#include<string.h>
#include<alloc.h>
char * mul(char *, char);
char * add(char *, char *);
void main()
{

	char *no1=(char * )malloc(100);
	char *no2=(char *)malloc(100);
	char *q="0";
	char *p;
	int i=0,j=0,t=0,l=0;
	clrscr();
	printf("\n Enter the large no ");
	gets(no1);
	printf("\n Enter the second no ");
	gets(no2);

	while(l<strlen(no2))
	{
		p=mul(no1,no2[l]);
		for(j=1;j<=strlen(no2)-l-1;j++)
		strcat(p,"0");
		q=add(q,p);
		l++;
	}
	printf("\n Multiplication is %s",q);
	free(no1);
	free(no2);
}


char * mul(char *x, char ch)
{
	int i=0,j=0,t=0;
	char *p=(char *)malloc(300);
	char *a =(char *)malloc(300);
	strcpy(p,x);
	strrev(p);
	while(p[i]!='\0')
	{
		a[j]=(p[i]-48)*(ch-48)+t;
		t=a[j]/10;
		a[j]=(a[j]%10)+48;
		i++;
		j++;
	}
	if(t!=0)
	a[j]=t+48;
	else
	j--;
	a[j+1]='\0';
	strrev(a);
	free(p);
	return(a);
}
char * add(char *p, char *q)
{
	char *t=(char *)malloc(300);
	int i=0,j=0,x=0,a;
	strrev(p);
	strrev(q);
	while(p[i]!='\0' && q[i]!='\0')
	{
		a=(p[i]-48)+(q[i]-48)+x;
		x=a/10;
		a=a%10;
		t[i]=a+48;
		i++;
	}
	while(i<strlen(p))
	{
		a=(p[i]-48)+x;
		x=a/10;
		a=a%10;
		t[i]=a+48;
		i++;
	}
	while(i<strlen(q))
	{
		a=(q[i]-48)+x;
		x=a/10;
		a=a%10;
		t[i]=a+48;
		i++;
	}

	if(x!=0)
		t[i++]=x+48;
	t[i]='\0';
	strrev(t);
	return(t);
}



 
Is This Answer Correct ?    2 Yes 0 No
Atul Kabra
 

 
 
 
Other C Interview Questions
 
  Question Asked @ Answers
 
What is structure packing ? HP1
Write a C program to print 1 2 3 ... 100 without using loops?  5
Program to find the absolute value of given integer using Conditional Operators N-Tech2
5. distance conversion: Convert a distance from miles to kilometers .there are 5280 feets per mile,12 inches per foot .2.54 centimeters per inch and 100000centimeters per kilometer  1
WHAT IS THE DIFFERENCE BETWEEN malloc() and calloc() in c file management?  6
Write a program to find the smallest and largest element in a given array in c language Microsoft3
1. Write a c pgm to print 1 to 100 without using loops. 2. Write a c pgm for leap year 3. Write a c pgm fibbonacci series,factorial 4. Write a c pgm count no of lines , blanks, tabs in a para(File concept) 5. Write a c pgm to print the letter as per given condition i.e.. if u give 4 out put should b 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 6.how do get the o/p in number from 1 to 100 in the screen without using control statement? 7. who do u print the word "hello world" without using "printf" statement? 8. write sql program to get the detail of student in a class? Definitions: structure union arrays linkedlist macros directives difference b/w pre processorsDiffrence: 1.Constructors and destructors 2.Structure and Union 3.Array and Lists 4.pre processor... 5. Privillages in C++ 6.structure and union 7.break and continue 8.while and dowhile Pgm..  1
how to generate the length of a string without using len funtion?  3
4.weight conversion: Write a program that will read weight in pounds and convert it into grams.print both the original weight and the converted value.There are 454 grams in a pound.design and carry out a test plan for this program. Wipro1
6. Which of the Following is not defined in string.h? A)strspn() B)strerror() C)memchr() D)strod() Accenture1
WAP to accept basic salary of an employee? Calculate it HRA=25%,DA=30%,PF=30%&net salary display all contents?  5
2.Given the short c program that follows a. make a list of the memory variables in this program b.which lines of code contain operations that change the contents of memory? what are those operations? Void main( void) { Double base; Double height; Double area; Printf(“enter base and height of triangle :”); Scanf(“%lg”, &base); Scanf(“%lg”, &height); Area=base*height/2.0; Printf(“the area of the triangle is %g \n”,area); } Wipro1
what is a headerfile?and what will be a program without it explain nan example? Assurgent5
How do we swap or interchange any 2 numbers without using Temporary variable...Anybody can pls answer it.. Thanks in Advance  7
1. Write the function int countchtr(char string[ ], int ch); which returns the number of times the character ch appears in the string. Example, the call countchtr(“She lives in NEWYORK”, ‘e’) would return 3.  2
What kind of sorting is this? SORT (k,n) 1.[Loop on I Index] repeat thru step2 for i=1,2,........n-1 2.[For each pass,get small value] min=i; repeat for j=i+1 to N do { if K[j]<k[min] min=j; } temp=K[i];K[i]=K[min];K[min]=temp; 3.[Sorted Values will be returned] A)Bubble Sort B)Quick Sort C)Selection Sort D)Merge Sort Accenture3
what is c? Tech-Mahindra5
what is the use of keyword volatile?? LG-Soft4
main() { int i = 1; int num[] = {1,2,3,4}; num[i] = i++; printf("%d", num[i]); } what will be the output? } NDS15
what are the various memory handling mechanisms in C ? HP3
 
For more C Interview Questions Click Here 
 
 
 
 
 
   
Copyright Policy  |  Terms of Service  |  Help  |  Site Map 1  |  Articles  |  Site Map  |   Site Map  |  Contact Us interview questions urls   External Links 
   
Copyright © 2007  ALLInterview.com.  All Rights Reserved.

ALLInterview.com   ::  Forum9.com   ::  KalAajKal.com