NEB class 12 computer science 2078 BS board exam solution. This exam was held internal in the school whereas question was published by NEB. 2077/78 Class 12 is the last batch to appear in old grid board examination.
#include <stdio.h>
int main( )
{
int n;
printf(“ Press 1 for Sunday 2 for Monday and so on”);
scanf(“%d”, &n);
switch(n)
{
case 1:
printf(“Sunday”);
break;
case 2:
printf(“Monday”);
break;
case 3:
printf(“Tuesday”);
break;
case 4:
printf(“Wednesday”);
break;
case 5:
printf(“Thursday”);
break;
case 6:
printf(“Friday”);
break;
case 7:
printf(“Saturday”);
break;
default:
printf(“Invalid input”);
}
}
b) Demonstrate the FOR loop with example.
// Program to display first 10 natural number
#include <stdio.h>
int main( )
{
int i;
for(i=1; i<=10; i++)
{
printf(“%d”, i);
}
return 0;
}
2. What is array? Write a program to input any 10 numbers in an array and display it. 4+6
#include <stdio.h>
int main ( )
{
int i, n[10];
printf(“Enter 10 number”);
for(i=1; i<=10; i++)
{
scanf(“%d”, &n[i]);
}
printf(“Entered values are: “);
for(i=1; i<=10; i++)
{
printf(“%d”, &n[i]);
}
return 0;
}
3. Define function in C. Write a program to calculate factorial of a given number using function. 4+6
#include<stdio.h>
void fact (void);
int main( )
{
fact( );
return0;
}
void fact( )
{
int n, i, f=1;
printf(“Enter any number”);
scanf(“%d”, &n);
for(i=1; i<=n; I++)
{
f=f*i;
}
printf(“Factorial is %d”, f);
}
Click here for factorial of given number using recursive function
4. Why do you use structure ? Write a program to input teacher id, name, address and subject of 10 teachers and display them properly using structure. 2+8
#include<stdio.h>
struct teacher
{
int id;
char n[10], a[10], s[10];
};
struct teacher t[10];
int main( )
{
int i;
printf(“Enter teachers id, name, address and subject”);
for(i=1;i<=10;i++)
{
scanf(“%d %s %s %s”, &t[i].id, t[i].n, t[I].a, t[i].s);
}
printf(“Entered data are:”);
for(i=1;i<=10;i++)
{
printf(“%d %s %s %s”, t[i].id, t[i].n, t[i].a, t[i].s);
}
return 0;
}
5. What is pointer? Write a program to enter the name, mobile and post of employee and write it in file “worker.dat” in C program. 4+6
#include <stdio.h>
int main ( )
{
int n, i, m;
char n[10], p[10];
FILE *fp;
fp = fopen(“worker.dat”, “w”);
printf(“Enter the number of records”);
scanf(“%d”, &n);
printf(“Enter Name, Mobile and Post of employees”);
for(i=1; i<=n; i++)
{
scanf(“%s %d %s”, n, &m, p);
fprintf(fp, “%s %d %s”, n, m, p);
}
fclose(fp);
return 0;
}
Click here for all C theory.
Click here for Group B solution
Click here for all subject board exam question.