Sunday, September 22, 2013

"FUNCTIONS--CHAPTER NO. 6"

"FUNCTIONS--CHAPTER NO. 6"
Question No. 2
#include<stdio.h>
#include<conio.h>
int large(int a,int b);
void main(void)
{
                clrscr();
                int x,y,z;
                printf("Enter an integer value = ");
                scanf("%d",&x);
                printf("Enter second integer value = ");
                scanf("%d",&y);
                z=large(x,y);
                printf("Large value is %d",z);
                getch();
}

int large(int a,int b)
{
                if(a>b)
                {
                                return a;
                }
                else
                {
                                return b;
                }
}
Question No. 3
#include<stdio.h>
#include<conio.h>
int area(int l,int w);
void main(void)
{
                clrscr();
                int x,y,z;
                printf("Enter Length of Rectangle = ");
                scanf("%d",&x);
                printf("Enter Width of Rectangle = ");
                scanf("%d",&y);
                z=area(x,y);
                printf("Area of Rectange = %d",z);
                getch();
}

int area(int l,int w)
{
                int area;
                area=l*w;
                return area;
}
Question No. 4
#include<stdio.h>
#include<conio.h>
float temp(int c);
void main(void)
{
                clrscr();
                float f;
                printf("-------------------------------\n");
                printf("Centigrage\tFahrenheit\n");
                printf("-------------------------------\n");
                for(int i=0;i<=50;i+=5)
                {
                                f=temp(i);
                                printf("%d\t\t%f\n",i,f);
                }
                getch();
}

float temp(int c)
{
                float f;
                f=(c*1.8)+32;
                return f;
}
Question No. 5
#include<stdio.h>
#include<conio.h>
void func(void);
void main(void)
{
                clrscr();
                func();
                getch();
}
void func(void)
{
                char c;
                int n,sc=0;
                printf("Enter a phrase = ");
                c=getche();
                while(c!='\r')
                {
                n=c;
                if(n>=97 && n<=122)
                sc++;
                c=getche();
                }
                clrscr();
                printf("Number of Small case characters = %d",sc);
}
Question No. 6
#include<stdio.h>
#include<conio.h>
void pro(void);
void main(void)
{
                clrscr();
                pro();
                getch();
}

void pro(void)
{
                float arr[10],r=1;
                printf("Enter 10 floating values = ");
                for(int i=0;i<10;i++)
                {
                                scanf("%f",&arr[i]);
                }
                for(i=0;i<10;i++)
                {
                                r*=arr[i];
                }
                printf("Result = %f",r);
}
Question No. 7
#include<stdio.h>
#include<conio.h>
void func(void);
void main(void)
{
                clrscr();
                func();
                getch();
}
void func(void)
{
                int x[10],y[10],temp;
                for(int i=0;i<10;i++)
                {
                printf("Enter integer value for m[%d] = ",i);
                scanf("%d",&x[i]);
                }
                for(i=0;i<10;i++)
                {
                printf("Enter integer value for n[%d] = ",i);
                scanf("%d",&y[i]);
                }

                for(i=0;i<9;i++)
                {
                                for(int l=0;l<9-i;l++)
                                {
                                                if(x[l]>x[l+1])
                                                {
                                                temp=x[l];
                                                x[l]=x[l+1];
                                                x[l+1]=temp;
                                                }
                                }
                }
                for(i=0;i<9;i++)
                {
                                for(int l=0;l<9-i;l++)
                                {
                                                if(y[l]>y[l+1])
                                                {
                                                temp=y[l];
                                                y[l]=y[l+1];
                                                y[l+1]=temp;
                                                }
                                }
                }
                printf("Array X = ");
                for(i=0;i<10;i++)
                {
                printf("%d ",x[i]);
                }
                printf("\nArray Y = ");
                for(i=0;i<10;i++)
                {
                printf("%d ",y[i]);
                }

}


1 comment: