4) Write a program that takes a 5 digit number and
calculates 2 power
that number and prints it.
I did the following program and is this correct

Answer Posted / renu gaindar

#include <stdlib.h>
#include <string.h>
#include <stdio.h>

void main()
{
int a[5],b[5],c[2],j[2],d[2];
int d,e,f,g,h,i,l,result;
char first[10], secont[10],third[10],forth[10],fifth
[10],x[20];
printf("\nEnter 5 digit number : ");
for(i=1,i<=5;i++)
{
scanf("%d",a[i]);
}
c=a[5]*a[5]; //multiplication of units place
d[1]=c[1]; //1st carry
e=c[0]; //First Digit

c=a[4]*a[4];
d[1]=c+d;
f=c[0];

c=(a[3]*a[3]);
d[1]=c+d;
g=c[0];

c=(a[2]*a[2]);
d[1]=c+d;
h=c[0];

c=(a[1]*a[1]);
d[1]=c+d;
l=c[0];

atoi(e,first,10);
atoi(f,second,10);
atoi(g,third,10);
atoi(h,forth,10);
atoi(l,fifth,10);

strcpy(x,first);
strcpy(x,second);
strcpy(x,third);
strcpy(x,forth);
strcpy(x,fifth);

result=atoi(x);
printf("%d",result);

}

Is This Answer Correct ?    1 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

i want to know details about SBI bank exam and date when to apply and what is the eligibility and the model papers related to it and various post available for Engineering in Information Technology.

1720


what is polymorphism.

1535


what are the simlerities between macro and subroutine

1626


In HSE what is Lost time accident? why it is to be reported within 48 hrs to gov.authorities ?

1557


what is dns?

1604






Draw the diagram showing the function stack, illustrating the variables that were pushed on the stack at the point when function f2 has been introduced . type def struct { double x,double y} point; } main( int argc, char *arg[3]) { double a; int b,c; f1(a,b); } f1(double x, int y) {point p; stack int n; f2(p,x,y) } f2(point p, double angle) { int i,j,k,int max;

1775


am a textile eng. frombut with major of my course including chemical eng, subjects, can i too apply to the co.?

1663


What are the input documents to 1.Functional testing,2.System testing and 3.Integration testing. Whether there will be separate test cases for regression testing or functional testing?

1743


program for inter process communicatin using message sharing in unix c

1481


can i get some win vista notes

1431


Write steps of retrieving data using ado.net?

1997


int main() { int d = 10; int m = 2; int y = 3603; int c = 0; int val; val = ( d + m + y + (y/4) + c) % 7; cout << val; return 0; }

1323


what is the difference between physical address and logical address?

1672


what is test strategy

1591


a book consists of chapter ,chapter consist of sections and sections consists of subsections.construct a tree and print the node.

5207