C Programming Important Questions for NEB Board Exam

C PROGRAMMING - NEB Board Exam Important Questions


Here are some of the most probable questions of C Programming for upcoming NEB Board Exam :


Q1. WAP to enter roll no, name, age of 20 students and count students with age > 20 and <25. 

#include<stdio.h>

struct students

{

    int roll;

    char name[50];

    int age;

};

int main()

{

    int n,i,j;

    printf("How many data ");

    scanf("%d",&n);

    struct students a[n];

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

    {

       printf("\nEnter roll,name,age of %d student",i+1);

       scanf("%d %s %d",&a[i].roll,a[i].name,&a[i].age);

    }   

int count=0;

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

{

    if(a[i].age>20&&a[i].age<25)

    {

        count++;

    }

}

printf("Required number is %d",count);

return 0;

}

 

 

Q2. WAP to enter the employee id, name and salary of the desired number of employees and sort them according to their names in alphabetical order.

#include<stdio.h>

#include<string.h>

struct employee

{

    int id;

    char name[20];

    float salary;

};

int main()

{

    int n;

    printf("How many data do you want to enter ?");

    scanf("%d",&n);

    struct employee a[n];

    for(int i=0;i<n;i++)

    {

    printf("Enter %d employee id:",i+1);

    scanf("%d",&a[i].id);

    printf("Enter %d employee name:",i+1);

    scanf("%s",a[i].name);

    printf("Enter %d employee salary:",i+1);

    scanf("%f",&a[i].salary);

    }

   

    //sort by name

    struct employee temp;

    for(int i=0;i<n;i++)

    {

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

        {

            if(strcmp(a[i].name,a[j].name)>0)

            {       

                temp=a[i];

                a[i]=a[j];

                a[j]=temp;

                //strcpy(temp,a[i].name);

                //strcpy(a[i].name,a[j].name);

                // strcpy(a[j].name,temp);

            }

        }

    }

 

    for(int i=0;i<n;i++)

    {

        printf("\nThe %d employee id,name,salary is %d\t%s\t%f",i+1,a[i].id,a[i].name,a[i].salary);

    }

    return 0;

}

 

 

Q3. WAP to enter the employee id, name and salary of the desired number of employees and sort them according to their id in ascending order.

#include<stdio.h>

struct employee

{

    int id;

    char name[20];

    float salary;

};

int main()

{

    int n;

    printf("How many data do you want to enter ?");

    scanf("%d",&n); 

    struct employee a[n];

    for(int i=0;i<n;i++)

    {

    printf("Enter %d employee id:",i+1);

    scanf("%d",&a[i].id);

    printf("Enter %d employee name:",i+1);

    scanf("%s",a[i].name);

    printf("Enter %d employee salary:",i+1);

    scanf("%f",&a[i].salary);

    }

 

    //sort by id

    struct employee temp;

    for(int i=0;i<n;i++)

    {

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

        {

            if(a[i].id>a[j].id)

            {

                temp=a[i];

                a[i]=a[j];

                a[j]=temp;

            }

        }

    }

 

    for(int i=0;i<n;i++)

    {

        printf("\nThe %d employee id,name,salary is %d\t%s\t%f",i+1,a[i].id,a[i].name,a[i].salary);

    }

    return 0;

}

 

 

Q4. WAP using user-defined function to check whether the given number is Palindrome or not.

#include<stdio.h>

void palindrome();

int main()

{

    palindrome();

    return 0;

}

void palindrome()

{

    int n,rem,i,copy;

    int rev=0;

    printf("Enter any number to check:");

    scanf("%d",&n);

    copy=n;

    while(n!=0)

    {

        rem=n%10;

        rev=rev*10+rem;

        n=n/10;

    }

   

    if(copy==rev)

    {

        printf("Yes, the entered number is Palindrome.");

    }

    else

    {

        printf("No, the entered number is not Palindrome.");

    }

}


 

Q5. WAP using user-defined function to check whether the given number is Armstrong or not.

#include<stdio.h>

#include<math.h>

void armstrong();

int main()

{

    armstrong();

    return 0;

}

 

void armstrong()

{

     int n,i,copy;

     int sum=0,count=0,rem=0;

     printf("Enter number: ");

     scanf("%d",&n);

    

    copy=n;

    while(n!=0)

     {

                n=n/10;

                count++;

     }

    

     //check

     n=copy;

     while(n!=0)

     {

                rem=n%10;

                sum=sum+pow(rem,count);

                n=n/10;

     }

    

     if(sum==copy)

     {

            printf("Yes, entered number is Armstrong");

     }

    

     else

     {

         printf("No, entered number is not Armstrong");

     }

}

 

 

Q6. WAP using user-defined function to check whether the given number is Prime or Composite.

#include<stdio.h>

void check();

int main()

{

              check();

}

void check()

{

              int n,i,count=0;

              printf("Enter any number:");

              scanf("%d",&n);

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

              {

                            if(n%i==0)

                            {

                                          count++;

                            }

              }

              if (count==2)

              {

                            printf("Prime");

              }

              else

              {

                            printf("Composite");

              }

}

 

 

Q7. WAP using user-defined function to check whether the given number is odd or even.

#include<stdio.h>

void check();

int main()

{

              check();

}

void check()

{

              int n,i,count=0;

              printf("Enter any number:");

              scanf("%d",&n);

             

              if(n%2==0)

              {

                            printf("Even");

              }

              else

              {

                            printf("Odd");

              }

}

 

 

Q8. WAP using user-defined function to find the greatest among 3 numbers.

#include<stdio.h>

void great();

int main()

{

              great();

}

void great()

{

              int a,b,c,g1,g2;

              printf("Enter three numbers one by one:");

              scanf("%d %d %d",&a,&b,&c);

             

              g1=a>b?a:b;

              g2=g1>c?g1:c;

             

              printf("Largest among three is %d",g2);

}

             

 

Q9. WAP using user-defined function to count and find the sum of the digits of a number.

#include<stdio.h>

void sumDigit();

int main()

{

              sumDigit();

}

void sumDigit()

{

              int n,i,rem;

              int sum=0,count=0;

              printf("Enter any number:");

              scanf("%d",&n);

              while(n!=0)

              {

                            rem=n%10;

                            sum=sum+rem;

                            n=n/10;

                            count++;            

              }

printf("The number of digits is %d and its sum is %d",count,sum);

}

 

 

Q10. WAP using user-defined function to find the multiplication table of a number.

#include<stdio.h>

void multiply();

int main()

{

              multiply();

}

void multiply()

{

              int n,i;

              printf("Enter any number:");

              scanf("%d",&n);

             

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

              {

                            printf("%d X %d = %d\n",n,i,n*i);

              }

}

 

 

Q11. Show basic concept of call by value and call by reference using simple swapping program.

CALL BY VALUE:

#include<stdio.h>

void swap(int ,int );

int a=5,b=6;

int main()

{

              printf("Value of a and b before function call is %d and %d",a,b);

              swap(a,b);

              printf("\nValue of a and b after function call is %d and %d",a,b);   

              return 0;

}

void swap(int a,int b)

{

              int temp;

              temp=a;

              a=b;

              b=temp;

printf("\nValue of a and b in function block is %d and %d",a,b);    

}

 

CALL BY REFERENCE:

#include<stdio.h>

void swap(int *,int *);

int a=5,b=6;

int main()

{

              printf("Value of a and b before function call is %d %d",a,b);

              swap(&a,&b);

              printf("\nValue of a and b after function call is %d %d",a,b);          

              return 0;

}

void swap(int *a,int *b)

{

              int temp;

              temp=*a;

              *a=*b;

              *b=temp;

}

 

Q12. Fibonacci series using recursion.

#include<stdio.h>

int fibo(int);

int main()

{

              int n;

              printf("Enter number: ");

              scanf("%d",&n);

 

              for(int i=0;i<n;i++)

              {

              printf("\n%d",fibo(i));

              }

}

int fibo(int n)

{

              if(n==0)

              {

                            return 0;

              }

             

              else if(n==1)

              {

                            return 1;

              }

             

              else

              {

                            return (fibo(n-1)+fibo(n-2));

              }

}

 

 

Q13. FACTORIAL using recursion.

#include<stdio.h>

int fact(int);

int main()

{

              int n,s;

              printf("Enter number:");

              scanf("%d",&n);

              s=fact(n);

              printf("Required number is %d",s);

              return 0;

}

int fact(int n)

{

              if(n==0||n==1)

              {

                            return 1;

              }

              else

              {

                            return(n*fact(n-1));

              }

}

 

 

Q14. WAP to find the sum of 2 numbers using pointer.

#include<stdio.h>

int main()

{

              int a,b,sum;

              int *p,*q;

              p=&a;

              q=&b;

              printf("Enter two  numbers:\n");

              scanf("%d %d",&a,&b);

              sum=*p+*q;

              printf("Sum is %d",sum);

}

 

 

Q15. WAP to store information of n number of students having fields id and name in a file named student.txt file and finally read from a file and display the records.

#include<stdio.h>

int main()

{

              int i,n,id;

              char name[50];

              FILE *fptr;

              //store

              fptr=fopen("student.txt","w");

              printf("How many data do you want to enter?\n");

              scanf("%d",&n);

              printf("Enter id and name of students:");

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

              {

              scanf("%d %s",&id,name);

              fprintf(fptr,"%d %s\n",id,name);

              }

             

              fclose(fptr);

             

             //display

fptr=fopen("student.txt","r");

              while(fscanf(fptr,"%d %s",&id,name) !=EOF)

              {

                            printf("%d %s\n",id,name);

              }

              fclose(fptr);

              return 0;

}            

              

       

⚠️ For JavaScript important questions :

CLICK HERE