Tuesday, November 26, 2019

Write a C Program to find the factorial of the given number

#include<stdio.h>
      int main()
    {
      int k, n;        
      int fact = 1;  
      printf("Enter an input number to find its factorial \n");
      scanf("%d", &n);
        
    if(n==0)
     {
       printf("Entered number must be above zero \n");
     }
      else
     {
     
      for (k = 1; k <= n; k++)
      fact = fact * k;
      printf("Factorial of the given number is %d = %d\n", n, fact);
    
     }
     
      return 0;
    }

OUTPUT:
Enter an input number to find its factorial
4
Factorial of the given number is 4 = 24

Enter an input number to find its factorial
9
Factorial of the given number is 9 = 362880

Saturday, November 23, 2019

Write a program in C to display the n terms of even natural number and their sum



#include<stdio.h>
int main()
{
   int i,n,sum=0;

   printf("Enter the n value : ");
   scanf("%d",&n);
   printf("\nThe even numbers are :");
 

  for(i=1;i<=n;i++)
  {
    if(i%2==0)
   {
     printf("%d ",i);
     sum+=i;
   }
  }


printf("\nThe Sum of Even Natural Number upto %d terms : %d \n",n,sum);
return 0;
}


OUTPUT:
Enter the n value : 5
The even numbers are :2 4
The Sum of Even Natural Number upto 5 terms : 6

Enter the n value : 10
The even numbers are :2 4 6 8 10
The Sum of Even Natural Number upto 10 terms : 30

Write a program in C which is a Menu-Driven Program to compute the area of the various geometrical shape

#include<stdio.h>
int main ()
{
      int input_choice;
      int radious;
      int length,width;
      int base,hight;
      float area=0;

      printf("Enter 1 for area of circle\n");
      printf("Enter 2 for area of rectangle\n");
      printf("Enter 3 for area of triangle\n");
      printf("Enter your choice : ");
      scanf("%d",&input_choice);
      switch(input_choice)
      {
           case 1:
                 printf("Input radious of the circle : ");
                 scanf("%d",&radious);
                 area=3.14*radious*radious;
                 break;
            case 2:
                  printf("Input length and width of the rectangle : ");
                  scanf("%d \n %d ",&length,&width);
                  area=length*width;
                  break;
            case 3:
                  printf("Input the base and hight of the triangle :");
                  scanf("%d \n %d",&base,&hight);
                  area=(0.5)*base*hight;
                  break;
        
            default:
                  printf("select the correct choice\n");   
    }
          printf("The area is : %f\n",area);
          return 0;
}


OUTPUT:

Enter 1 for area of circle
Enter 2 for area of rectangle
Enter 3 for area of triangle
Enter your choice : 1
Input radious of the circle : 4
The area is : 50.240002

Enter 1 for area of circle
Enter 2 for area of rectangle
Enter 3 for area of triangle
Enter your choice : 5
select the correct choice
The area is : 0.000000







Write a C program to calculate the factorial of a given number


#include<stdio.h>

int main()

{

  int k, n;              

  int fact = 1;         


printf("Enter an input number to find its factorial \n");

scanf("%d", &n);



   if(n==0)

  {

      printf("Entered number must be above zero \n");

  }

  else

  {


     for (k = 1; k <= n; k++)

     fact = fact * k;

  }
printf("Factorial of the given number is %d = %d\n", n, fact);



return 0;
}

OUTPUT:
Enter an input number to find its factorial
6
Factorial of the given number is 6 = 720

Enter an input number to find its factorial
0
Entered number must be above zero

Write a C program to convert a string to a long integer

#include<stdio.h>
int main()

{

  long longinteger;

  int no;
 
  // string to long integer converison
  longinteger = atol("56789");

  // string to integer converison
  no=atoi("345");


  printf("The string converted to long int is %ld\n", longinteger-2);

  printf("The string converted to int is %d\n", no+2);


  return 0;

 }

}

OUTPUT:
The string converted to long int is 56787
The string converted to int is 347

Wednesday, October 23, 2019

PPS with C IMPORTANT QUESTIONS




1) a) Briefly explain about the storage of integers and real(float) numbers with format. 
    b) Write the differences between variable and constant with example

2) a) Briefly explain about the operator precedence and associativity in C
    b) Write a c program to find the bigger number among the three numbers

3) a) Write a short notes on the following
     i) Increment and decrement operators.
     ii) Conditional operator.

    b) Write a short notes on the following
     i) if else if
     ii) global and local variable
     iii) keywords

4) a) Convert the given decimal number into Binary,Octal and Hexadecimal numbers
     i) (222)10 ,ii) (84)10 

    b) What is need of the data type and briefly explain different type of data types with            
         example.

5) a) Convert the given Binary number into Decimal,Octal and Hexadecimal numbers
     i) (00101000)2 ,ii) (01010000)

    b) What is need of the variable and briefly explain different type of rules to declare 
         variable.

6) a) Briefly explain different types of storage classes in C
    b) Write a C program to perform arithmetic operations using Switch case.

7) a) write a short notes on the following
     i) Type conversion
     ii) Type qualifiers
     iii) Type specifiers

    b) Write a C program to print even numbers upto 10.

8) a) Write a short notes on the following
     i) Logical operators
     ii) Bitwise operators

    b) Write a short notes on the following
     i) if else
     ii) while
     iii) break.

9) a) Write a short notes on the following
     i) 1’s complement
     ii) 2’s complement

     b) Write a short notes on the following
     i) nested if.
     ii) do while
     iii) goto.

PPS WITH C UNIT 1 & 2 NOTES