1.
SUM OF N NATURAL NUMBERS
#include <stdio.h>
#include<conio.h>
void main()
 {
   int n, i, sum = 0;
   clrscr();
   printf("Enter a Number: ");
   scanf("%d", &n);
     for (i = 1; i <= n; ++i)
   {
      sum =sum+ i;
   }
   printf("Sum = %d", sum);
  getch();
}
OUTPUT
Enter a positive integer: 3
Sum = 6
2.TO FIND THE LARGEST OF GIVEN 3 NUMBERS
#include <stdio.h>
#include<conio.h>
void main()
{
    int a, b, c;
    clrscr();
    printf("Enter a,b,c: ");
    scanf("%d %d %d", &a, &b, &c);
    if (a > b && a > c)
   {
        printf("a is Greater than b and c");
   }
   else if (b > a && b > c)
 {
       printf("b is Greater than a and c");
  }
    else if (c > a && c > b)
 {
       printf("c is Greater than a and b");
  }
   else
{
        printf("all are equal or any two values are equal")
}
    getch();
}
OUTPUT
Enter a,b,c: 10 5 7
a is Greater than b and c
3.TO SOLVE QUADRIC EQUATION
# include<stdio.h>
# include<conio.h>
# include<math.h>
void main ()
 {
    float a,b,c,r1,r2,d;
    printf ("Enter the values of a b c: ");
    scanf (" %f %f %f", &a, &b, &c);
    d= b*b - 4*a*c;
     if (d>0)
    {
        r1 = -b+sqrt (d) / (2*a);
        r2 = -b-sqrt (d) / (2*a);
        printf ("The real roots = %f %f", r1, r2);
    }
    else if (d==0)
   {
        r1 = -b/(2*a);
        r2 = -b/(2*a);
        printf ("Roots are equal =%f %f", r1, r2);
    }
    else
        printf("Roots are imaginary");
         getch();
}
OUTPUT
Enter the values of a b c: 1 2 1
Roots are equal =-1.000000 -1.000000
4.TO FIND THE SIMPLE AND COMPOUND INTEREST
#include<stdio.h>
#include<conio.h>
#include<math.h>
void main()
{
  float p, r, t;
  clrscr();
  printf("Enter Principal Amount: ");
  scanf("%f", &p);
    printf("Enter Time Period: ");
    scanf("%f", &t);
    printf("Enter Rate of Interest: ");
    scanf("%f", &r);
    printf("Simple Interest = %f\n", (p*r*t)/100.0);
    printf("Compound Interest = %f\n", p*pow(1+r/100, t) - p);
}
OUTPUT
Enter Principal Amount: 5000
Enter Time Period: 2
Enter Rate of Interest: 18
Simple Interest = 1800.000000
Compound Interest = 1962.000788
5. TO READS AN INTEGER N AND DETERMINE THE WHETHER N IS
PRIME OR NOT
#include <stdio.h>
#include<conio.h>
void main()
{
  int n;
  clrscr();
   printf("Enter the number: ");
   scanf("%d",&n);
   if(n == 1)
   {
      printf("1 is neither prime nor composite.");
      getch();
   }
   int count = 0;
   for(int i = 2; i < n; i++)
  {
      if(n % i == 0)
         count++;
  }
   if(count == 0)
  {
      printf("%d is a prime number.", n);
  }
   else
   {
      printf("%d is not a prime number.", n);
   }
   getch();
}
OUTPUT
Enter the number: 5
5 is a prime number.
Enter the number: 9
9 is not a prime number.
6. TO ARRANGE THE NUMBER IN ASCENDING AND DESCENDING
ORDER
#include <stdio.h>
#include<conio.h>
void main()
{
      int a[100],n,i,j;
      clrscr();
      printf("Array size: ");
     scanf("%d",&n);
     printf("Elements: ");
        for(i=0;i<n;i++)
    {
         scanf("%d",&a[i]);
    }
          for (int i = 0; i < n; i++)
          {
                 for (int j = 0; j < n; j++)
                 {
                         if (a[j] > a[i])
                         {
                                 int tmp = a[i];
                                 a[i] = a[j];
                                 a[j] = tmp;
                         }
                 }
          }
          printf("\n\nAscending : ");
     for (int i = 0; i < n; i++)
     {
            printf(" %d ", a[i]);
     }
     for (int i = 0; i < n; i++)
     {
            for (int j = 0; j < n; j++)
            {
                    if (a[j] < a[i])
                    {
                            int tmp = a[i];
                            a[i] = a[j];
                            a[j] = tmp;
                    }
            }
     }
     printf("\n\nDescending : ");
     for (int i = 0; i < n; i++)
     {
            printf(" %d ", a[i]);
     }
     getch();
}
OUTPUT
Array size: 5
Elements: 3 6 2 8 9
Ascending : 2 3 6 8 9
Descending : 9 8 6 3 2
7. TO GENERATE THE FIBONACCI SEQUENCE
#include <stdio.h>
#include<conio.h>
void main()
{
  int n, num1 = 0, num2 = 1, nextNum;
  clrscr();
  printf("Enter the number of Elements: ");
  scanf("%d", &n);
  printf("Fibonacci Series: ");
  for (int i = 1; i <= n; ++i)
   {
     printf("%d, ", num1);
     nextNum = num1 + num2;
     num1 = num2;
     num2 = nextNum;
   }
       getch();
}
OUTPUT
Enter the number of Elements: 10
Fibonacci Series: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34
8. TO FIND MEAN AND STANDARD DEVIATION
#include<math.h>
#include<stdio.h>
#include<conio.h>
void main()
{
 int i, n;
 float num[10], deviation, sum, sumsqr, mean, variance, stddev;
 sum = 0;
 sumsqr =0;
 n = 0;
clrscr();
 printf("Enter number of elements:\n");
 scanf("%d", &n);
 printf("Input %d values \n", n);
 for(i=0; i<n; i++)
 {
  scanf("%f", &num[i]);
  sum += num[i];
 }
 mean = sum/(float)n;
 printf("Mean is %f\n", mean);
 for(i=0;i<n;i++)
 {
  deviation = num[i] - mean;
  sumsqr += deviation * deviation;
 }
 variance = sumsqr/(float)n;
 stddev = sqrt(variance);
 printf("Standard Deviation is %f\n", stddev);
}
OUTPUT
Enter number of elements:
6
Input 6 values
5
2
3
6
9
8
Mean is 5.500000
Standard Deviation is 2.500000
9. TO FIND THE ADDITION AND SUBTARCTION OF TWO MATRIX
#include <stdio.h>
#include<conio.h>
void addMatrix(int rows, int cols, int mat1[10][10], int mat2[10][10], int
result[10][10])
 {
    for (int i = 0; i < rows; i++)
   {
       for (int j = 0; j < cols; j++)
      {
          result[i][j] = mat1[i][j] + mat2[i][j];
       }
   }
 }
void subtractMatrix(int rows, int cols, int mat1[10][10], int mat2[10][10], int
result[10][10])
 {
   for (int i = 0; i < rows; i++)
    {
      for (int j = 0; j < cols; j++)
      {
         result[i][j] = mat1[i][j] - mat2[i][j];
        }
    }
}
void displayMatrix(int rows, int cols, int mat[10][10])
{
   for (int i = 0; i < rows; i++)
  {
      for (int j = 0; j < cols; j++)
       {
         printf("%d\t", mat[i][j]);
       }
      printf("\n");
  }
}
void main()
 {
   int rows, cols;
   clrscr();
    printf("Enter the number of rows: ");
    scanf("%d", &rows);
    printf("Enter the number of columns: ");
    scanf("%d", &cols);
     int mat1[10][10], mat2[10][10], resultSum[10][10], resultDiff[10][10];
    printf("Enter elements of matrix1:\n");
    for (int i = 0; i < rows; i++)
   {
        for (int j = 0; j < cols; j++)
       {
           scanf("%d", &mat1[i][j]);
        }
    }
    printf("Enter elements of matrix2:\n");
    for (int i = 0; i < rows; i++)
     {
         for (int j = 0; j < cols; j++)
       {
         scanf("%d", &mat2[i][j]);
     }
     }
    addMatrix(rows, cols, mat1, mat2, resultSum);
    subtractMatrix(rows, cols, mat1, mat2, resultDiff);
    printf("\nSum of matrices:\n");
    displayMatrix(rows, cols, resultSum);
    printf("\nDifference of matrices:\n");
    displayMatrix(rows, cols, resultDiff);
    getch();
}
OUTPUT
Enter the number of rows: 3
Enter the number of columns: 3
Enter elements of matrix1:
111
222
333
Enter elements of matrix2:
444
555
666
Sum of matrices:
5      5    5
7      7    7
9      9    9
Difference of matrices:
-3    -3    -3
-3    -3    -3
-3    -3    -3
10. TO FIND THE MULTIPLICATION OF TWO MATRICES
#include<stdio.h>
#include<stdlib.h>
#include<conio.h>
void main()
{
int a[10][10],b[10][10],mul[10][10],r,c,i,j,k;
clrscr();
system("cls");
printf("Enter the number of row=");
scanf("%d",&r);
printf("Enter the number of column=");
scanf("%d",&c);
printf("Enter the first matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("Enter the second matrix element=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
scanf("%d",&b[i][j]);
}
}
printf("Multiply of the matrix=\n");
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
mul[i][j]=0;
for(k=0;k<c;k++)
{
mul[i][j]+=a[i][k]*b[k][j];
}
}
}
# for printing result
for(i=0;i<r;i++)
{
for(j=0;j<c;j++)
{
printf("%d\t",mul[i][j]);
}
printf("\n");
}
getch();
}
OUTPUT
Enter the number of row=3
Enter the number of column=3
Enter the first matrix element=
111
222
333
enter the second matrix element=
111
222
333
multiply of the matrix=
666
12 12 12
18 18 18