Showing posts with label Placement Important Questions. Show all posts
Showing posts with label Placement Important Questions. Show all posts

Friday, December 9, 2016

Star Pattern-II - Placement Practice Questions @ C/C++

Special Thanks to - Rishubh Pratap Singh

A. Output 


B. Code in C 


#include <stdio.h>

int main()
{
int i,j,n;
printf("Enter the number of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=n;j>=i;j--)
{
            printf(" * ");
        }
printf("\n");
}
return 10;

}

Star Pattern-I - Placement Practice Questions @ C/C++

Special Thanks to - Rishubh Pratap Singh

A. Output 



B. Code in C 

#include <stdio.h>

int  main()
{
int i,j,n;
printf("Enter the number of rows");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
for(j=1;j<=i;j++)
{
  printf(" * ");
}
printf("\n");
}
return 0;
}

Tuesday, November 29, 2016

Placement Practice Set - Logical Small Questions

Prime Number:

A prime number that doesn’t have factors. Like  2  3  5  7  11  13   17……
Just see the logic how to check a given number is prime or not
// number is a variable to be checked
// count is a integer variable
// flag is used to check condition initially should be 0
   
  for(count=2; count<=number/2; count++)
    {
        if( number % count = = 0)
        {
            flag = 1;
            break;
        }
    }

    if (flag = = 0)
        printf("prime number");
    else
        printf("not a prime number");

 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

Factorial of a given number

  A.   Using loop

int main()
{
  int count , fact = 1,num;
  printf("Enter Number: ");
  scanf("%d",&num);
  for(count = 1; count < = num; count++)
  {    
  fact = fact * count;
  }
  printf("Factorial of %d is: %d",num,fact);
  return 0;
}

  B.    Using Recursion  -
           Recursion is function which calls itself , Calling itself 
           stops at a particular condition.
         int fact(int n);   // Function Declaration
         int main()
        {
         int num, result;
         printf("Enter  num: ");
         scanf("%d", &num);
         result = fact(num);      // Function Calling
         printf("Factorial of %d is %d", num, result);
         return 0;
        }
     int fact(int n)                // Function Definition
      {
       if (n <= 0)
       {
          return 1;
       }
      else
      {
          return (n * fact(n - 1));
      }  
 }