Index
Problem No. Problem Name Page No.
01 Write a program in C to find the factorial 02
of a given number.
02 Write a program in C to check whether 02
the given number is prime or not.
03 Write a program in C to find the 03
summation of Even numbers between 1
to 100.
04 Write a program in C to find the 04
maximum number and its position in an
array from the given numbers.
05 Write a program in C to find the 05
summation of prime numbers between 1
to 100.
06 Write a program in C to arrange the 06
numbers in ascending order.
07 Write a program in C to count the number 07
of vowels, consonant and blank spaces in
a sentence.
08 Write a program in C to transpose a 09
matrix spaces in sentence.
09 Write a program in C for matrix addition. 10
10 Write a program in C for matrix 11
multiplication.
1|Page
1.Write a program in C to find the factorial of a given number.
#include<stdio.h>
#include<conio.h>
int main()
clrscr();
long int i, fact=1, int No;
printf("Enter the number:");
scanf("%d", &No);
for(i=n; i<=No; i++)
fact=fact*i;
printf("\n The factorial is :%d", fact);
getch();
return 0;
2.Write a program in C to check whether the given number is prime
or not.
#include<stdio.h>
#include<conio.h>
int main()
clrscr();
2|Page
int no, I, flag=1;
printf(“Enter the number:”);
scanf(“%d”, &no);
goto l;
for(i=2; i<no ; i++)
if(no % i==0)
flag=0;
break;
if (flag==1)
printf("\n prime");
else
l: printf("\n not prime");
getch();
return 0;
3.Write a program in C to find the summation of Even numbers
between 1 to 100.
#include<stdio.h>
#include<conio.h>
int main()
3|Page
{
clrscr();
int i, sum =0;
for(i=1 ; i<=100 ; i++)
if(i%2 == 0)
sum = sum + i;
printf(“The summation of even number is: %d”, sum);
getch();
return 0;
4.Write a program in C to find the maximum number and its position
in an array from the given numbers.
#include<stdio.h>
#include<conio.h>
int main()
clrscr();
int i,max,pos,n,a[100];
printf("How many numbers do you want?:");
scanf("%d",&n);
printf("\n Enter the numbers:");
for(i=1; i<=n; i++)
4|Page
scanf("%d",&a[i]);
max=a[1];
pos=1;
for(i=1; i<=n; i++)
if(max<a[i])
max = a[i];
pos= i;
printf("\n The maximum number and its position are:%d%d",max,pos);
getch();
return 0;
5.Write a program in C to find the summation of prime numbers
between 1 to 100.
#include<stdio.h>
#include<conio.h>
int main()
clrscr();
5|Page
int i, j, flag, sum = 0;
for(i=2; i<=100; i++)
flag=1;
for(j=2; j<i; j++)
if(i%j == 0)
flag=0;
break;
if (flag == 1)
sum=sum+i;
printf("The summation of prime numbers :%d",sum);
getch();
return 0;
6.Write a program in C to arrange the numbers in ascending order.
#include<stdio.h>
#include<conio.h>
int main()
{
6|Page
clrscr();
int no, i, j, temp, a[100];
printf("How many numbers do you want ?:");
scanf("%d",&no);
printf(" Enter the numbers:");
for(i=1; i<=no; i++)
scanf("%d",&a[i]);
for(i=1; i<=no; i++)
for(j=i+1; j<=no; j++)
if( a[i] > a[j] )
temp = a[j];
a[j] = a[i];
a[i] = temp;
printf("\n The ascending numbers are :");
for(i=1; i<=no; i++)
printf("\n%d",a[i]);
getch();
return 0;
7.Write a program in C to count the number of vowels, consonant and
blank spaces in a sentence.
7|Page
#include<stdio.h>
#include<conio.h>
#include<ctype.h>
int main()
clrscr();
int v=0, c=0, b=0, i, n;
char s[100];
printf("Enter the sentence");
gets(s);
n = strlen(s);
for(i=0; i<n; i++)
s[i] = tolower s[i];
if(s[i]=='a'||s[i]=='e'||s[i]=='i'|| s[i]=='o'|| s[i]=='u')
v = v+1;
else if( s[i] == ' ')
b = b+1;
else
c = c+1;
printf("\n The vowel is %d \n The consonant is %d \n The blank space is %d ",v
, c, b);
8|Page
getch();
return 0;
8.Write a program in C to transpose a matrix spaces in sentence.
#include<stdio.h>
#include<conio.h>
int main()
clrscr();
int a[5][5] , i, j, n;
printf(" Enter the row and column size:");
scanf("%d %d",&n);
printf("\n Enter the elements of a matrix:");
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
scanf("%d", & a[i] [j] );
printf("\n The transpose of a matrix is:");
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
printf("%5d", a[j] [i]);
printf("\n");
9|Page
}
getch();
return 0;
9.Write a program in C for matrix addition.
#include<stdio.h>
#include<conio.h>
int main()
int a[4][4], b[4][4], c[4][4], i, j, n;
printf("Enter the number of rows and columns : ");
scanf("%d ", &n);
printf("\n Enter the element of 1st matrix");
for(i=1; i<=n ; i++)
for(j=1; j<=n; j++)
scanf("%d", & a[i] [j] );
printf("\n Enter the elements of 2nd matrix");
for(i=1; i<=n; i++)
for(j=1; j<=n; j++){
scanf("%d",&b[i] [j]);
printf(" \n Enter the elements of 3rd matrix");
for(i=1; i<=n; i++)
10 | P a g e
for(j=1; j<=n; j++)
c[i] [j]= a[i] [j] + b[i] [j];
printf(“\n The matrix addition is :”);
for (i=1; i<=n; i++)
for (j=1 ; j<=n; j++)
printf(“%5d”, c [i] [j]);
printf("\n");
getch();
return 0;
10.Write a program in C for matrix multiplication.
#include<stdio.h>
#include<conio.h>
int main()
clrscr();
int i, j, k, n, a [4] [4], b [4] [4], c [4] [4];
printf("Enter the number of rows and columns : ");
scanf("%d ",& n);
printf(“\n Enter the elements of 1st matrix”);
11 | P a g e
for(i=1; i<=n; i++)
for(j=1; j<=n; j++){
scanf("%d",&a[i] [j] );
printf("\n Enter the elements of 2nd matrix ");
for(i=1; i<=n; i++)
for(j=1; j<=n; j++)
scanf("%d",& b[i] [j]);
printf(“\n Enter the elements of 3rd matrix” );
for(i=1; i<=n; i++)
for(j=1; j<=n; j++) {
c[i] [j] = 0;
for(k=1; k<=n; k++)
c[i] [j] = c[i] [j] + a [i] [k]* b[k] [j];
printf(" \n The matrix multiplication is:");
for(i=1; i<=n; i++) {
for(j=1; j<=n; j++){
printf("%5d", c[i] [j]);
printf("\n"); }
getch();
return 0;
12 | P a g e