105 prob sols - c

Upload: nikhil-prakash

Post on 02-Jun-2018

221 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/10/2019 105 Prob Sols - C

    1/72

    PROGRAMS

    1. Write a program to find factorial of a number

    Br:

    1) If number is negative store -1 into the output1 variable

    2) If number is greater than 7 store -2 into the output1 variable

    #include

    #includevoid main()

    {

    int n,i,fact=1,op;

    clrscr();

    printf("\nEnter Number:");

    scanf("%d",&n);

    if(n7)

    {

    op=-2;

    }

    else

    {

    for(i=1;i

  • 8/10/2019 105 Prob Sols - C

    2/72

    op=-2;

    else

    {

    if(count==1)

    op=1;

    if(count==2)

    op=0;

    if(count==3){

    while(n!=0)

    {

    a=n%10;

    sum=sum+(a*a*a);

    n=n/10;

    }

    op=1;

    }

    }

    }

    printf("%d",op);

    getch();

    }

    3. Write a program to find number of digits in a given number(ex: for 345 no of digits is 3)

    1) if number is negative store -1 into the output1 variable

    #include

    #include

    void main()

    {

    int n,a=0,op;

    clrscr();

    printf("\nEnter n:");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    3/72

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    4/72

    output1=-2;

    printf("The Ans is:%d",output1);

    }

    else if(a[i]

  • 8/10/2019 105 Prob Sols - C

    5/72

    }

    6. Given two arrays, compare two arrays and store the greater element of the arrays into output array.

    Br:

    1) If any of the element in an array is negative store -1 into first element of the output array

    2) If the size of an array is negative then store -2 into the first element of the output array

    #include

    #include

    void main()

    {

    int c[80],n ,a[30],b[30],i,j,k,temp,output1;

    clrscr();

    printf("ENTER THE ARRAY SIZE");

    scanf("%d",&n);

    printf("ENTER THE ARRAY ELEMENTS A:");

    for(i=1;i

  • 8/10/2019 105 Prob Sols - C

    6/72

  • 8/10/2019 105 Prob Sols - C

    7/72

    {

    output1=-1;

    printf("The number is -ve=%d",output1);

    }

    else if(n>32767)

    {

    output1=-2;printf("The number great than =%d",output1);

    }

    else if(n>0&&n0)

    {

    a=n%10;

    n=n/10;

    if(a%2==0)

    sum=sum+a;

    }

    printf("the sum is %d",sum);

    }

    getch();

    }

    9. Write a program to search an element in an array and if it is found store the location into

    Output variable

    Br:

    1) if it is not found store 1 into the output variable

    2) if any element in an input array is negative store -1 into output variable

    3) if the size of an array is negative store -2 into the output variable

    #include

    #include

    void main()

    {

    int a[20],search,n,flag,i,op;clrscr();

    printf("\nEnter n:");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    8/72

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    9/72

    {

    if(i!=0)

    k++;

    max=count;

    op[k]=a[i];

    //k++;

    }

    else{}

    }

    }

    }

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    10/72

    }

    printf("\n\nOutput: %d",op);

    getch();

    }

    12. Find the product of the digits of the given no and if product is divisible by 3 or 5 store 1 to the

    output variable

    Input1=56Output=1

    Input2 is the array size.

    BR

    1.If the given input is negative store -1 to the output

    2.If the given no itself is divided by 3 or 5 store -2 to the output

    #include

    #include

    void main()

    {

    int num,n,op,a,i,sum=1;

    clrscr();

    printf("\nEnter n:");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    11/72

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    12/72

    3.Store -3 to the first position of the output array if the given array size is even

    #include

    #include

    int main()

    {

    int input1[40],output[40],input;

    int i,j,k,count=0,temp;clrscr();

    printf("Enter the size::\n");

    scanf("%d",&input);

    if(input

  • 8/10/2019 105 Prob Sols - C

    13/72

    Input3=4;

    OUTPUT[]={26,24,45,7}

    BR

    1.Store -1 to the first position of the output array if any input array elements contains negative

    value

    2.Store -2 to the first position of the output array if array size is negative

    #include#include

    int main()

    {

    int input1[40],input2[40],output[40],input;

    int i,j,k,count=0;

    clrscr();

    printf("Enter the size::\n");

    scanf("%d",&input);

    if(input

  • 8/10/2019 105 Prob Sols - C

    14/72

    value

    2.Store -2 to the first position of the output array if array size is negative

    #include

    #include

    int main()

    {

    int input1[25],input2,output[25],i,j,k,count=0;

    clrscr();printf("enter limit::\n");

    scanf("%d",&input2);

    if(input2

  • 8/10/2019 105 Prob Sols - C

    15/72

    void main()

    {

    int fahren;

    clrscr();

    printf("enter the temperature in fahrenheit:");

    scanf("%d",&fahren);

    temp(fahren);

    printf("output=%d",out);getch();

    }

    void temp(int fahren)

    {

    if(fahren

  • 8/10/2019 105 Prob Sols - C

    16/72

    1) if the limit(n) is negative, store -1 to output

    2) if the n value is greater than 7, store -1 to output

    #include

    #include

    void primesum(int inut);

    int out;

    void main()

    {int input;

    clrscr();

    printf("enter the range");

    scanf("%d",&input);

    primesum(input);

    printf("output=%d",out);

    getch();

    }

    void primesum(int input)

    {

    int sum=8,i,flag,j;

    if(input7)

    out=-1;

    else

    {

    for(i=3;i

  • 8/10/2019 105 Prob Sols - C

    17/72

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    18/72

    if(input1[i]

  • 8/10/2019 105 Prob Sols - C

    19/72

    {

    printf("%d\t",output[i]);

    }

    getch();

    }

    void delnegandsort(int input1[],int input)

    {

    int j,temp;

    if(input

  • 8/10/2019 105 Prob Sols - C

    20/72

    void main()

    {

    int input;

    clrscr();

    printf("Enter an number:");

    k=(int)if(scanf("%d",&input));

    sumofcubes(input,k);

    printf("Sum of cubes of prime numbers:\n\tout=%ld",out);getch();

    }

    void sumofcubes(int input,int k)

    {

    int i,j,flag,count=0;

    long int sum=1;

    if(k!=1)

    {

    out=-2;

    }

    else if(input

  • 8/10/2019 105 Prob Sols - C

    21/72

    scanf("%d",&input1[i]);

    sumofmul5(input1,input);

    printf("\noutput:");

    printf("%.1f\t",out);

    getch();

    }

    void sumofmul5(int input1[],int input)

    {int count=0,sum=0,temp;

    if(input

  • 8/10/2019 105 Prob Sols - C

    22/72

    Business Rule:1.if the element is found, store 1 into the output variable,

    2.if the array contanis -ve elements store 1- into the output variable,

    3.if the array size is -ve, store -2 into the array,

    4.if the element not found, store -3 into the array,

    #include

    #include

    void main()

    {int a[20],n,i,s,output;

    clrscr();

    printf("enter the limit:");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    23/72

    int j,i,output;

    long int n,sum=0;

    clrscr();

    printf("enter the numbers:");

    scanf("%ld",&n);

    if(n32767)

    {

    output=-2;

    printf("output=%d",output);

    }

    else

    {

    for(j=1;j

  • 8/10/2019 105 Prob Sols - C

    24/72

    count++;

    }

    }

    avg=s/count;

    printf("output=%f",avg);

    }

    getch();}

    32. sum of squres of odd digits in a number.

    Business Rule:if input1< 0, store -1 into the output variable

    #include

    #include

    void main()

    {

    long int n,t,r=0,q,s=0,count=1,output;

    clrscr();

    printf("enter the value:");

    scanf("%ld",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    25/72

    #include

    void main()

    {

    int input1[25],input2,output1[25],i,j,temp;

    clrscr();

    printf("enter the range");

    scanf("%d",&input2);

    if(input2

  • 8/10/2019 105 Prob Sols - C

    26/72

    printf("enter limit");

    scanf("%d",&input1);

    if(input1500){

    output1=-2;

    printf("%d",output1);

    }

    else

    {

    for(i=1;i

  • 8/10/2019 105 Prob Sols - C

    27/72

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    28/72

    Business Rules:

    i) If the given input is not a binary value store -1 to the output variable.

    ii) If the given input is greater than 11111 store -2 to the output variable.

    #include

    #include

    void main()

    {

    long int input1,output1=0,base=1,rem,count=0,n,d,k=0;clrscr();

    printf("enter number");

    scanf("%ld",&input1);

    if(input1>11111)

    {

    output1=-2;

    printf("%ld",output1);

    }

    else

    {

    n=input1;

    while(n!=0)

    {

    d=n%10;

    k++;

    if((d==0)||(d==1))

    count++;

    n=n/10;

    }

    if(k==count)

    {

    while(input1>0)

    {

    rem=input1%10;

    output1=output1+rem*base;

    input1=input1/10;

    base=base*2;

    }

    printf("output1=%ld",output1);}

    else

    {

    output1=-1;

    printf("output1=%ld",output1);

    }

    }

    getch();

    }

    37. Calculate the sum of squares of prime numbers up to N natural number. Consider input1 is the N

    value. (Consider 1 is not a prime.)

    Eg:

    Input1=10

    Output1=87

    Business Rules:

    i) If the given input is negative store -1 to the output variable.

    ii) If the given input is greater than 500 store -2 to the output variable.

    #include

    #include

    void main()

    {

  • 8/10/2019 105 Prob Sols - C

    29/72

    int c,f;

    clrscr();

    printf("temperature=");

    scanf("%d",&c);

    if(c

  • 8/10/2019 105 Prob Sols - C

    30/72

    {

    sum=sum+i*i;

    }

    }

    printf("sum is %d",sum);

    }

    getch();

    }

    39. Convert celcius to farenheit

    Business rule: if the input temperature is negative then store -1 to output1

    #include

    #include

    void main()

    {

    int input1[10],input2,i,sum=0,output;

    clrscr();

    printf("\n input2=");

    scanf("%d",&input2);

    if(input2

  • 8/10/2019 105 Prob Sols - C

    31/72

    Input1[]={1.2.3.4}

    Input2[]={4,3,2,1}

    Output1={2,4,6,8}

    Business Rule1: If the size of input array is negative ,then store -2 to output array

    Business Rule2: If any of element in input array is negative then store -1 to output array

    #include

    #include

    void main(){

    int input1[10],input2[10],c[10],i,j,n,sum=0,output;

    clrscr();

    printf("\n size");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    32/72

    input1[]={2,-3,4,5,-9}

    output1=11

    Business Rule1: If the size of input array is negative ,then store -2 to output array

    Business Rule2: If any element in input array is negative ,then store -1 to output array

    #include

    #include

    void main(){

    int a[10],n,i,j,sum=0,op;

    clrscr();

    printf("\n enter the limit of the arrays");

    scanf("%d",&n);

    if(n0)

    {

    printf("\n enter the array elements");

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    33/72

    else if(n>0)

    {

    printf("\n enter the array elements");

    for(i=0;i=11111)

    {

  • 8/10/2019 105 Prob Sols - C

    34/72

    op=-2;

    printf("\n %ld",op);

    }

    else if(b

  • 8/10/2019 105 Prob Sols - C

    35/72

    k++;

    }

    }

    if(k==2)

    sum=sum+(i*i*i);

    }}

    printf("the sum of cube is %ld",sum);

    getch();}

    46. Program to calculate sum of squares of multiples of 5 and find out the average up to n number.

    if

    Input1

  • 8/10/2019 105 Prob Sols - C

    36/72

    for(i=0;i=0)

    k++;

    if(a[i]%3==0)

    b++;

    }if(k==n)

    {

    out=b;

    }

    else

    out=-1;

    }

    printf("the out is %d",out);

    getch();

    }

    48. Program to find out the sum of odds from a digit.

    Input1 < 0 output1=-1

    Input1 >32767 output1=-2

    #include

    #include

    void main()

    {

    long int count=0, b, n,rev=0,d;

    clrscr();

    printf("enter the number");

    scanf("%ld",&n);

    if(n32767)

    count=-2;

    else

    while(n!=0){d=n%10;

    if(d%2!=0)

    count=count+d;

    n=n/10;

    }

    printf("the odd count in digit is %ld",count );

    getch();

    }

    49. Program to find the repetitions of the particular element in an array for a given element.

    Input1[]

  • 8/10/2019 105 Prob Sols - C

    37/72

    printf("\nBR2 : Output is %d",output); // Array size is negative

    }

    else if(n>0)

    {

    printf("\nEnter the elements of array : ");

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    38/72

    #include

    #include

    void main()

    {

    float salary,output1,days,savings,foodexp,travelexp,daysal,earnsal;

    int flag=0,dayflag=0;

    clrscr();printf("\nEnter the Monthly salary : ");

    scanf("%f",&salary);

    if(salary=0 && salary

  • 8/10/2019 105 Prob Sols - C

    39/72

    {

    printf("\nOutput is Rs. %0.2f",output1);

    }

    getch();

    }

    51. wap to calculate the square of sum of even digits in a given number.(Ex:1234 output=20)

    br:store -1 to output variable if input value is negative.#include

    #include

    void main()

    {

    int num,output,rev=0,rem,sum=0,count=0;

    clrscr();

    printf("\nEnter the Number : ");

    scanf("%d",&num);

    if(num0)

    {

    while(num!=0) // Reversing the number

    {

    rev=(rev*10)+(num%10);

    num=num/10;

    }

    while(rev!=0) // Calculating sum of Squares

    {

    rem=rev%10;

    count++;

    rev=rev/10;

    if(count%2==0) // Even digits

    {

    sum=sum+(rem*rem);output=sum;

    }

    }

    }

    printf("\nOutput is %d",output);

    getch();

    }

    52. wap to find if input number is perfect number or not.

    br:store 1 to output1 if it is perfect number

    store -1 to output1 if it is not a perfect number

    store -2 to output1 if entered number is negative number

    #include

    #include

    void main()

    {

    int i,num,output1,n,sum=0;

    clrscr();

    printf("\nEnter the number : ");

    scanf("%d",&n);

    num=n;

    if(num

  • 8/10/2019 105 Prob Sols - C

    40/72

    output1=-2; // BR3

    }

    else if(num>0)

    {

    for(i=1;ib)

    output1=a;

    else

    output1=b;

    if(c>output1)

    output1=c;

    }

    printf("Output is %ld",output1);

    getch();

    }

    54. wap to calculate the sum of multiples upto given number.

    Ex: 3 upto 15(3+6+9+12+15=45)

    #include

    #include

    void main()

    {

    int n ,sum=0,i;

    clrscr();

    printf("enter the limit:");

    scanf("%d",&n);

  • 8/10/2019 105 Prob Sols - C

    41/72

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    42/72

    }

    if(flag==1)

    op[0]=-1;

    else

    {

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    43/72

    {

    output=0;

    }

    }

    printf("\n%d",output);

    getch();

    }

    58. find the product of prime numbers in a given array

    B.R1: if input

  • 8/10/2019 105 Prob Sols - C

    44/72

    }

    59. find the second largest number in a given array

    B.R1:if any element is negative in the array store -1 in the output

    B.R2:if the size of the array is less than 0 store -2 in the output

    #include

    #include

    void main()

    {int n,a[100],temp,i,j,output;

    clrscr();

    printf("Enter the size of the array:");

    scanf("%d",&n);

    if(n0)

    {

    printf("\nEnter the elements of the array:");

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    45/72

    if(n0)

    {

    printf("\nEnter the elements in the array:");for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    46/72

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    47/72

    //if((input1>0) && (input2>0))

    {

    switch(n)

    {

    case 1: input3=input1+input2;

    printf("\n %d",input3);

    break;

    case 2: input3=input1-input2;

    // input3=2;

    printf("\n %d",input3);

    break;

    case 3: input3=input1*input2;

    // input3=3;

    printf("%d\n",input3);

    break;

    case 4: input3=input1/input2;

    //nput3=4;

    printf("%d\n",input3);

    break;

    }

    }

    getch();

    }

    63. List the prime numbers in the given array and store in the output array

    Business Rule(Store -1 to output array if array contains any negative elements, Store -2 in the output

    array if the input size is negative and Store -3 in the output array if there are no prime numbers in the

    given input array)

    #include#include

    void main()

    {

    int n,i,j,a[100],f,c;

    clrscr();

    printf("\nenter the limit:");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    48/72

    if(f==0)

    {

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    49/72

    else if(amt>0)

    {

    printf("\n Notes of 500 required:%d",amt/500);

    printf("\n Notes of 100 required:%d",(amt%500)/100);

    printf("\n Notes of 50 required:%d",((amt%500)%100)/50);

    printf("\n Notes of 10 required:%d",(((amt%500)%100)%50)/10);

    printf("\n Coins of 1 required:%d",((((amt%500)%100)%50)%10)/1);

    }getch();

    }

    66. Calculate the gross salary of the employee given da and hra is 75% and 50% of basic salary

    (Business rule: Store -1 in the output variable if basic pay10000 and -3 in the output variable if number of working days>31)

    // 67. Find the sum of factors from a given number upto N like input1:3,input2:15

    output1=3+6+9+12+15=45)

    (Business rule:Store -1 in output variable if input1 is negative and -2 in output variable if input2 is

    >32627) 68. Generate perfect numbers upto N natural numbers (Business rule: store -1 in output variable if N 23627)

    #include

    #include

    void main()

    {

    int n,i,sum=0;

    clrscr();

    printf("\n Enter the number:");

    scanf("\n %d",&n);

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    50/72

    {

    for(i=min;i

  • 8/10/2019 105 Prob Sols - C

    51/72

    {

    if(output[i]

  • 8/10/2019 105 Prob Sols - C

    52/72

    Input2:6

    Input3:4

    Output1:3

    If any one of the element in input array is negative ,store-1,

    If input2 is negative,store -2.

    If input3 is negative,store -3.

    #include#include

    void main()

    {

    int input[10],output=0,temp=0,i,j,n,ele;

    printf("enter the size of array\n");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    53/72

    If he works for 31 days add 500 to the salary of the employee.

    Example1:

    Input1=5000

    Input2=30

    Output1=11250

    Example2:Input1=5000

    Input2=31

    Output1=11750

    If input1>10000,store -1.

    If input2>31,store -2.

    If input1 is negative,store -3.

    If input2 is negative,store -4.

    74. decimal to binary.

    Hint: Output is an array

    If input1 is negative,store -1

    75. Find the largest of three numbers.

    If any number is negative store -1 to output

    If the number is greater than 32767 store -2 to output

    76. a person owns some plots plot numbers are even and odd numbers, he want to keep average of

    sum of odd numbers and sum of even numbers as his password,,.. What is his password Input is an array and output is an integer

    Business rule if any number in array is negative store -1 in output1 Business rule if array size is negative store -2 in output1 77. a

    ship story.. inputs are two arrays output is an array We have to add the FIRST ELEMENT OF ONE ARRAY WITH LAST ELEMENT OF

    ANOTHER ARRAY SECOND ELEMENT OF ONE ARRAY WITH SECOND LAST ELEMENT OF ANOTHER ARRAY

    Business rule if any number in array i s negative store -1 in output1...

    78. salary story

    Inputs are salary and number of working days

    and output is an integer

    Calculate the amount saved by a person if his

    Salary of person is 7000 for 30 days500 extra if he works for 31 daysFood expenditure is 50% of salary

    Travel expenditure is 20% of salary

    Business rule:

    If input1 >9000 then store -1if input1 is negative then store -3If input2 is negative then store -4

    79. leap year

    Store -1 in output 1 if input number is negative

    80. product of prime

    Store -1 in output 1 if input number is negative

    81. second highst element in an array

    Business rule if any number in array is negative store -1 in output1

  • 8/10/2019 105 Prob Sols - C

    54/72

    Business rule if array size is negative store -2 in output1

    #include

    #include

    void main()

    {

    int a[100],i,j,n,count=0,temp;

    printf("Enter the number");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    55/72

    for(j=i+1;j3 output=-2,if no. is not Armstrong

    output=-3,if Armstrong output=1)

    83. second highest no. in an array

    (if array has any negative no. output=-1,if size of array isve output=-2)

    84. print largest repeated element in array(if array has any negative no. output=-1,if size of array isve

    output=-2)

    85. count no. of digits in number(if no. isve output=-1)

    #include

    #include

    void main()

    {

    int a,count=0;

    clrscr();

    printf("enter the number");

    scanf("%d",&a);

    if(a99 output=-1,if 70

  • 8/10/2019 105 Prob Sols - C

    56/72

    int out,n,a[10],i,sum=0;

    float avg;

    clrscr();

    printf("enter the number");

    scanf("%d",&n);

    printf("enter the marks");

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    57/72

    }

    }

    }

    printf(" 0 = %d",sum);

    getch();

    }

    88. write a Program to calculate temperature from celcius to Fahrenheitc/5=f/9-32

    Business Rules:

    a)If given input is negative store -1 to the output variable

    #include

    void main()

    {

    float f,c;

    clrscr();

    printf("enter celsius");

    scanf("%f",&c);

    if(c

  • 8/10/2019 105 Prob Sols - C

    58/72

    output=-2;

    printf("%d",output);

    }

    }

    getch();

    }

    90. write a program to find products of digits which are divisible by 3 or 5

    If it divisible then store 1 to the output variablea)if given input is divisible by 3 or 5 then store -1 to output variable

    b)if given input is negative store -2 to output variable

    Input=56Output=1

    #include

    #include

    void main()

    {

    int input,output,pdt=1,d;

    clrscr();

    printf("enter number");

    scanf("%d",&input);

    if(input

  • 8/10/2019 105 Prob Sols - C

    59/72

    printf("enter range");

    scanf("%d",&input2);

    if(input2

  • 8/10/2019 105 Prob Sols - C

    60/72

    {

    printf("enter elements");

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    61/72

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    62/72

    94. Second largest in a given array.[if array has -ev elements store -1 , if array size is -ve store -2]#include

    #include

    void main()

    {

    int n,i,j,t,a[10];

    clrscr();

    printf("Enter the number");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    63/72

    printf("%d",output);

    goto l;

    }

    printf("Enter the values");

    for(i=0;i

  • 8/10/2019 105 Prob Sols - C

    64/72

    }

    else if(bs31)

    {

    c=-2;

    printf("\n %d",c);

    }

    else if(d99 store -3]

    #include

    #include

    void main()

    {

    int av,a[10],n,i,sum=0,j,bs,c,d;

    float avg;

    clrscr();

    printf("enter the no of subjects");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    65/72

    av=-3;

    printf("%d",av);

    }

    else

    printf("the average is %f",avg);

    }l:

    getch();

    }

    98. Sort the array (half ascending and descending based on odd or even no elements) [if input arrayhas -ve elements store -1, size of array -ve store -2]

    #include

    #include

    void main()

    {

    int s[20], a[20],i,j,n,b[20],c[20],t,d[20],e[20],k;

    clrscr();

    printf("enter the limit");scanf("%d",&n);

    printf("enter the element");

    for(i=1;i

  • 8/10/2019 105 Prob Sols - C

    66/72

    }

    for(i=(n/2)+1;i

  • 8/10/2019 105 Prob Sols - C

    67/72

    99. Sum of digits of a given number. Input1=given number, if the

    given no is negative store output1=-1,if given no is >32767

    #include

    #include

    void main()

    {

    long int a,count=0;clrscr();

    printf("enter any no");

    scanf("%ld",&a);

    if((a32767))

    {

    count=-1;

    printf("%d",count);

    goto l;

    }

    while(a!=0)

    {

    a=a/10;

    count=count+1;

    }

    printf("no of digit in a no %d",count);

    l:

    getch();

    }

    99. Sum of digits of a given number. Input1=given number, if thegiven no is negative store output1=-1,if given no is >32767

    #include

    #includevoid main()

    {long int a,count=0;clrscr();

    printf("enter any no");scanf("%ld",&a);

    if((a32767)){count=-1;

    printf("%d",count);

    goto l;}while(a!=0)

    {

    a=a/10;count=count+1;

    }printf("no of digit in a no %d",count);l:

    getch();

    }

    100. Sum of digits of a given number. Input1=given number, if the given no is negative storeoutput1=-1,if given no is >32767101. Sum of even numbers up to n numbers if the given no is negative store output1=-1,if given no is

    >32767

    #include

    #include

  • 8/10/2019 105 Prob Sols - C

    68/72

    void main()

    {

    int n,i,out=0;

    clrscr();

    printf("\n enter the no");

    scanf("%d",&n);

    if(n3276)

    {

    out=-1;

    }

    else

    {

    for(i=1;i

  • 8/10/2019 105 Prob Sols - C

    69/72

    {

    int n,i,j,out=0;

    printf("\n enter the range");

    scanf("%d",&n);

    if(n

  • 8/10/2019 105 Prob Sols - C

    70/72

    if(n

  • 8/10/2019 105 Prob Sols - C

    71/72

    if(n

  • 8/10/2019 105 Prob Sols - C

    72/72

    }

    else

    j++;

    }

    }

    for(i=0;i10000,store output1=-1.