c question and answer

Upload: mkumbhcar

Post on 05-Apr-2018

218 views

Category:

Documents


0 download

TRANSCRIPT

  • 7/31/2019 C Question and Answer

    1/4

    *Q.1 (b) Write a C program using pointers to read in an array of integers and print its elements in

    reverse order.[June-2005, Set-2, Unit-3, Q.No.-5]

    Ans. :

    Program to read integers into an array and reversing them using pointers.*/#include

    #include

    #define MAX 30void main()

    {int size,i,arr[MAX];int *ptr;

    clrscr();

    ptr=&arr[0];

    printf("Enter the size of array: ");scanf("%d",&size);

    printf("\nEnter %d integers into array:\n",size);

    for(i=0;i=0;i--)

    {

    printf("\nElement%d is %d :",i,*ptr);

    ptr--;}

    getch();

    }

    *Q.1 (b) An electric power distributioncompany charges its domestic consumers as follows:

    Consumption Units Rate of Charge

    0-200 Rs.0.50 per unit201-400 Rs.100 plus Rs.0.65 per unit excess 200

  • 7/31/2019 C Question and Answer

    2/4

    401-600 Rs.230 plus Rs.0.80 per unit excess of 400.Write a C program that reads the customer number and power consumed and prints the amount

    to be paid by the customer. [Nov./Dec.-2005,Set-3, Unit-1, Q.No.-34]

    Ans. : */#include

    #include

    void main(){

    int n, p;

    float amount;

    clrscr();printf("Enter the customer number: ");

    scanf("%d",&n);

    printf("Enter the power consumed: ");scanf("%d",&p);

    if(p>=0 && p200 && p400 && p

  • 7/31/2019 C Question and Answer

    3/4

    #include#include

    void main()

    {int a[10];

    int i,sum=0;

    int *p;printf("Enter 10 elements:\n");

    for(i=0;i

  • 7/31/2019 C Question and Answer

    4/4

    scanf("%f",&set.st.percentage);clrscr();

    printf("The student details are:\n");

    printf("Name : %s", set.st.name);printf("\nRollno : %d", set.st.rollno);

    printf("\nSex : %c", set.st.sex);

    printf("\nPercentage : %f", set.st.percentage);getch();

    }