Correct Answer: atoi() Converts a string to an integer itoa() Convert an integer to a string gcvt() Converts a floating-point number to a string #include "stdlibh" main() { char s[] = "12345"; char buffer [15], string[20]; int i; i = atoi (s); printf("\n%d",i); gcvt (20141672, 4, buffer); printf ("\n%s", buffer); itoa(15, string,2); printf ("\n%s", string); }
7. What's the difference between the functions rand(), random(), srand() and randomize()?
Correct Answer: rand() returns a random number random() returns a random number in a specified range srand() initialise a random number generator with a given seed value randomize() initializes a random number generator with a random value based o time
8. What will be output when you will execute following c code? #include void main() { switch(2) { case 1L:printf("No"); case 2L:printf("%s","I"); goto Love; case 3L:printf("Please"); case 4L:Love:printf("Hi"); } }
Correct Answer: #include int main(){ int a[10],i,n,m,c=0; printf("Enter the size of an array: "); scanf("%d",&n); printf("Enter the elements of the array: "); for(i=0;i<=n-1;i++){ scanf("%d",&a[i]); } printf("Enter the number to be search: "); scanf("%d",&m); for(i=0;i<=n-1;i++){ if(a[i]==m){ c=1; break; } } if(c==0) printf("The number is not in the list"); else printf("The number is found"); return 0; } Sample output: Enter the size of an array: 5 Enter the elements of the array: 4 6 8 0 3 Enter the number to be search: 0 The number is found
10. Rewrite the following set of statements using conditional operators. int a =1, b ; if ( a > 10 ) b = 20;