Tuesday, 22 April 2014

Q. Write to calculate the gross salary of an employee of an organization with the conditions: i) if the basic > 25000, DA will be 60%, and house rent is 10% ii) if the basic <= 25000 but >15000, DA will be 65%, and house rent is 15% ii) if the basic <= 15000 , DA will be 70%, and house rent is 2000. [gross salary=basic+DA+house rent]

#include<stdio.h>
main()
{   
    float basic,da,hra,gross;
    printf("\nEnter basic salary=");
    scanf("%f",&basic);
    if(basic>25000)
    {
        da=0.6*basic;
        hra=0.1*basic;
    }
    else if(basic<=25000 && basic>15000)
    {
        da=0.65*basic;
        hra=0.15*basic;
    }
    else
    {
        da=0.7*basic;
        hra=2000;
    }
    gross=basic+da+hra;
    printf("\nDA=%f",da);
    printf("\nHouse rent=%f",hra);
    printf("\nGross salary=%f",gross);
}

Q. Write a C program to sort the records of n students on the basis of their height (descending order) if age of two or more employees are same then sort them on the basis of their weight (descanding order). Use the array of the following structure to have the records of students struct student { int rollno; float height,weight; char name[50]; };

#include<stdio.h>

struct student
{
    int rollno;
    char name[50];
    float height,weight;

};

main()
{
    struct student s[100],temp;
    int n,i,j;
    printf("\nEnter number of students=");
    scanf("%d",&n);
    printf("\nEnter details of the students\n");
    for(i=0;i<n;i++)
    {
        printf("\nEnter roll number of student %d=",i+1);
        scanf("%d",&s[i].rollno);
        printf("\nEnter name of student %d=",i+1);
        scanf("%s",s[i].name);
        printf("\nEnter height of student %d=",i+1);
        scanf("%f",&s[i].height);
        printf("\nEnter weight of student %d=",i+1);
        scanf("%f",&s[i].weight);
    }

    printf("\n\nDetails of the students before sorting\n");
    printf("\n\nRoll number\tName\t\tHeight\t\tWeight\n\n");
    for(i=0;i<n;i++)
    {
        printf("\n%-10d%-20s%10.2f%10.2f\n",s[i].rollno,s[i].name,s[i].height,s[i].weight);
    }

    for(i=0;i<n-1;i++)
    {
        for(j=i+1;j<n;j++)
        {
            if(s[i].height<s[j].height)
            {
                temp=s[i];
                s[i]=s[j];
                s[j]=temp;
            }
            else
            {
                if(s[i].height==s[j].height)
                {
                    if(s[i].weight<s[j].weight)
                    {
                        temp=s[i];
                        s[i]=s[j];
                        s[j]=temp;
                    }
                }
            }
        }
    }
    printf("\n\nDetails of the students after sorting\n");
    printf("\n\nRoll number\tName\t\tHeight\t\tWeight\n\n");
    for(i=0;i<n;i++)
    {
        printf("\n%-10d%-20s%10.2f%10.2f\n",s[i].rollno,s[i].name,s[i].height,s[i].weight);
    }
}

Wednesday, 9 April 2014

Write a C program to add two matrices.

#include<stdio.h>
main()
{
     int a[100][100],b[100][100],sum[100][100],r1,c1,r2,c2,i,j;
     printf("\nEnter row number of the 1st matrix=");
     scanf("%d",&r1);
     printf("\nEnter column number of the 1st matrix=");
     scanf("%d",&c1);
     printf("\nEnter the 1st matrix elements=");
     for(i=0;i<r1;i++)
     {
          for(j=0;j<c1;j++)
          {
              scanf("%d",&a[i][j]);
          }
     }
     printf("\nThe 1st matrix is\n");
     for(i=0;i<r1;i++)
     {
          for(j=0;j<c1;j++)
          {
              printf("%6d",a[i][j]);
          }
          printf("\n");
     }

     printf("\nEnter row number of the 2nd matrix=");
     scanf("%d",&r2);
     printf("\nEnter column number of the 2nd matrix=");
     scanf("%d",&c2);
     printf("\nEnter the 2nd matrix elements=");
     for(i=0;i<r2;i++)
     {
          for(j=0;j<c2;j++)
          {
              scanf("%d",&b[i][j]);
          }
     }

     printf("\nThe 2nd matrix is\n");
     for(i=0;i<r2;i++)
     {
          for(j=0;j<c2;j++)
          {
              printf("%6d",b[i][j]);
          }
          printf("\n");
     }
     if(r1!=r2 ||c1!=c2)
          printf("\nMatrix addition is not possible\n");
     else
     {
          for(i=0;i<r1;i++)
          {
              for(j=0;j<c1;j++)
              {
                  sum[i][j]=a[i][j]+b[i][j];
              }
          }
          printf("\nThe sum matrix is\n");
          for(i=0;i<r1;i++)
          {
              for(j=0;j<c1;j++)
              {
                  printf("%6d",sum[i][j]);
              }
              printf("\n");
          }
     }
}

Write a C program to calculate the transpose of a matrix.

#include<stdio.h>
main()
{
     int a[100][100],t[100][100],r,c,i,j,sum=0;
     printf("\nEnter row number of the matrix=");
     scanf("%d",&r);
     printf("\nEnter column number of the matrix=");
     scanf("%d",&c);
     printf("\nEnter the matrix elements=");
     for(i=0;i<r;i++)
     {
          for(j=0;j<c;j++)
          {
              scanf("%d",&a[i][j]);
          }
     }
     printf("\nThe matrix is\n");
     for(i=0;i<r;i++)
     {
          for(j=0;j<c;j++)
          {
              printf("%6d",a[i][j]);
          }
          printf("\n");
     }

     for(i=0;i<c;i++)
     {
          for(j=0;j<r;j++)
          {
              t[i][j]=a[j][i];
          }
     }
     printf("\nThe transpose matrix is\n");
     for(i=0;i<c;i++)
     {
          for(j=0;j<r;j++)
          {
              printf("%6d",t[i][j]);
          }
          printf("\n");
     }
}

Write a C program to check whether a number is armstrong or not.

#include<stdio.h>

main()
{
      int num,temp,flag=0,sum=0;
      printf("\nEnter a number=");
      scanf("%d",&num);
      temp=num;
      while(num)
      {
          r=num%10;
          sum=sum+r*r*r;
          num=num/10;
      }
      if(sum==temp)
          printf("\n%d is an armstrong number",temp);
      else
          printf("\n%d is not an armstrong number",temp);
}

Write a C Program to convert temperature from Fahrenheit to degree centigrade. c=(f-32)*5/9

#include<stdio.h>
main()
{
     float f,c;
     printf("\nEnter Fahrenheit value=");
     scanf("%f",&f);
     c=(f-32)*5/9;
     printf("\n%.2f f= %.2f c",f,c);
}

Write a C program to find greater of two number.

#include<stdio.h>
main()
{
     int a,b;
     printf("\nEnter two numbers=");
     scanf("%d%d",&a.&b);
     if(a>b)
          printf("\n%d is greater",a);
     else
          printf("\n%d is greater",b);
}

Tuesday, 8 April 2014

A4-R3: COMPUTER ORGANIZATION (Doeacc)

January, 2007


Q. The minimum time delay between the initiations of two independent memory operations is called
a) Cycle time
b) Access time
c) Latency time
d) None of the above

Monday, 7 April 2014

Write a C program to display all prime numbers less than the number entered by the user.(Using function)

#include<stdio.h>

int isprime(int n)
{
      int i,j;
      for(i=2;i<=n/2;i++)
      {
          if(n%i==0)
              return 0;
      }
      return 1;
}

main()
{
      int num,i;
      printf("\nEnter a number=");
      scanf("%d",&num);
      printf("\nPrime numbers less than %d are=",num);
      for(i=2;i<=num;i++)
      {
          if(isprime(i)==1)
          {
              printf("%d ",i);
          }
      }
}

Write a C function to generate the following figure for n = 4. 1 1 3 1 3 5 1 3 5 7 The value of n is passed to the function as an argument.

#include<stdio.h>

void design(int n)
{
     int i,j;
     for(i=1;i<=n;i++)
     {
        for(j=1;j<=i;j++)
        {
           printf("%d ",2*j-1);
        }
        printf("\n");
     }
}

main()
{
     design(4);
}

Write a C function print_upper() to prints its character argument in uppercase.(Using function).

#include<stdio.h>
void print_upper(char *s)
{
     int i=0;
     while(s[i]!='\0')
     {
        if(s[i]>=97 && s[i]<=123)
           s[i]=s[i]-32;
        i++;
     }
}

main()
{
     char str[100];
     printf("\nEnter a string=");
     scanf("%s",str);
     printf("\nThe original string=%s",str);
     print_upper(str);
     printf("\nThe after conversion string=%s",str);
}

Write a C program to absolute value of a number given by the user.

#include<stdio.h>
main()
{
     int a,abs;
     printf("\nEnter a number=");
     scanf("%d",&a);
     if(a<0)
          abs=a*(-1);
     else
          abs=a;
     printf("\nThe absolute value of %d is %d",a,abs);
}

Write a program to find: i. Addition of two numbers. ii. Subtraction of two numbers. iii. Multiplication of two numbers. iv. Division of two numbers.

#include<stdio.h>
main()
{
     int a,b,add,sub,mul,div;
     printf("\nEnter two numbers=");
     scanf("%d%d",&a,&b);
     add=a+b;
     printf("\nThe addition of %d and %d is %d",a,b,add);
     sub=a-b;
     printf("\nThe difference of %d and %d is %d",a,b,sub);
     mul=a*b;
     printf("\nThe product of %d and %d is %d",a,b,mul);
     div=a/b;
     printf("\nThe division of %d and %d is %d",a,b,div);
}

Program of arithmatic operator

#include<stdio.h>
main()
{
     int a,b,sum,dif,mul,div;
     printf("\nEnter two numbers=");
     scanf("%d%d",&a,&b);
     sum=a+b;
     printf("\nThe sum of %d and %d is %d",a,b,sum);
     dif=a-b;
     printf("\nThe difference of %d and %d is %d",a,b,dif);
     mul=a*b;
     printf("\nThe product of %d and %d is %d",a,b,mul);
     div=a/b;
     printf("\nThe division of %d and %d is %d",a,b,div);
}

Wednesday, 2 April 2014

Write a program to reverse an array.

#include<stdio.h>
main()
{
     int a[100],n,i,temp;
     printf("\nEnter number of terms=");
     scanf("%d",&n);
     printf("\nEnter the numbers=");
     for(i=0;i<n;i++)
     {
          scanf("%d",&a[i]);
     }
     printf("\nThe original array is\n");
     for(i=0;i<n;i++)
     {
          printf("%d ",a[i]);
     }
     for(i=0;i<n/2;i++)
     {
          temp=a[i];
          a[i]=a[n-i-1];
          a[n-i-1]=temp;
     }
     printf("\nThe reverse array is\n");
     for(i=0;i<n;i++)
     {
          printf("%d ",a[i]);
     }
}