Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...


write a c program to find the square of a 5 digit number
and print the result.

Answers were Sorted based on User's Feedback



write a c program to find the square of a 5 digit number and print the result...

Answer / sreenu

#include<stdio.h>
#include<conio.h>
void main()
{
long i,j
clrscr();
printf("enter the number");
scanf("%ld",&i);
j=i*i;
printf("the sqare of the number is %d",j);
getch();
}

Is This Answer Correct ?    30 Yes 23 No

write a c program to find the square of a 5 digit number and print the result...

Answer / balagopalan

#include<stdio.h>
int main()
{
long long int a = 99999;
long long int b = a * a;
printf("%lld" , b);
return 0;
}

Is This Answer Correct ?    2 Yes 1 No

write a c program to find the square of a 5 digit number and print the result...

Answer / paras

#include<stdio.h>
#include<conio.h>
void main(){
clrscr();
long a=0,b=0;
long num;
printf("Enter a 5 digit number: ");
scanf("%ld",&num);
a=num/100;
b=num%100;
printf("Square of this number is: ");
long c=2*a*b;
a=a*a;
b=b*b;
long t=c%100;
t*=100;
t+=b;
long w=c/100;
w+=a;
if(t/10000 <= 0)
printf("%ld",w);
else
{
w=w+t/10000;
t=t%10000;
printf("%ld",w);

}
if(t/10==0)
printf("000%ld",t);
else if(t/100==0)
printf("00%ld",t);
else if(t/10==0)
printf("0%ld",t);
else
printf("%ld",t);
getch();
}

Is This Answer Correct ?    7 Yes 7 No

write a c program to find the square of a 5 digit number and print the result...

Answer / sarthak

I was asked to calculate the square without using long int or double. This is how i did it. I was eventually rejected but i have no idea why as the code is correct.

/*Program to find the square of a 5 digit number and print*/

#include<stdio.h>
#include<conio.h>

main()
{
clrscr();



/*Part 1: -
num is used to initially read the number
i,j are used as counters
sq is used to multiply the number with each of its digits
sq1 is used to store the result of sq with proper shift and ading zeros
result is used to store and print fial result
rem used to store remainder
quot used to store quotient
rs use as sum of coloumn*/

int num[5],i=0,j=0,sq[5][10],sq1[5][10],result[10],dig,rem,quot,rs=0;



/* Part 2: -
Reading the 5 digit number*/

printf("Enter the 5 digit number\nPlease press enter after each digit: -");
for(i=4;i>=0;i--)
{
scanf("%d",&num[i]);
}

/*Print the entered number*/

printf("\n\nYou entered the number: ");

for(i=4;i>=0;i--)
{
printf("%d",num[i]);
}




/*Part 3: -
Initialize sq as 0*/

for(i=0;i<=4;i++)
{
for(j=0;j<=9;j++)
{
sq[i][j]=0;
}
}

/*Initialize sq1 as all 0s*/

for(i=0;i<=4;i++)
{
for(j=0;j<=9;j++)
{
sq1[i][j]=0;
}
}

printf("\n\nInitially after assigning array to all 0's: -");

/*Print the 2D array after asigning it to 0*/

printf("\n\n");
for(i=0;i<=4;i++)
{
printf("\n");
for(j=0;j<=9;j++)
{
printf("%d",sq[i][j]);
}
}



/* Part 4: -
Multiply the 5 digit number with each of its own digits and storing rowise*/

for(j=0;j<=4;j++)
{
for(i=0;i<=4;i++)
{
dig=num[i]*num[j];
rem=dig%10;
quot=dig/10;
sq[i][j]=sq[i][j]+rem;
if(sq[i][j]>=10)
{
sq[i][j+1]=sq[i][j+1]+(sq[i][j]/10);
sq[i][j]=sq[i][j]%10;
}
sq[i][j+1]=sq[i][j+1]+quot;
}
}

printf("\n\nAfter multiplying the number with each of its respective digits and storing in respective rows: -");

/*Print the array without shifting*/

printf("\n\n");
for(i=0;i<=4;i++)
{
printf("\n");
for(j=0;j<=9;j++)
{
printf("%d",sq[i][j]);
}
}



/*Part 5: -
Applying shift to the array*/

for(i=0;i<=4;i++)
{
for(j=9;j>=0;j--)
{
sq1[i][j+i]=sq[i][j];
}
}

printf("\n\nAfter applying proper shift to the rows of the array: -");

/*Print after applying shift to the array*/

printf("\n\n");
for(i=0;i<=4;i++)
{
printf("\n");
for(j=0;j<=9;j++)
{
printf("%d",sq1[i][j]);
}
}



/* Part 6: -
Initialize result to 0*/


for(i=0;i<=9;i++)
{
result[i]=0;
}

/*add up the coloumns*/

quot=0;
rem=0;
for(j=0;j<=9;j++)
{
for(i=0;i<=4;i++)
{
rs=rs+sq1[i][j];
}
quot=rs/10;
rem=rs%10;
result[j]=result[j]+rem;
rs=quot;
}

printf("\n\nAfter adding up the respective coloumns of the above array \n and reversing the order: -");

/*print the result*/

printf("\n\nThe square of the numer is :- ");

for(i=9;i>=0;i--)
{
printf("%d",result[i]);
}
return 0;
}

Is This Answer Correct ?    2 Yes 11 No

write a c program to find the square of a 5 digit number and print the result...

Answer / ishany gaurav

#include<iostream.h>
#include<conio.h>
void main()
{
int i,k,j,l;
cout<<"lets find out the square of five digit no.";
cout<<"enter the five digit no." ;
cin>>i;
k=i*i;
cout<<"square of a no. is"<<k;
getch();
}

Is This Answer Correct ?    9 Yes 30 No

Post New Answer

More C Interview Questions

. Consider the following program main() { int a[5]={1,3,6,7,0}; int *b; b=&a[2]; } The value of b[-1] is (A) 1 (B) 3 (C) -6 (D) none

9 Answers   Oracle,


Write a program to compute the following 1!+2!+...n!

4 Answers  


How can you determine the maximum value that a numeric variable can hold?

0 Answers  


how many errors in c explain deply

0 Answers  


What is an arrays?

0 Answers  


What are the complete rules for header file searching?

0 Answers  


Write a C Program to display the following menu: Menu 1. Display 2. Copy 3. Append 4. Exit Accept the choice (1-4) from the user, and perform the following tasks: Choice 1: Accept a file name from the user and display the file on screen Choice 2: Accept two file names, and copy first file to the second Choice 3: Accept two file names, and append second file to the first file Choice 4: Terminate the program

1 Answers   Accenture, Concor, DMU, Satyam, Syntel, Tora,


Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

0 Answers  


Why clrscr is used after variable declaration?

0 Answers  


please help me.. how to write a code of this output?? "Enter range number:"10 1 is an odd number 2 is an even numbers 3 in an odd numbers 4 " to 10" "printing all odd numbers:" 1,3,5,7,9 "printing all even numbers:" 2,4,6,8,10 "sum of all odd numbers:25 "sum of all even numbers:30 using a C Programming ARRAY pleas pleas help.. its my project ..please :(

1 Answers  


What does the function toupper() do?

0 Answers  


count the numbers between 100 and 300, that star with 2 and ends with 2

5 Answers   Mind Tree,


Categories