GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Placement Papers  >  TCS  >  C
Go To First  |  Previous Question  |  Next Question 
 C  |  Question 60 of 87    Print  
What does the following code do?
fn(int n, int p, int r)
{
static int a=p;
switch(n)
  {
   case 4:a+=a*r;
   case 3:a+=a*r;
   case 2:a+=a*r;
   case 1:a+=a*r;
   }
}

A. computes simple interest for one year
B. computes amount on compound interest for 1 to 4 years
C. computes simple interest for four year
D. computes compound interest for 1 year


  
Total Answers and Comments: 1 Last Update: January 24, 2008   
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
January 24, 2008 13:59:57   #1  
kumarchirag_05 Member Since: January 2008   Contribution: 1    

RE: What does the following code do?fn(int n, int p, int r){static int a=p;switch(n)  {   case 4:a+=a*r;   case 3:a+=a*r;   case 2:a+=a*r;   case 1:a+=a*r;   }}A. computes simple interest for one year
the answer to the question ius option B
Reason being
if this function is called from within a loop with n 0 to n<4
then cases 1 2 3 4 in switch will be called one by one
as int a is static first time it will be initialized with the value p but after words
its memeory location will be updated every time the fun is called with the latest value of a calculated within the case
but r should be a float value
example:
main()
int p 100;
float r 0.10;
{
for(n 1;n< 4;n++)
{
fun(n p r);
}

}

than execution will be:
first iteration
a p 100
n 1
case(1) selected
a a+a*r >a 100+100*.1
a 110

second iteration
a 110;
n 2
case(2)
a a+a*r >a 110+110*.1
a 121

third iteration
a 121
n 3
case(3)
a a+a*r > a 121+121*.1
a 133.1

fourth iteration
a 133
n 4
case(4)
a 133+133*.1
a 146

in this way we can see this is the amount for compound interest for 1-4 years

 
Is this answer useful? Yes | No

 Related Questions

What is false about the following A compound statement is a.A set of simple statmentsb.Demarcated on either side by curly bracketsc.Can be used in place of simple statementd.A C function is not a compound statement.

Write one statement equivalent to the following two statementsx=sqr(a);return(x);Choose from one of the alternativesa.return(sqr(a));b.printf("sqr(a)");c.return(a*a*a);d.printf("%d",sqr(a));

Latest Answer : Here the statement if(x=6) is true because this is not a conditional operator it assigns 6 to x so it is true, the if condition is truethen y=7; ...

Read the folllowing code# define MAX 100# define MIN 100........if(x>MAX)x=1;else if(x

A memory of 20 bytes is allocated to a string declared as char *sthen the following two statements are executed:s="Etrance"l=strlen(s);what is the value of l ?a.20b.8c.9d.21

Given the piece of codeint a[50];int *pa;pa=a;to access the 6th element of the array which of the following is incorrect?a.*(a+5)b.a[5]c.pa[5]d.*(*pa + 5)

Regarding the scope of the varibles;identify the incorrect statement:a.automatic variables are automatically initialised to 0b.static variables are are automatically initialised to 0c.the address of a register variable is not accessiabled.static variables cannot be initialised with any expression

Latest Answer : I think value of y = 5.Because if you format the code, it will look like thisx = 10;y=5;if (x==10){}else if(x==9){}else{   y=8;}Since value of x is 10 so condition if (x==10) will satisfy. And there is no assignment for y. So value of y ...

What does the following code do?fn(int n,int p,int r){static int a=p;switch(n){case 4:a+=a*r;case 3:a+=a*r;case 2:a+=a*r;case 1:a+=a*r;}}a.computes simple interest for one yearb.computes amount on compound interest for 1 to 4 yearsc.computes simple interest for four year d.computes compound interst for 1 year

Consider the following program sigmentint n,sum=1;switch(n) {case 2:sum=sum+2;case 3:sum*=2;break;default:sum=0;} if n=2, what is the value of suma.0b.6c.3d.none


 Sponsored Links

 
Related Articles

How to Best Use Business Intelligence to Your Advantage

How to Best Use Business Intelligence to Your Advantage It is no big secret that today s businesses rely heavily on data and the information it delivers about their companies Whether it is for the purpose of customer acquisition improving operational performance or understanding competitors all of t
 

Taking Advantage of Standard Internet Protocols

Taking Advantage of Standard Internet Protocols As mentioned Oracle XML DB provides native support for standard internet protocols such as S WebDAV and Continuing with the preceding sample you might for example upload another employee XML document into the XML repository with one of the above prot
 

Accessing Repository Resources with SQL

Accessing Repository Resources with SQL In fact Oracle XML DB repository resources are stored in a set of database tables and indexes which can be accessed via SQL You are not supposed to access those tables directly Instead Oracle XML DB provides two public views RESOURCE VIEW and PATH VIEW through
 

XML Processing in PHP and Oracle Applications

Processing XML in PHP Oracle Applications As mentioned there are two alternatives when it comes to performing XML processing in your PHP Oracle application You can perform any required XML processing using either PHP s XML extensions or PEAR XML packages or Oracle s XML features mosgoogle In the fol
 

Business Intelligence Applications

Business Intelligence Applications In this article we are going to take some time to discuss the various applications that are normally provided with Business Intelligence Systems mosgoogle Tools Used to Analyze Performance Projects and Internal Operations First we will look over the tools most comm
 

Business Intelligence Data Analysis

Business Intelligence Data Analysis Data Analysis Data Analysis is a complete and thorough review of all of the information being collected and warehoused by an organization This is most commonly done by organizing and examining the data collected with the help of charts graphs and tables mosgoogle
 

SQA Approaches and Methodologies

SQA Approaches and Methodologies A scientific approach should have methods As a scientific process a stage or a step should be established or used to ensure the final product is according to the user&rsquo; s specifications The method is usually determined through the wishes of the clients the a
 

SQA Analysis

SQA Analysis Software Quality Assurance is all about analysis One of the major purposes of this discipline is to know the inner workings of an application To do this careful analysis has to be exercised at all times Although there are programs and applications that aid in knowing the inner workings
 

What is Software Quality Assurance?

What is Software Quality Assurance Business software is never built overnight It takes a lot of planning consultation and testing to be able to come up with an initial version of the application If a business hurries up the development of a certain application they would end up spending more in addr
 

Software Quality Assurance Training

Software Quality Assurance Training In this training session you will learn about SQA Software Quality Assurance SQA Principles SQA Planning SQA Project Metrics SQA Software and Tools SQA Analysis SQA Approaches and Methodologies SQA Planning and Requirements SQA Lifecycle Standards SQA Implementati
 

About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape