NEB C Programming Question Collection by Notehubs Nepal In this blog, we cover everything you need to know, from the basics to the more advanced topics. You'll learn about different problem related to functions, array, file handling, pointers etc. Each topic is explained simply and comes with example questions and solutions to help you understand it thoroughly.
Our goal is to help you succeed not only in the NEB exam but also in real-life programming situations. We focus on clarity and depth, breaking down complex concepts into easy-to-understand explanations. By the end, you'll feel confident writing efficient and elegant code.
1. Write a program to print whether a given number is prime or composite number.
Solutions:
#include<stdio.h>
int main(){
int a;
printf("Enter a number to check \n");
scanf("%d",&a);
int b;
int c=0;
for(b=1;b<=a;b++){
if(a%b==0){
c=c+1;
} }
if(c==2){
printf("It is prime number");
}
else{
printf("It is composite number");
}
return 0;
}
2. Write a program to find given number is even or odd using C program.
Solutions:
#include <stdio.h>
int main() {
int num;
printf("Enter a number: ");
scanf("%d", &num);
if (num % 2 == 0) {
printf("%d is even.\n", num);
} else {
printf("%d is odd.\n", num);
}
return 0;
}
3. Write a to display Fibonacci series using C program with functions.
Solutions:
#include<stdio.h>
void fibonacciSeries(int range)
{
int a=0, b=1, c;
while (a<=range)
{
printf("%d\t", a);
c = a+b;
a = b;
b = c;
}
}
int main()
{
int range;
printf("Enter range: ");
scanf("%d", &range);
printf("The fibonacci series is: \n");
fibonacciSeries(range);
return 0;
}
4. Write a program to find factorial of given number using recursive function.
Solutions:
#include<stdio.h>
#include<conio.h>
int fact(int);
void main(){
int n,f;
printf("Enter no. for finding factorial :");
scanf("%d",&n);
f=fact(n);
printf("factorial is %d",f);
getch();
}
int fact(int n){
if(n==0){
return(1);
}
else{
return(n*fact(n-1));
}
}
5. Write a program to find sum of given ‘n’ numbers in array using function.
Solutions :
#include <stdio.h>
int sumofarray(int a[],int n)
{
int i,sum=0;
for(i=0; i<n; i++)
{
sum+=a[i];
}
return sum;
}
int main()
{
int a[1000],i,n,sum;
printf("Enter size of the array : ");
scanf("%d", &n);
printf("Enter number to do sum : ");
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
sum=sumofarray(a,n);
printf("sum of array is :%d",sum);
}
6. Write a display to Sunday to Saturday when user enters a number using switch case in c program.
Solutions:
#include <stdio.h>
int main() {
int a ;
printf("Enter a day number\n");
scanf("%d",&a);
switch(a){
case 1 : printf("This is Sunday");
break;
case 2: printf("This is Monday");
break;
case 3: printf("This is Tuesday");
break;
case 4: printf("This is Wednesday");
break;
case 5 :printf("This is Thursday");
break;
case 6:printf("This is Friday");
break;
case 7: printf("This is Saturday");
break;
default: printf("This is Invalid number");
}
return 0;
}
7. Write a c program to find whether a given string is palindrome or not.
Solutions :
#include<stdio.h>
#include<string.h>
int main()
{
char s1[1000],s2[1000];
printf("Enter the string: ");
gets(s1);
strcpy(s2,s1);
strrev(s2);
if(!strcmp(s1,s2))
printf("string is palindrome");
else
printf("string is not palindrome");
return 0;
}
8. Write a c program to input 2*2 matrix element and display the transpose of matrix.
Solutions:
#include<stdio.h>
void main()
{
int mat[2][2],transpose[2][2];
int i;
int j;
printf("Transpose of 2*2 matrix\n");
printf("Enter the elements of the matrix\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
scanf("%d",&mat[i][j]);
}
}
printf("The matrix\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",mat[i][j]);
}
printf("\n");
}
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
transpose[j][i]=mat[i][j];
}
}
printf("The transpose of the matrix is\n");
for(i=0;i<2;i++)
{
for(j=0;j<2;j++)
{
printf("%d\t",transpose[i][j]);
}
printf("\n");
}
}
9.WAP to enter the 20 employee’s name, age, and salary using structure and print them.
Solutions :
#include<stdio.h>
struct emp
{
char n[100];
int age;
int sal;
};
struct emp e[20];
int main()
{
int i;
printf("Enter employee name age and salary\n");
for(i=0;i<20;i++)
{
scanf("%s %d %d",e[i].n,&e[i].age,&e[i].sal);
}
printf("Name \t Age \t Salary");
for(i=0;i<20;i++)
{
printf("%s\t %d\t %d\t",e[i].n,e[i].age,e[i].sal);
}
return 0;
}
10. Write a c program to find whether a given number is Armstrong or not.
Solutions:
#include<stdio.h>
int isArmstrong(int number)
{
int lastDigit = 0;
int power = 0;
int sum = 0;
int n = number;
while(n!=0) {
lastDigit = n % 10;
power = lastDigit*lastDigit*lastDigit;
sum += power;
n /= 10;
}
if(sum == number) return 0;
else return 1;
}
int main()
{
int number;
printf("Enter number: ");
scanf("%d",&number);
if(isArmstrong(number) == 0)
printf("%d is an Armstrong number.\n", number);
else
printf("%d is not an Armstrong number.", number);
return 0;
}
Concussion
Understanding these concepts is very important because these types of questions come every year. They will help boost your confidence in C programming. Throughout this blog, we've covered a wide range of topics, from basic concepts to more advanced techniques, with the aim of providing a understanding of C programming. Each topic was accompanied by example questions and solutions to help your learning.
As you continue your journey in mastering C programming, remember to practice regularly and apply the concepts in practical projects. Don't hesitate to reach out if you have any questions or if there are specific topics you'd like to see covered in more detail.