Showing posts with label c_Array. Show all posts
Showing posts with label c_Array. Show all posts

Monday, 11 November 2013

C program to find largest and second largest among four numbers


C program to find largest and second largest among four numbers:

#include<stdio.h>
#include<conio.h>

 main()
{
    int A[4];
    int i,j,b;
clrscr();
   for(i=0;i<4;i++)
{
   printf("\nEnter the Number %d : ", i+1);
   scanf("%d", &A[i]);
}
   for(i=0;i<4;i++)
{
   for(j=i;j<4;j++)
{
   if(A[i]< A[j])
{
   b=A[j];
  A[j]=A[i];
  A[i]=b;
}
}
}
  printf("\nLargest Number is: %d\n",A[0]);
  printf("\nSecond Largest Number is : %d\n",A[1]);
getch();
return 0;
}



OUTPUT:







  

Thursday, 7 November 2013

C program to find Fibonacci series of a number (using ARRAY)

C program to find Fibonacci series of a number (using ARRAY)

#include<stdio.h>
#include<conio.h>
main()
{

    int i,n;
    long int arr[40];

    printf("Enter the number range: ");
    scanf("%d",&n);

    arr[0]=0;
    arr[1]=1;

    for(i=2;i<n;i++){
         arr[i] = arr[i-1] + arr[i-2];
    }

    printf("Fibonacci series is: ");
    for(i=0;i<n;i++)
         printf("%ld ",arr[i]);
 
getch();   

return 0;
}




OUTPUT:

Enter the number range: 8

Fibonacci series is: 0 1 1 2 3 5 8 13

 
Design by Free WordPress Themes | Bloggerized by Lasantha - Premium Blogger Themes | Lady Gaga, Salman Khan