How to use functions in Jmeter?

Write a C program to find whether the number is power of 2 or not? Do not use functions.?

  • Do not use functions 1)Write a C program to find whether the number is power of 2 or not? Do not use functions. 2) Write a c program to reverse the given string in the decreasing order say from z to a - another task in this is to separate the upper case and lower case letters and then to descend them from z to a. -another task is if u want to show the result in ascending order then what you will change in the program.

  • Answer:

    1)Write a C program to find whether the number is power of 2 or not? Do not use functions. #include<stdio.h> main() { int no, rem, flag=0; printf("\nEnter a Number: "); scanf("%d",&no); while(no>2) { rem=no%2; if(rem==1) { flag=1; break; } else no=no/2; } if(flag==1) printf("\nNo is not Power of two."); else printf("\nNo is Power of two"); } ______________________________________… 2) Write a c program to reverse the given string in the decreasing order say from z to a - another task in this is to separate the upper case and lower case letters and then to descend them from z to a. -another task is if u want to show the result in ascending order then what you will change in the program. #include<stdio.h> main() { char str[20],temp; int length,i; printf("\nEnter a string: "); gets(str); length=strlen(str); for(i=0;i<length-1;i++) { if(str[i]>str[i+1]) { temp=str[i]; str[i]=str[i+1]; str[i+1]=temp; i=0; continue; } } strrev(str); printf("\nYour string in descending order: %s",str); strrev(str); printf("\nYour string in ascending order: %s",str); } for more information on c visit http://s3c.in/Articles.aspx?ID=40

Manoj Pilania at Yahoo! Answers Visit the source

Was this solution helpful to you?

Other answers

Too greedy ! I will help you the first but the others will spend my time much writing codes (I'm using Nokia 6300 to compose words answering questions). #include<conio.h> #include<stdio.h> void main() { int n,i = 0; printf("Please input an integer to check if it is a power of 2 or not: "); scanf("%d", &n); while(n%2==0&&n!=0) { n=n/2; i++; if(n==1) n = -1; } if(n==-1||n==1) printf("\nThe number you have input is a power of 2 ! And it is 2^%d", i); else printf("\nThe number you have input is not a power of 2 !"); getch(); } I'm sure my solution is the best for this request! Try copying it and running it yourself! -------------------- Note: the codes of Manoj have 2 problems: 1. When you input no=0, flag still equals to 0, and then the result printed out will be "No is power of 2" That's wrong at all. 2. As above you can see, the result includes the word "No" not a concrete number, it should be "0 is power of 2" and that's wrong at all as I mentioned above. The least number which is power of 2 is 1 (2^0). Please review it yourself!

King Boy

For program 1 (handy if you know binary numbers): #include <stdio.h> int main(int iArgs, char *pszArgs[]) { int iNumber, iCount, iIndex; printf("Enter a number: "); scanf("%d",&iNumber); for (iIndex=iCount=0; iIndex<(sizeof(iNumber)*8); iIndex++) if (iNumber>>(iIndex)&1) iCount++; if (iCount==1) printf("%d is a power of two.",iNumber); else printf("%d is not a power of two.",iNumber); return 0; }

Techwing

)Write a C program to find whether the number is power of 2 or not? Do not use functions.

Aasefa

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.