Showing posts with label cprogramming. Show all posts
Showing posts with label cprogramming. 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

C program to find fibonacci series (using FOR Loop)

C program to find fibonacci series:

#include<stdio.h>
#include<conio.h>
main()
{
int i,x,y,z,n;
clrscr();
printf("\nEnter a number:");
scanf("%d",&n);
x=0;
y=1;
printf("%d%d",x,y);
for(i=3;i<=n;i++)
{
z=x+y;
printf("%d ",z);
x=y;
y=z;
}
getch();
return 0;
}



OUTPUT:

Enter a number: 8
       0 1 1 2 3 5 8 13
 

C program to check whether a number is EVEN or ODD

C program to check whether a number is EVEN or ODD

#include<stdio.h>
#include<conio.h>
main()
{
int number;
clrscr();
printf("Enter any integer: ");
scanf("%d", &number);
if(number%2==0)
printf("%d is even number.",number);
else
printf("%d is odd number.",number);
getch();
return 0;
}



OUTPUT:

Enter any integer: 17

17 is odd number. 

 

Monday, 4 November 2013

C program to find quotent and remainder of 2 integers

C program to find quotent and remainder of 2 integers:

#include<stdio.h>
#include<conio.h>
main()
{
int n,t,quot,rem;
clrscr();
printf("\nEnter two numbers: \t");
scanf("%d%d",&n,&t);
quot=(n/t);
rem=(n%t);
printf("Quotient is: %d",quot);
printf("Remainder is: %d", rem);
getch();
return 0;
}

C program to find average of 3 integers ( average of 3 numbers)

C program to find average of 3 integers ( average of 3 numbers)

#include<stdio.h>
#include<conio.h>
main()
{
int n,s,r,avg;
clrscr();
printf("\nEnter 3 numbers : \t"); 
scanf("%d%d%d",&n,&s,&r);
avg=(n+s+r)/3;
printf("\nAverage of 3 numbers is: %d ", avg);
getch();
return 0;
}


OUTPUT:

 Enter 3 numbers: 15 6 8

Average of 3 numbers is: 9

 

Sunday, 3 November 2013

C program to display ASCII code of a character

Program to display ASCII code of a character:

#include<stdio.h>
#include<conio.h>
main()
{
char n;
clrscr();
printf("\nEnter a character: \t");
scanf("%c",&n);
printf("Result: %c",n); 
getch();
return 0;
}


OUTPUT:

Enter a character: A

Result: 65  

C program to print square of a number given by the user

Program to print square of a number given by the user

#include<stdio.h>
#include<conio.h>
main()
{
int n,sq;
clrscr();
printf("\nEnter a number:\t");
scanf("%d",&n);
sq=n*n;
printf("Result: %d",sq);
getch();
return 0;
}


OUTPUT:

Enter a number: 3

Result: 9 

C program to add 2 integers ( program to add 2 numbers)

Program to add 2 integers ( program to add 2 numbers)

#include<stdio.h>
#include<conio.h>
main()
{
int n,i,sum;
clrscr();
printf("\nEnter two numbers:\t");
scanf("Sum=%d",sum);
getch();
return 0;
}


OUTPUT:

Enter two numbers: 5 6

Sum= 11 

C program to print "Good Morning"

Program to print "Good Morning"

#include<stdio.h>
#include<conio.h>
main()
{
clrscr();
printf("Good Morning!");
gect();
}

Output:

Good Morning!

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