Saturday, July 24, 2021

IMP Questions:

 

1)    Define Structure and write a program to read and display 3 employee records with structure                                                                                        

2)   Define Pointer; briefly explain about the pointer to pointer and pointer Arithmetic operations.                                                                                       

3)   Briefly explain about the different types of File handling functions with examples

Numbers series and their sum

N terms of Natural numbers series and their sum ( 1^2+2^2 + 3^2+4^2+5^2 + 6^2 ..... n^2)

--------------------------------------------------------------------------------------------------- 

#include <stdio.h>

int main()

{

   int i,n,sum=0;

   printf("Input the number of terms in the series: \n");

   scanf("%d",&n);

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

   {

      sum+=(i)*(i);  //main logic series generation

   }

   printf("\nSum of Series upto %d terms : %d \n",n,sum);

  return 0;

}


------------------------------------------------------------------------------------------------

N terms of even numbers series and their sum ( 2^2 + 4^2 + 6^2 ..... n^2)

--------------------------------------------------------------------------------------------------- 

#include <stdio.h>

int main()

{

   int i,n,sum=0;

   printf("Input the number of terms in the series: \n");

   scanf("%d",&n);

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

   {

      sum+=(2i)*(2i);  //main logic even no's generation

   }

   printf("\nSum of Series upto %d terms : %d \n",n,sum);

  return 0;

}

--------------------------------------------------------------------------------------------------

N terms of odd numbers series and their sum ( 1^2 + 3^2 + 5^2+7^2 ..... n^2)

-----------------------------------------------------------------------------------------------

#include <stdio.h>

int main()

{

   int i,n,sum=0;

   printf("Input the number of terms in the series: \n");

   scanf("%d",&n);

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

   {

      sum+=(2i-1)*(2i-1);  //main logic odd number generation

   }

   printf("\nSum of Series upto %d terms : %d \n",n,sum);

  return 0;

}

Triangle Display

 ^^^^^ Number Triangle Display ^^^^^

1

1    2

1    2    3

1    2    3    4

1    2    3    4    5

---------------------------------------------------------------------------------

#include<stdio.h>

void main()

{

 int i,j;

 printf("Triangle Display \n");

 for(i=1;i<10;i++)

 {

   for(j=1;j<=i;j++)

   {   

      printf("%d\t",j);

   }

  printf("\n");

 }

}

*************************************************

1    2    3    4    5    6

1    2    3    4    5

1    2    3    4

1    2    3

1    2

1

**************************************************

#include<stdio.h>

void main()

{

 int n,i,j;

 clrscr();

 printf("Enter the no of lines required: \n");

 scanf("%d",&n);

 for(i=n;i>0;i--)

 {

   for(j=1;j<=i;j++)

   {

     printf("%d\t",j);

   }

    printf("\n");

 }

}

Star Triangle Program

^^^^^^^^^^^^^Triangle Display^^^^^^^^^^^^^^^

*

*    *

*    *    *

*    *    *    *

*    *    *    *    *

---------------------------------------------------------------------------------

#include<stdio.h>

void main()

{

 int i,j;

 printf("Triangle Display \n");

 for(i=1;i<10;i++)

 {

   for(j=1;j<=i;j++)

   {   

      printf("*\t");

   }

  printf("\n");

 }

}

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

*    *    *    *    *

*    *    *    *

*    *    *

*    *

*

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#include<stdio.h>

void main()

{

 int n,i,j;

 clrscr();

 printf("Enter the no of lines required: \n");

 scanf("%d",&n);

 for(i=n;i>0;i--)

 {

   for(j=1;j<=i;j++)

   {

     printf("* \t");

   }

    printf("\n");

 }

}