Video Tutorial for C Program Solved for HSEB Grade 12
To understand and use how to write C program. Useful for all and specially for HSEB Grade 12 Computer Science Students.
C Program to find the third angle value of a triangle
C Program to find Even or odd Number
C Program to display the first 20 multiples of user supplied number
C Program to find sum of each digits of a multi-digits number
C Program to display 2,8,18,32,50,72,98,128............. 17th terms.
#include<stdio.h>#include<conio.h> int main() { int i,j;
HSEB based important C questions
WAP in C:
To ask length and breadth, and display the area and perimeter of a rectangle.
To ask a number and check whether it is Even or odd number.
To supply a number and check whether it is Prime or Composite number.
To supply a number and display whether it is a multiple of 7 or not.
To supply a number and print its factors. (12=1,2,3,4,6,12)
To supply a number and print the total number of factors of a user supplied number. (12=6)
To ask radius of a circle and display circumference. (C=2πr)
Use for or while loop.
To ask the name and address of a person and print it for 25 times.
To enter the last number and print the sum of all numbers from 1 to that number.
To display the sum of first 10 multiples of 7.
To display the series: 1, 3, 5, 7, 9, 11, 13, 15, 17, 19.
To display multiplication table of 10 up to 100.
To display multiplication table of user entered number up to 10 times.
To display: 1, 2, 4, 7, 11, 16, 22, 29.
To display: 100, 85, 70, 55, 40, 25, 10.
To display: 1, 8, 27, 64, 125, ……. 1000.
To display: 2, 4, 8, 16, 32, 64, ……… 512.
To display: 2, 4, 6, 8, 10, 12,……………….. 50.
To display your favourite actor/actress name for 15 times.
To enter the marks of 5 subjects. Calculate total marks, percentage and division.
Use while or do-while loop.
To enter a number and find the sum of each digits. (123=6)
To enter a number and find the product of each digits.(234=24)
To enter a multi-digits number and display square of each digits. (123=1,4,9)
To enter a multi-digits number and display the sum of squares of each digits. (123=1+4+9=14)
To enter multi-digits number and display the revere of the supplied number. (1234=4321)
Hailstone Series
#include<stdio.h>
#include<conio.h>
int main()
{
int x=3, i;
printf("Hailstone Series:\n");
for(i=1;i<=15;i++)
{
printf("%d\t",x);
if(x % 2==0)
x=x/2;
else
x=(x*3)+1;
}
getch();
}
Fibonacci Series
Here is an example C program for finding 'Fibonacci' series.
#include<stdio.h>
#include<conio.h>
int main()
{
int i, a,b,c;
a=1;
b=1;
printf("Fibonacci Series\n");
for(i=1;i<=15;i++)
{
printf("%d\n",a);
c=a+b;
a=b;
b=c;
}
getch();
}
C Programs for HSEB 12
ARRAY
/*Program to input values into an array and display them.*/
#include
#include
void main()
{
int arr[5],i;
clrscr();
for(i=0;i<5;i++)
{
printf("Enter he value for array[%d] :",i);
scanf("%d",&arr[i]);
}
printf("The array elements are"\n");
for(i=0;i<5;i++)
printf("%d\t",arr[i]);
printf("\n");
getch();
}
/* Program to add the elements of an array. */
#include
#include
void main()
{
int arr[0],I,sum=0;
clrscr();
for(i=0;i<10;i++)
{
printf("Enter the value for arr[%d]:", i);
scanf("%d",&arr[i]);
sum=sum+arr[i];
}
printf("Sum of the elements of array = %d\n",sum);
getch();
}
/*Program to count even and odd numbers in a array*/ /*Program to find the maximum and minimum number in an array. */ /*Program to reverse the elements of an array. */ /* Program input and display a matrix */ /* Program for addition of two matrices. */ /* Program for multiplication of two matrices. */ STRINGS /* Program to print characters of a string and address of each characters. */ /*Program to understand the work of strlen() fuction. */ /*Program to understand the work of strcmp() function */ /*Program to understand the work of strcpy() function. */ /*Program to understand the work of strcpy() function. */ /*Program to understand the work of strcat() function. */ /* Program to sort the array of strings. */ GENERAL /* Program to enter your name and address and print them 10 times. */ /* Program to enter a number and print whether it is EVEN or ODD.*/ /* Program to enter a number and print whether it is PRIME or COMPOSITE. */ /* Program to enter 3 numbers and print the (greatest)largest number. */ /* Program of sorting using selection sort. */ POINTERS /* Program to dereference pointer variables. */
#include
#include
#define size 10
void main()
{
int arr[size],i,even=0,odd=0;
clrscr();
for(i=0;i
#include
#include
void main()
{
int i,arr[10]={2,5,4,1,8,9,11,6,3,7}
int min,max;
clrscr();
min=max=arr[0];
for(i=1;i<10;i++)
{
if(arr[i]
max=arr[i];
}
printf("Minimum number in array = %d, Maximum number in array = %d\n",min,max);
getch();
}
#include
#include
void main()
{
int i,j,temp,arr[10]={1,2,3,4,5,6,7,8,9,10};
clrscr();
for(i=0,j=9;i
#include
#include
#define row3
#define col 4
void main()
{
int mat[row][col],i,j;
printf("Enter the elements of matrix[%dx%d] row-wise :\n",row,col);
for(i=0;i
#define row 3
#define col 4
#include
#include
void main()
{
int i,j,mat1[row][col],mat2[row][col],mat3[row][col];
clrscr();
printf("Enter matrix mat1(%dx%d) row-wise : \n",row,col);
for(i=0;i
#define row1 3
#define col1 4
#define row2 col1
#define col2 2
#include
#include
void main()
{
int i,j,k,mat1[row1][col1],mat2[row2][col2],mat3[row1][col2];
clrscr();
printf("Enter matrix mat1(%dx%d) row-wise : \n",row1,col1);f
for(i=0;i
/* Program for input and output of strings using scanf() and printf() function. */
#include
#include
#include
void main()
{
char str[40]="Welcome to the world of Strings";
clrscr();
printf("String is : %s\n",str);
printf("Enter new value for string :\n");
gets(str);
printf("New string is : %s\n",str);
getch();
}
#include
#include
void main()
{
char str[]="Nepal";
int i;
for(i=0;str[i]!='\0';i++)
{
printf("Character - %c\t", str[i]);
printf("Address = %u\n, str[i]);
}
getch();
}
#include
#include
void main()
{
char str[20];
int length;
clrscr();
printf("Enter the string.\n");
gets(str);
length=strlen(str);
printf("Length of the string is : %d\n", length);
getch();
}
#include
#include
#include
void main()
{
char str1[10],str2[10];
printf("Enter the first string :");
gets(str1);
printf("Enter the second string :");
gets(str2);
if((strcmp(str1,str2))==0)
printf("Strings are same.\n");
else
printf("Strings are not same.\n");
getch();
}
#include
#include
#include
void main()
{
char str1[10],str2[10];
clrscr();
printf("Enter the first string :");
gets(str1);
printf("Enter the second string :");
gets(str2);
strcpy(str1,str2);
printf("First string :%s \t\t Second string :%s\n",str1,str2);
strcpy(str1,"Nepal");
strcpy(str2,"Kathmandu");
printf("First string :%s \t\t Second string :%s\n",str1,str2);
getch();
}
#include
#include
#include
void main()
{
char str1[20],str2[20];
clrscr();
printf("Enter the first string :");
gets(str1);
printf("Enter the second string :");
gets(str2);
strcat(str1,str2);
printf("First string :%s \t Second string :%s\n",str1,str2);
strcat(str1,"Computer");
printf("Now the first string is : %s \n",str1);
getch();
}
#include
#include
#include
void main()
{
char str1[20], str2[20];
clrscr();
printf("Enter the first string :");
gets(str1);
printf("Enter the second string :");
gets(str2);
printf("First string is : %s \t Second string is : %s\n",str1,str2);
strcat(str1,str2);
printf("Now first string is : %s \n",str1);
getch();
}
#include
#include
#include
#define n 5
#define len 10
void main()
{
char str1[20], str2[20];
clrscr();
char arr[n][len]={"white","red","green","yellow","blue"};
char temp[10];
int i,j;
printf("Before sorting :\n");
for(i=0;i
{
strcpy(temp,arr[i]);
strcpy(arr[i],arr[j]);
strcpy(arr[j],temp);
}
printf("After sorting :\n");
for(i=0;i
/*Program to enter length and breadth & print area and perimeter of rectangle.*/
#include
#include
void main()
{
float l,b,a,p;
clrscr();
printf("Enter length and breadth\n");
scanf("%f",&l);
scanf("%f",&b);
a=l*b;
p=2*(l+b);
printf("The area of the rectangle is %f", a);
printf("The perimeter of the rectangle is %f",p);
getch();
}
#include
#include
void main()
{
char n[20], a[20];
int i;
clrscr();
printf("Enter your name and address.\n");
scanf("%s",&n);
scanf("%s",&a);
for(i=1;i<=10;i++)
{
printf("Your name is %s\n", n);
printf("Your address is %s\n",a);
}
getch();
}
#include
#include
void main()
{
int x;
clrscr();
printf("Enter a number\n");
scanf("%d",&x);
if(x%2==0)
printf("The supplied number is EVEN.\n");
else
printf("The supplied number is ODD.\n);
getch();
}
#include
#include
void main()
{
int a,r,i,c=0;
clrscr();
printf("Enter a number\n");
scanf("%d",&a);
for(i=1;i<=a;i++)
{
r=a%2;
if(r==0)
c=c+1;
}
If(c==2)
printf("The supplied number %d is prime",a);
else
printf("The supplied numer %d is composite\n",a);
getch();
}
#include
#include
void main()
{
int a,b,c;
clrscr();
If(a>b && a>c)
printf("the greatest number is %d", a);
else if(b>a && b>c)
printf("the greatest number is %d", b);
else
printf("the greatest number is %d", c);
getch();
}
#define size 10
#include
#include
void main()
{
int arr[size];
int i,j,temp;
printf("Enter elements of the array :\n");
for(i=0;i
{
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
}
}
printf("Sorted array in Descending Order is : \n");
for(i=0;i
/* Program to print address of variables using address operator. */
#include
#include
void main()
{
int age=24;
float sal=15000.75;
printf("Value of age = %d, Address of variable age = %u\n",age,&age);
printf("Value of sal = %.2f, Address of variable sal = %u\n",sal,&sal);
getch();
}
#include
#include
void main()
{
int a=100;
float b=4.5;
int *p1=&al;
float *p2=&b;
clrscr();
printf("Value of p1 = Address of a= %u\n", p1);
printf("Value of p2 = Address of b = %u\n",p2);
printf("Address of p1 = %u\n", &p1);
printf("Address of p2 = %u\n",&p2);
printf("Value of a = %d %d %d \n",a,*p1,*(&a));
printf("Value of b = %f %f %f \n", b,*p2, *(&b));
getch();
}




