Monday, July 31, 2017

Find largest and smallest no. in C

#include<stdio.h>
void main()
{
    int x[10],i,j,temp;
    for(i=0;i<=9;i++)
    {
        printf("Enter %dth number : ",i+1);
        scanf("%d",&x[i]);
    }
    for(i=0;i<=8;i++)
    {
        for(j=i+1;j<=9;j++)
        {
           if(x[i]<x[j])
           {
               temp=x[i];
               x[i]=x[j];
               x[j]=temp;
           }
        }
    }
    printf("\nThe largest of 10 entered numbers is %d",x[0]);
    //printf("\nThe smallest of 10 entered numbers is %d",x[9]);
    getch();
}

Related Posts:

  • Application of struct in C#include<stdio.h> #include<string.h> struct student {     char name[20];     int roll; }; void main() {   struct student s[10],t;   int i,n,j;   printf("Enter no. of students : "… Read More
  • Check if a no. is prime or not in C ?#include<stdio.h> int testprime(int ,int); void main() {     int n,prime;     printf("Enter a positive number : ");     scanf("%d",&n);     prime=testprime(n,n/2);   &nbs… Read More
  • Find fibonacci series in C#include<stdio.h> void fibonacci(int); void main() {     int n,first=0,second=1;     printf("Enter the number of fibonacci series to be printed : ");     scanf("%d",&n);     p… Read More
  • Find HCF in C#include<stdio.h> int hcf(int a,int b,int c) {     if(a%c==0 && b%c==0)     return c;     hcf(a,b,c-1); } void main() {     int h,x,y;     printf("Enter two numb… Read More
  • Check if 3rd digit of a no. is prime or not in C ?#include<stdio.h> int digitcount(int x) {     int r,c=0,i=0,y=x;     while(x!=0)     {         r=x%10;         x=x/10;         c+… Read More

0 comments:

Post a Comment