Bangladesh National University Result

Custom Search

Wednesday, February 10, 2010

Basic C Programme For LAB final EXAM Practice

NOTICE : all header file written as stdio.h  but actually there a pair of Bracket as usual
#include stdio.h   //find out maximum,2nd,3rd & 4th maximum value from input numbers
void main()         //www.nabilphysics.blogspot.com
{
int a[50],max=0,max2=0,n,max3=0,max4=0;
printf("How many numbers:");
scanf("%d",&n);
 for(int i=0;i
 scanf("%d",&a[i]);
  for(i=0;i
     if(a[i]>max)
     max=a[i];
     printf("\t\nMaximum value:%d\n\t",max);

     /*2nd max calculation*/
     for(i=0;i
     if((a[i]max2))
     max2=a[i];
     printf("\n\a2nd Maximum value:%d\n",max2);
     /*3rd max calculation*/
     for(i=0;i
     if((a[i]max3))
     max3=a[i];
     printf("\n3rd Maximum is:%d",max3);
     //calculation of 4th maximum
     for(i=0;i
     if((max3>a[i])&&(max2>a[i])&&(max>a[i])&&(max4
     max4=a[i];
     printf("\n4th Maximum is:%d",max4);
    }

#include stdio.h //calculation average until press 0
void main()       // www.nabilphysics.blogspot.com
{
int n,avg,sum=0,count=0;
scanf("%d",&n);

  while(n!=0)
     {
        sum=sum+n;
        count=count+1;
        scanf("%d",&n);
      }
    avg=sum/count;
    printf("%d",avg);
 }

#include stdio.h  /*Programme to Reverse the sentence*/
#include string.h /*www.nabilphysics.blogspot.com*/
#include ctype.h
  void main()
    {
    printf("\n\a\tProgramme to reverse the sentence or word\n\n\b");
    do
    {

    char name[200];     
    printf("Please Enter your word or Sentence\n");
    gets(name);
    int a=strlen(name);
    printf("\n\aReverse order:\n");
      for(int b=a-1;b>=0;b--)
        {
         printf("%c",toupper(name[b]));
        }

    printf("\nLetter number is= %d\n\n",a);
    }
    while(1);
    }


#include stdio.h
long smaller(long x,long y);  //www.nabillphysics.blogspot.com
void main()                        //programme to compare two numbers
{
long a,b,min;
int n;
//printf("How many calculations:\n");
//scanf("%d",&n);
  while(a!=0||b!=0)    //exit when a and b both entered 0
     {
scanf("%ld",&a);
scanf("%ld",&b);
min=smaller(a,b);
printf("minimum:%ld\n",min);
     }
}

long smaller(long x,long y)
    {
    if(x<=y)
    return(x);
    else
    return(y);
    }



No comments:

Post a Comment

Search Anything you want.just write and click search and see the magic