Saturday, March 31, 2012

Small program for swaping & average calculation

#include<stdio.h>
#include<stdlib.h>
#include <sys/types.h>
#include <time.h>
int i,n;
 main()
{
    int a,b,swap(),hellow();
    /*char getch(),k;*/
    char k;
    do
    {
    hellow();
    printf("Enter the value of A = ");
    scanf("%d",&a);
    printf("Enter the value of B = ");
    scanf("%d",&b);
    printf("values before swaping are
 A=%d B=%d
",a,b);
    swap(&a,&b);
    printf("values after swaping are
 A=%d B=%d
",a,b);
    printf("Press Y to continue or any other key to Terminate
");
/*    printf("Quit?  (y/n):  ");*/
    scanf("%s", &k);
    printf("

");
    }
    while (k == 'Y' || k == 'y');
     return (0);

    /* getchar() = k;
        if (k=!"N")
    {
            printf("U can continue
");
            main();
    }
        else
        {
            printf("U can break
");
            goto
        }    */
}

 swap(int*x,int*y)
 {
    int z;
    z=*x;
    *x=*y;
    *y=z;
    return(0);
}

  /* #include<stdio.h>
int i,n;
void main()     */
 hellow()
{
    int a[100];
    float Avg=0,sum=0;
    printf("Enter the value of N = ");
    scanf("%d",&n);
    for (i=0;i<n;i++)
    {
    printf("Enter the values = ");
    scanf("%d",&a[i]);
    sum=sum+a[i];
    }
    Avg= (sum/i);
    printf("Total=%f,Average=%f
",sum,Avg);
      return(0);
}


/*#include <stdio.h>
#include <sys/types.h>
#include <time.h>

main()
 abey()

  {  int i;
     time_t t1,t2;
      (void) time(&t1);
     for (i=1;i<=300;++i)
     printf("%d %d %dn",i, i*i, i*i*i);
     (void) time(&t2);
     printf("n Time to do 300 squares and cubes= %d secondsn", (int)
t2-t1);
     return(0);
 }
    */

No comments:

Post a Comment