Nakum Anil

PRACTICAL-SET-4

4_1.c
Write a program to print Fibonacci series. 1,1,2,3,5,……N


#include<stdio.h>
#include<conio.h>
void main()
{
int a=0,b=1,i,n,sum=0;
clrscr();
    printf("\n Enter the value ");
    scanf("%d",&n);
    printf("\t1");
for(i=0;i<=n;i++)
   {
    if(i<1)
      {
       sum=1;
      }
    else
      {
       sum=a+b;
       a=b;
       b=sum;
       printf("\n\t%d",sum);
      }
   }
getch();
}



4_2.c
 Write a program to reverse the digit.


#include<stdio.h>
#include<conio.h>
void main()            
{
long int a,n;
clrscr();
    printf("Enter the value ");
    scanf("%ld",&n);
while(n!=0)
     {
      a=n%10;
      n=n/10;
      printf("%ld",a);
     }
getch();
}



4_3.c
 Add, subtract and multiply two nos. using switch statement.


#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,n,I,J,K;
clrscr();
    printf("Enter the value of a=");
    scanf("%d",&a);
    printf("Enter the value of b=");
    scanf("%d",&b);
    printf("Enter the char");
    scanf("%c",&n);
switch(n=getchar())
      {
      case 'a':
    I=a+b;
    printf("Addition of a&b is= %d",I);
      break;
      case 's':
    J=a-b;
    printf("Subsstrction of a&b is= %d",J);
      break;
      case 'm':
    K=a*b;
    printf("Multiplication of a&b is= %d",K);
      break;
       }
getch();
}



4_4.c
 Write a program to add two matrixes.


#include<stdio.h>
#include<conio.h>
void main()
{
int a[2][2],b[2][2],c[2][2],i,j;
clrscr();
printf("\nEnter the value Matrix-1\n");
for(i=0;i<2;i++)
   {
   for(j=0;j<2;j++)
      {
       scanf("%d",&a[i][j]);
      }
   }
printf("\nEnter the value Matrix-2\n");
for(i=0;i<2;i++)
   {
   for(j=0;j<2;j++)
      {
       scanf("%d",&b[i][j]);
      }
   }
printf("\nSum of two matrix 1&2 \n");
for(i=0;i<2;i++)
   {
   for(j=0;j<2;j++)
      {
      c[i][j]=a[i][j]+b[i][j];
      printf("\n%d",c[i][j]);
      }
   }
getch();
}



4_5.c
 Write a program to given no in ascending order.


#include<stdio.h>
#include<conio.h>
void main()
{
int a[5],i,j,t;
clrscr();
for(i=0;i<5;i++)
   {
   printf("Enter the Element %d=",i+1);
   scanf("%d",&a[i]);
   }
for(i=0;i<5;i++)
   {
   for(j=i+1;j<5;j++)
      {
       if(a[i]>a[j])
     {
     t=a[i];
     a[i]=a[j];
     a[j]=t;
     }
      }
   }
    printf("the Ascending order is");
for(j=0;j<5;j++)
   {
   printf("%5d",a[j]);
   }
getch();
}



4_6.c
  W.A.P to read array of integers and print it in reverse order

#include<stdio.h>
#include<conio.h>
void main()
{
int a[50],i,t;
clrscr();
    printf("Enter the num.");
    scanf("%d",&t);
for(i=0;i<t;i++)
   {
   printf("Enter the Element %d=",i+1);
   scanf("%d",&a[i]);
   }
    printf("\nthe reverse arrey is\n");
for(i--;i>=0;i--)
   {
   printf("%d\n",a[i]);
   }
getch();
}

No comments:

Post a Comment