You are on page 1of 72

1.

1) 2)

PROGRAMS Write a program to find factorial of a number Br: If number is negative store -1 into the output1 variable If number is greater than 7 store -2 into the output1 variable

#include<stdio.h> #include<conio.h> void main() { int n,i,fact=1,op; clrscr(); printf("\nEnter Number:"); scanf("%d",&n); if(n<0) { op=-1; } else if(n>7) { op=-2; } else { for(i=1;i<=n;i++) fact=i*fact; // printf("Factorial of %d is %d",n,fact); op=fact; } printf("\nOutput is %d",op); getch(); } 2. Write a program to check for Armstrong number 1) If number is negative store -1 into the output1 variable 2) If number is greater than 3 digit store -2 into the output1 variable 3) If it is Armstrong number store 1 into the output1 variable 4) If it is not store store 0 into the output1 variable #include<stdio.h> #include<conio.h> void main() { int n,sum=0,num,op,count=0,a; clrscr(); printf("\nEnter number:"); scanf("%d",&num); n=num; if(num<0) { op=-1; } else { while(n!=0) { n=n/10; count++; } n=num; if(count>3)

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<stdio.h> #include<conio.h> void main() { int n,a=0,op; clrscr(); printf("\nEnter n:"); scanf("%d",&n); if(n<0) { op=-1; } else { while(n!=0) { n=n/10; a++; } op=a; } printf("\n%d",op); getch(); } 4. Write a program to find sum of even numbers and odd numbers in an array and avg them (ex: ar{1,2,3,4,5,6} output1=(12+9)/2 1) If any of the array element is negative store -1 into the output1 variable 2) If the size of an array is negative store -2 into the output1 variable #include<stdio.h> #include<conio.h> void main() { int n,a[20],i,op,flag=0,sum=0; clrscr(); printf("\nEnter n:");

scanf("%d",&n); if(n<0) op=-2; else { printf("\nEnter elements:"); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) flag=1; } if(flag==1) op=-1; else { for(i=0;i<n;i++) sum=sum+a[i]; op=sum/2; } } printf("\n%d",op); getch(); } 5. Given two input arrays, sort first array into ascending order and second array into descending order And multiply the first element of first array with last element of second array and second element of first array with second last of the second array and so on.. (ex: Input1{1,2,3,4,5} and input2={9,8,7,6,5} and output1{5,12,21,32,45} Br: 1) If any element of input arrays is negative store -1 into the first element of the output array 2) If size of an array is negative store -2 into the first element of the output array

#include<stdio.h> #include<conio.h> void main() { int t,i,j,a[10],b[10],n,output1,c[20]; clrscr(); printf("ENTER THE ARRAY SIXZE"); scanf("%d",&n); for(i=0;i<n;i++) { printf("\n ENTER THE %d ELEMENT", i); scanf("%d",&a[i]); } for(i=0;i<n;i++) { printf("\n ENTER THE %d ELEMENT", i); scanf("%d",&b[i]); }

if(n<0) {

output1=-2; printf("The Ans is:%d",output1); } else if(a[i]<0 && b[i]<0) { output1=-1; printf("The Ans is:%d",output1); } else if(i>0) { for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(a[i]<a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } }

for(i=0;i<n;i++) { printf("THE SORTED FIRST ARRAY: %d\n",a[i]); } printf("\n"); for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(b[i]>b[j]) { t=b[i]; b[i]=b[j]; b[j]=t; } } } for(i=0;i<n;i++) { printf("THE SORTED SECOND ARRAY: %d\n",b[i]); }

//PRINTING THE OUTPUT printf("\n THE OUTPUT AFTER MULTIPLICATION \n"); for(i=0;i<n;i++) { c[i]= a[i] * b[n-1-i]; printf("%d \t",c[i]); } } getch();

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<stdio.h> #include<conio.h> 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<=n;i++) { scanf("%d",&a[i]); } printf("ENTER THE ARRAY ELEMENTS B:"); for(i=1;i<=n;i++) { scanf("%d",&b[i]); } if(n<0) { output1=-2; printf("The Ans is:%d",output1); } else if(a[i]<0) { output1=-1; printf("The Ans is:%d",output1); } else if (n>0&&a[i]>0) { for(i=1;i<=n;i++) { if(a[i]>b[i]) c[i]=a[i]; else c[i]=b[i]; } for(i=1;i<=n;i++) { printf("The Output Is:%d\n",c[i]); } } getch();

7. Br: 1)

Write a program to multiply the positive numbers in an array If the size of an array is negative store -2 into the output variable #include<stdio.h> #include<conio.h> void main() { int i,n,a[10],output1,temp=1; clrscr(); printf("ENTER THE ARRAY SIZE"); scanf("%d",&n); printf("ENTER THE ELEMENTS IN THE ARRAY"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } if(n<0) { output1=-2; printf("the ans is:%d",output1); } else if(n>0) { for(i=0;i<n;i++) { if(a[i]>0) temp=temp*a[i]; } printf("the output is %d\n",temp); } getch(); }

8. 1) 2)

Write a program to find the sum of the even digits in a given number Br: If number is negative store -1 into the output variable If number is greater than 32767 store -2 into the output variable

#include<stdio.h> #include<conio.h> void main() { int n,output1,a,sum=0; clrscr(); printf("ENTER A NUMBER"); scanf("%d",&n); if(n<0)

{ 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&&n<32767) { while(n>0) { a=n%10; n=n/10; if(a%2==0) sum=sum+a; } printf("the sum is %d",sum); } getch(); } 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<stdio.h> #include<conio.h> void main() { int a[20],search,n,flag,i,op; clrscr(); printf("\nEnter n:"); scanf("%d",&n); if(n<0) op=-2; else { printf("\nEnter elements:"); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) { // op=-1; flag=1; } } if(flag==1) op=-1; else { flag=0; printf("\nEnter search element:"); scanf("%d",&search); 9.

for(i=0;i<n;i++) { if(a[i]==search) { op=i+1; flag=1; // printf("%d",a[i]); break; } } if(flag==0) op=1; } } printf("\nOutput: %d",op); getch(); } 10. Given an input array, if an element in an array is repeated most no of times store that element into an output array

ex: input1{2,2,2,2,3,3,3,3,4} then output={2,3} input{2,2,2,3,3,4} then output={2} #include<stdio.h> #include<conio.h> void main() { int n,a[20],i,op[20],flag=0,j,count=0,k=0,max=0; clrscr(); printf("\nEnter n"); scanf("%d",&n); if(n<0) op[0]=-2; else { for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) flag=1; } if(flag==1) op[0]=-1; else { for(i=0;i<n;i++) { count=0; for(j=i+1;j<n;j++) { if(a[i]==a[j]) count++; } if(count>max) { max=count; op[k]=a[i]; //k++; } else if(count==max)

{ if(i!=0) k++; max=count; op[k]=a[i]; //k++; } else {} } } } for(i=0;i<=k;i++) { printf("\nElement %d : %d",i+1 ,op[i]); } getch(); }

Count the multiples of 3 store it into the output variable Input1[]={1,2,3,4,5,6} Input2=6 Output=2 Input2 is the array size BR 1.Store -1 to the output variable if input array contains any negative elements 2.Store -2 to the output variable if given input array size is negative #include<stdio.h> #include<conio.h> void main() { int a[20],i,n,op,flag,count=0; clrscr(); printf("\nEnter n:"); scanf("%d",&n); if(n<0) op=-2; else { printf("\nEnter elements:"); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) flag=1; } if(flag==1) op=-1; else { for(i=0;i<n;i++) { if((a[i]%3)==0) count++; } if(count==0) op=1; else op=count; }

11.

} printf("\n\nOutput: %d",op); getch(); } 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=56 Output=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<stdio.h> #include<conio.h> void main() { int num,n,op,a,i,sum=1; clrscr(); printf("\nEnter n:"); scanf("%d",&n); if(n<0) op=-1; else { if(((n%3)==0) || ((n%5)==0)) op=-2; else { while(n!=0) { a=n%10; sum=sum*a; n=n/10; //printf("\n%d",sum); } if(((sum%3)==0) || ((sum%5)==0)) op=1; else op=-3; } } printf("\n\nOutput: %d",op); getch(); } 13. Find the sum of prime nos in an array and store it into output variable Note :1 is not a prime no Input1[]={1,2,3,4,5} Input2=5 Output1=10 BR 1.If the given input array contain any negative no store -1 to the output1 2.if the given input array size is negative store -2 to the output1// 3.If the input array does not contain any prime nos store -3 to the output1 #include<stdio.h> #include<conio.h> int main() { int a[20],n,i,j,op[50],flag=0; clrscr(); printf("\nEnter n"); 12.

scanf("%d",&n); if(n<0) { op[0]=-2; printf("%d\n",op[0]); } else { printf("Enter the elements into the array::\n"); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) flag=1; } if(flag==1) { op[0]=-1; printf("%d\n",op[0]); } else { for(i=0;i<n;i++) { for(j=2;j<a[i];j++) { if(a[i]%j==0) { flag=0; break; } flag=1; } if(flag==1) { op[i]=a[i]; printf("%d\n",op[i]); } else { op[0]=-3; printf("%d\n",op[0]); } } } } getch(); return 0; } 14. First element of the array is replaced with last element of the array.Input2 is the array size. For example Input1[]={12,34,56,17,2} Input2=5 Output1[]={2,17,56,34,12} Take mid=input2/2; BR 1.If array contain any negative elements store -1 to the first position of the output array 2.Store -2 if the given array size is negative

3.Store -3 to the first position of the output array if the given array size is even #include<stdio.h> #include<conio.h> 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<0) { output[0]=-2; printf("%d",output[0]); } else if(input%2==0) { output[0]=-3; printf("%d",output[0]); } else { printf("Enter the element into the array:\n"); for(i=0;i<input;i++) scanf("%d",&input1[i]); for(i=0;i<input;i++) if(input1[i]<0) { count++; } if(count==0) { for(i=0;i<input/2;i++) { temp=input1[i]; input1[i]=input1[input-i-1]; input1[input-i-1]=temp; } printf("The resultant array is::\n"); for(i=0;i<input;i++) { output[i]=input1[i]; printf("%d\n",output[i]); } } else { output[0]=-1; printf("%d\n",output[0]); } } getch(); return 0; } 15. Add the first element of the array input1 with the last element of the array input2.. Input3 is size of the array Input1[]={21,23,41,4} Input2[]={3,4,1,5}

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<stdio.h> #include<conio.h> 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<0) { output[0]=-2; printf("%d",output[0]); } else { printf("Enter the element into the first array:\n"); for(i=0;i<input;i++) scanf("%d",&input1[i]); printf("Enter the element into the 2nd array:\n"); for(i=0;i<input;i++) scanf("%d",&input2[i]); for(i=0;i<input;i++) if(input1[i]<0 || input2[i]<0) { count++; } if(count==0) { for(i=0;i<input;i++) { for(k=0;k<input;k++) { output[k]=input1[i]+input2[i]; } printf("%d\t",output[i]); } } else { output[0]=-1; printf("%d\n",output[0]); } } getch(); return 0; } 16. Remove the duplicate elements store it into the output array.Input2 is size of the array Input1[]={1,2,2,3,3} Input2[]=5; Output[]={1,2,3} 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<stdio.h> #include<conio.h> int main() { int input1[25],input2,output[25],i,j,k,count=0; clrscr(); printf("enter limit::\n"); scanf("%d",&input2); if(input2<0) { output[0]=-1; printf("%d",output[0]); } else { printf("enter elements::\n"); for(i=0;i<input2;i++) scanf("%d",&input1[i]); for(i=0;i<input2;i++) if(input1[i]<0) { count++; } if(count==0) { for(i=0;i<input2;i++) { for(j=i+1;j<input2;) { if(input1[i]==input1[j]) { for(k=j;k<input2;k++) input1[k]=input1[k+1]; input2--; } else j++; } } printf("resultant array\n" ); for(i=0;i<input2;i++) printf("\t%d",input1[i]); } else { output[0]=-2; printf("%d",output[0]); } } getch(); return 0;} 17. BRFahrenheit to Celsius conversion 1) if the number is negative, store -1 to output include<stdio.h> #include<conio.h> int out; void temp(int fahren);

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<0) out=-1; else { out=(fahren-32)*5/9; } } 18. Check whether the given number is perfect or not BR1) if the number is perfect number, store 1 to output 2) If the number is not negative, store -1 to output 3) If the number is negative, store -2 to output #include<stdio.h> #include<conio.h> void perfect(int input); int out; void main() { int input; clrscr(); printf("enter the u want to check"); scanf("%d",&input); perfect(input); printf("output=%d",out); getch(); } void perfect(int input) { int sum=0,i=1; if(input<0) out=-2; else { while(i<input) { if(input%i==0) sum=sum+i; i++; } if(sum==input) out=1; else out=-1; } } 19. BRfind the sum of cube of prime numbers upto n natural numbers(case study type)

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<stdio.h> #include<conio.h> 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(input<0) { out=-1; } else if(input>7) out=-1; else { for(i=3;i<=input;i++) { flag=0; for(j=2;j<i;j++) { if(i%j==0) { flag=1; break; } } if(flag==0) { sum=sum+(i*i*i); } } out=sum; } } 20. count the number of multiples of 3 in the given array BR1) if any array element is negative, store -1 to output #include<stdio.h> #include<conio.h> void multiple(int input[],int n); int out; void main() { int input[100],i,n; clrscr(); printf("enter the size of the array:"); scanf("%d",&n); printf("enter the array elements");

for(i=0;i<n;i++) scanf("%d",&input[i]); multiple(input,n); printf("output=%d",out); getch(); } void multiple(int input[],int n) { int count=0,i,flag=0; for(i=0;i<n;i++) { if(input[i]<0) flag=1; else { if(input[i]%3==0) count++; } } if(flag==1) out=-1; else out=count; }

21. Remove the repeated elements in the array BR1) if any array element is negative, store -1 to the first position of the output array #include<Stdio.h> #include<conio.h> void removerepeat(int[],int); int out[100],i,n; void main() { int input1[100],input; clrscr(); printf("Enter array range:"); scanf("%d",&input); printf("Enter array elements:"); for(i=0;i<input;i++) { scanf("%d",&input1[i]); } removerepeat(input1,input); printf("\nOutput array elements:\n"); for(i=0;i<n;i++) printf("%d\t",out[i]); getch(); } void removerepeat(int input1[],int input) { int j,temp=0,k; if(input<0) { out[0]=-2; } else { for(i=0;i<input;i++) {

if(input1[i]<0) { temp=1; } for(j=i+1;j<input;) { if(input1[i]==input1[j]) { for(k=j;k<input;k++) { input1[k]=input1[k+1]; } input--; } else { j++; } } } if(temp==1) { out[0]=-1; } else { for(i=0;i<input;i++) { out[i]=input1[i]; } } } if(input<0) n=1; else n=input; } 22. Remove the negative values from the array and sort the array Eg:{20,-10,4,78} Output:{4,20,78} Business Rule: Store -1 into the output variable if input2(array size) is negative value #include<stdio.h> #include<conio.h> void delnegandsort(int[],int); int i,output[100],n; void main() { int input1[100],input; clrscr(); printf("Enter array length:"); scanf("%d",&input); printf("Enter array elements:"); for(i=0;i<input;i++) { scanf("%d",&input1[i]); } delnegandsort(input1,input); printf("\noutput\n"); for(i=0;i<n;i++)

{ printf("%d\t",output[i]); } getch(); } void delnegandsort(int input1[],int input) { int j,temp; if(input<0) { output[0]=-1; } else { for(i=0;i<input;) { if(input1[i]<0) { for(j=i;j<input;j++) { input1[j]=input1[j+1]; } input--; } else i++; } for(i=0;i<input;i++) { for(j=i+1;j<input;j++) { if(input1[i]>input1[j]) { temp=input1[i]; input1[i]=input1[j]; input1[j]=temp; } } } for(i=0;i<input;i++) { output[i]=input1[i]; } } if(input<0) n=1; else n=input; } 23. find sum of cubes of prime for n natural numbers Business Rule: Store -1 into the output variable if input value is negative number Store -2 into the output variable if input value is exceeds 32676 #include<stdio.h> #include<conio.h> void sumofcubes(int,int); long int out,k;

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<0) { out=-1; } else { for(i=2;count<input;i++) { flag=0; for(j=2;j<i;j++) { if(i%j==0) { flag=1; break; } } if(flag==0) { //printf("%d----%d\n",i,(i*i*i)); sum=sum+i*i*i; count++; } } out=sum; } } 24. From the given array find sum of multiples of 5 and calculate avg Business Rule: Store -1 into the output variable if any of the input element is negative Store -2 into output variable if input2(array size)is negative value #include<Stdio.h> #include<conio.h> void sumofmul5(int[],int); float out; int i; void main() { int input1[100],input; clrscr(); printf("ENter array size"); scanf("%d",&input); printf("Enter array elements:"); for(i=0;i<input;i++)

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<0) { out=-2; } else { for(i=0;i<input;i++) { if(input1[i]<0) { temp=1; } if(input1[i]%5==0) { sum=sum+input1[i]; count++; } } if(temp==1) { out=-1; } } 25. find how many 500,100,50,10,1s in given input(rupees) value and count that and store it in output variable Eg:689 500-1 100-1 50-1 10-3 1-9 Output1=15 Business Rule: Store -1 into output variable if input value is negative 26. search the given input and Count how many times it repeating from the given array Eg: Input1-{1,2,2,3,3} Input2-5 Input3-2 Output-2 Business Rule: Store -1 into output variable if any of the array value is negative Store -2 into output variable if input2(array size) is negative Store -3 into output variable if input3(Search value) is negativ //27. Remove the negative elements from array and sort the remaining elements Business Rule:if array size is negative store -1 into the array. // 28. Sort the half of the array in ascending order and the other half in descending order Business Rule:if array size is negative store -1 into the array. //29. search for an element in an array

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<stdio.h> #include<conio.h> void main() { int a[20],n,i,s,output; clrscr(); printf("enter the limit:"); scanf("%d",&n); if(n<0) { output=-2; printf("output=%d",output); } else { printf("enter the elements:"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { output=-1; printf("output=%d",output); goto end; } } printf("search element="); scanf("%d",&s); for(i=0;i<n;i++) { if(a[i]==s) { output=1; printf("output=%d",output); break; } else { output=-3; printf("output=%d",output); break; } } } end: getch(); } 30. sum of cube of prime numbers upto a limit Business Rule:1.if input1< 0, store -1 into the output variable 2.if input1 >32767,store -2 into the output variable #include<stdio.h> #include<conio.h> void main() {

int j,i,output; long int n,sum=0; clrscr(); printf("enter the numbers:"); scanf("%ld",&n); if(n<0) { output=-1; printf("output=%d",output); } else if(n>32767) { output=-2; printf("output=%d",output); } else { for(j=1;j<=n;j++) { i=2; while(i<=j-1) { if(j%i==0) { break; } i++; } if(i==j) { sum=sum+i*i*i; } } printf("sum is %ld",sum); } getch(); } 31. average of the numbers divisible by 5 upto a limit. Business Rule:if input1< 0, store -1 into the output variable #include<stdio.h> #include<conio.h> void main() { int n,i,count=0,output; float avg,s=0; clrscr(); printf("enter the limit:"); scanf("%d",&n); if(n<0) { output=-1; printf("output=%d",output); } else { for(i=1;i<=n;i++) { if(i%5==0) { s=s+i;

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<stdio.h> #include<conio.h> void main() { long int n,t,r=0,q,s=0,count=1,output; clrscr(); printf("enter the value:"); scanf("%ld",&n); if(n<0) { output=-1; printf("output=%d",output); } else { while(n!=0) { t=n%10; r=(r*10)+t; n=n/10; } q=r; while(q!=0) { t=q%10; if(count%2!=0) { s=s+t; } count++; q=q/10; } printf("output=%ld",s); } getch(); }

//33.

From the given input array remove the negative elements and then sort the remaining array elements, store that into the output array. Consider input1 is array elements and input2 is array size. Input1= {8,-6,12,79,57} Input2=5 Output1= { 8,12,57,79}

Eg:

Business Rules: i) #include<stdio.h>

If the array size (input2) is negative then store -1 in to the output array.

#include<conio.h> void main() { int input1[25],input2,output1[25],i,j,temp; clrscr(); printf("enter the range"); scanf("%d",&input2); if(input2<0) { output1[0]=-1; printf("%d",output1[0]); } else { printf("enter array elements"); for(i=0;i<input2;i++) scanf("%d",&input1[i]); for(i=0;i<input2;i++) { if(input1[i]<0) { temp=input1[i]; input1[i]=input1[i+1]; input1[i+1]=temp; } } for(i=0;i<input2-1;i++) { for(j=i+1;j<input2-1;j++) { if(input1[i]>input1[j]) { temp=input1[i]; input1[i]=input1[j]; input1[j]=temp; } } } for(i=0;i<input2-1;i++) output1[i]=input1[i]; for(i=0;i<input2-1;i++) printf("\t%d",output1[i]); } getch(); } //34. Eg: Input1= 15 Output1=10 Business Rules: i) If the input1 is negative store -1 in to the output variable. ii) If input1 is greater than 500 store -2 in to the output variable. #include<stdio.h> #include<conio.h> void main() { int input1,output1,i,sum=0,count=0; clrscr(); Find the average of multiples of five up to N natural number. Consider input1 is the N value.

printf("enter limit"); scanf("%d",&input1); if(input1<0) { output1=-1; printf("%d",output1); } else if(input1>500) { output1=-2; printf("%d",output1); } else { for(i=1;i<=input1;i++) { if(i%5==0) { sum=sum+i; count=count+1; } } output1=sum/count; printf("output1=%d",output1); } getch(); } 35. Search and remove the element from the given input array and then sort the remaining array elements, store that in to the output array. Consider input1 is array elements, input2 is array size and input3 is the search element.

Eg: Input1= {54, 26, 78, 32, 55} Input2= 5 Input3=78 Ouput1= {26, 32, 54, 55} Business Rules: i) If any of the array element (input1) is negative store -1 into the output array. ii) If the array size (input2) is negative store -2 into the output array. iii) If the search element (input3) is not present in the array (input1) store -3 into the output array. #include<stdio.h> #include<conio.h> void main() { int input1[25],input2,input3,output1[25],i,temp,j,k=0,count=0; clrscr(); printf("enter range"); scanf("%d",&input2); if(input2<0) { output1[0]=-2; printf("%d",output1[0]); } else { printf("enter array elements"); for(i=0;i<input2;i++) scanf("%d",&input1[i]);

for(i=0;i<input2;i++) if(input1[i]<0) { count++ ; //output1[0]=-1; //printf("%d",output1[0]); //break; } if(count==0) { printf("enter element to be searched"); scanf("%d",&input3); for(i=0;i<input2;i++) { if(input1[i]==input3) { k++; temp=input1[i]; input1[i]=input1[i+1]; input1[i+1]=temp; } } if(k>0) { for(i=0;i<input2-1;i++) { for(j=i+1;j<input2-1;j++) { if(input1[i]>input1[j]) { temp=input1[i]; input1[i]=input1[j]; input1[j]=temp; } } } for(i=0;i<input2-1;i++) printf("\t%d",input1[i]); } else { output1[0]=-3; printf("%d",output1[0]); } } else { output1[0]=-1; printf("%d",output1[0]); } }

getch(); } 36. Convert the given binary number into the decimal number. Consider input1 is the binary number. Eg: Input1=1001 Output1=9

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<stdio.h> #include<conio.h> 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<stdio.h> #include<conio.h> void main() {

int c,f; clrscr(); printf("temperature="); scanf("%d",&c); if(c<0) { f=-1; } else { f=1.8*c+32; } printf("output=%d",f); getch(); } 38. Calculate the sum of positive elements in the given array. . Consider input1 is array elements and input2 is array size.

Eg: Input1= {10,-5, 12, 47, 36, -24} Input2=6 Output1=105 Business Rules: i) If the array doesnt have any positive element store -1 to the output variable. ii) If the array size (input2) is negative store -2 to the output variable. #include<stdio.h> #include<conio.h> void main() { int input1,i,j,sum=0,output; clrscr(); printf("\n enter num"); scanf("%d",&input1); if(input1<0) { output=-1; printf("%d",output); } else if(input1>500) { output=-2; printf("%d",output); } else { for(j=1;j<=input1;j++) { i=2; while(i<=j-1) { if(j%i==0) { break; } i++; } if(i==j)

{ 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<stdio.h> #include<conio.h> void main() { int input1[10],input2,i,sum=0,output; clrscr(); printf("\n input2="); scanf("%d",&input2); if(input2<0) { output=-2; printf("%d",output); } else { printf("\n input1="); for(i=0;i<input2;i++) { scanf("%d",&input1[i]); } for(i=0;i<input2;i++) { if(input1[i]<0) { output=-1; } else { sum=sum+input1[i]; output=sum; } } printf("output =%d",output); } getch(); } 40. Given two input arrays input1[],input2[], and size of both arrays is input3 Add the first element of input1[] to last element of input2[] and Second element of input1[] to last before element of input2[] . store result to output1[] Eg.

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<stdio.h> #include<conio.h> void main() { int input1[10],input2[10],c[10],i,j,n,sum=0,output; clrscr(); printf("\n size"); scanf("%d",&n); if(n<0) { output=-2; printf("%d",output); } else { printf("\n Elements of A:"); for(i=0;i<n;i++) { scanf("%d",&input1[i]); } printf("\n Elements of B:"); for(j=0;j<n;j++) { scanf("%d",&input2[j]); } for(i=0;i<n;i++) { for(j=0;j<n;j++) { if(input1[i]<0 && input2[j]<0) { output=-1; printf("%d",output); goto l; } else { c[i]=input1[i]+input2[n-1-i]; } } } printf("output is"); for(i=0;i<n;i++) { printf("%d",c[i]); } } getch(); }

41.

Given input array is input1[] and size of array is input3 Add the positive elements in array and store result in output1 Eg.

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<stdio.h> #include<conio.h> void main() { int a[10],n,i,j,sum=0,op; clrscr(); printf("\n enter the limit of the arrays"); scanf("%d",&n); if(n<0) { op=-2; printf("\n %d",op); } else if(n>0) { printf("\n enter the array elements"); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { if(a[i]>0) { sum=sum+a[i]; printf("\n %d",sum); } else { op=-1; printf("\n %d",op); } } } getch(); } 42. Given input array is input1[] and size of array is input3 Identify the second largest element and store it to output1 input1[]={2,3,4,1,9} output1=4 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<stdio.h> #include<conio.h> void main() { int a[10],i,j,n,temp=0,op; clrscr(); printf("\n enter the array limkit"); scanf("%d",&n); if(n<0) { op=-2; printf("\n %d",op); }

else if(n>0) { printf("\n enter the array elements"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { op=-1; printf("\n %d",op); } else if(a[i]>0) { for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } } printf("\n the second largest element is %d",a[n-2]); } } getch(); } 43. Given input1 number , Find the sum of the square of prime number from 1 to N where N is input1 Eg. If input1 is 7 Output1=22+32+52+72 Store the result to output 1 Business rule1: if the input1 is negative then store -1 to output1 Business rule1: if the input1 > 500 then store -2 to output1

44. convert the binary input to decimal Store result to output1 Eg. If input1=100 Output1=4 Business rule1: if the input1 is not binary then store -1 to output1 Business rule1: if the input1 > 11111 then store -2 to output1 #include<stdio.h> #include<conio.h> void main() { long int a,n,d,dec=0,j=1,b,count=0,k=0,op; clrscr(); printf("\n enter the no to be converted"); scanf("%ld",&n); b=n; if(b>=11111) {

op=-2; printf("\n %ld",op); } else if(b<11111) { while(b!=0) { count++; d=b%10; if(d==0 || d==1) k++; b=b/10; } if(count==k) { while(n!=0) { d=n%10; dec=dec+j*d; j=j*2; n=n/10; } printf("\n the converted no is %ld",dec); } else if(count!=k) { op=-1; printf("\n %d",op); } } getch(); } 45. Program to calculate sum of cubes of primes up to a limit.(including that number) Business Rule Input1 <0 set output1 = -1 Input1 >32767 set output1= -2 #include<stdio.h> #include<conio.h> void main() { long int k,j,i; long int n,sum=0; clrscr(); printf("enter the limit"); scanf("%ld",&n); if(n<0) sum=-1; else if(n>32767) sum=-2; else { for(i=1;i<=n;i++) { k=0; for(j=1;j<=i;j++) { if(i%j==0) {

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 <0 set output1 = -1 else Output1=sum #include<stdio.h> #include<conio.h> void main() { int n,i,k=0,sum=0; float avg; clrscr(); printf("enter the limit"); scanf("%d",&n); if(n<0) avg=-1; else { for(i=1;i<=n;i++) { if(i%5==0) { sum=sum+(i*i); k++; }} avg=(float)sum/k; } printf("the o/p is %0.2f",avg); getch(); } 47. Program to find out whether the numbers in an array is a multiple of 3 if yes Output1=number Any nmber in Input1[]<0 output1=-1 Input2 <0 output1=-2 (size) #include<stdio.h> #include<conio.h> void main() { int out, n,i,k=0,b=0,a[100];

clrscr(); printf("enter the limit"); scanf("%d",&n); if(n<0){ out=-2; } else {

for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[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<stdio.h> #include<conio.h> void main() { long int count=0, b, n,rev=0,d; clrscr(); printf("enter the number"); scanf("%ld",&n); if(n<0) count=-1; else if(n>32767) 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[] <0 any element output1=-1 Input2<0 output1=-2 (size) Input3<0 output1=-3 (element to be searched) #include<stdio.h> #include<conio.h> void main() { int a[20],n,flag=0,k,output,i,count=0; clrscr(); printf("\nEnter the size of the array : "); scanf("%d",&n); if(n<0) { output=-2;

printf("\nBR2 : Output is %d",output); // Array size is negative } else if(n>0) { printf("\nEnter the elements of array : "); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) // Elements of array is negative { output=-1;flag=1; } } if(flag==0) { printf("\nEnter the element to be searched : "); scanf("%d",&k); // k - element to search if(k<0) { output=-3; printf("\nBR3 : Output is %d",output); // Search element is negative } else if(k>0) { for(i=0;i<n;i++) { if(a[i]==k) { count++; } } } if(k>0) { if(count==0) { // Search element not found in array printf("\nElement %d is not found in array",k); } else { output=count; printf("Element %d is found %d times in array",k,output); } } } else if(flag==1) { printf("\nBR1 : Output is %d",output); // Array element negative } } getch(); } 50. Find out the savings of a person if the salary is given his expenses are 50% of the total salary for food 20% for travel. If the person works for 31days in a month he will get 500 additional. Input1 > 9000 output1 = -1 Input1 < 0 output1 = -2 Input2 < 0 output1 = -4 (days)

#include<stdio.h> #include<conio.h> 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) { output1=-2;flag=1; //BR2 } else if(salary>=0 && salary<=9000) { printf("\nEnter the number of calendar days in the month : "); scanf("%f",&days); if(days<0) { output1=-4;flag=1; // BR3 } else if(days==0) // Zero days { daysal=0; output1=0; } else if(days>0 && days<=30) // 30 days { daysal=salary/30.0; earnsal=daysal*days; foodexp=0.5*earnsal; // 50% of Food Expenses travelexp= 0.2*earnsal; // 20% of Travel Expenses output1=earnsal-foodexp-travelexp; } else if(days==31) // 31days { salary=salary+500; daysal=salary/31.0; earnsal=daysal*days; foodexp=0.5*earnsal; // 50% of Food Expenses travelexp= 0.2*earnsal; // 20% of Travel Expenses output1=earnsal-foodexp-travelexp; } else { printf("\nCalendar days should be between 0 and 31"); dayflag=1; } } else if(salary>9000) { output1=-1;flag=1; //BR1 } if(flag==1) { printf("\nOutput is %d",(int)output1); } else if(dayflag==0)

{ 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<stdio.h> #include<conio.h> void main() { int num,output,rev=0,rem,sum=0,count=0; clrscr(); printf("\nEnter the Number : "); scanf("%d",&num); if(num<0) // BR { output=-1; } else if(num>0) { 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<stdio.h> #include<conio.h> void main() { int i,num,output1,n,sum=0; clrscr(); printf("\nEnter the number : "); scanf("%d",&n); num=n; if(num<0) {

output1=-2; // BR3 } else if(num>0) { for(i=1;i<num;i++) { if(num%i==0) // Checking factors { sum=sum+i; } } if(sum==n) output1=1; // BR1 else output1=-1; // BR2 } printf("\nOutput is %d",output1); getch(); } 53. wap to find the maximum of three numbers.assign the maximum number to output1, br:store -1 to output1 if any of the three input values are negative store -2 to output if the enterd numbers is greater than 32767 #include<stdio.h> #include<conio.h> void main() { long int a,b,c,output1; clrscr(); printf("\nEnter the three numbers : "); scanf("%ld %ld %ld",&a,&b,&c); if(a<0 || b<0 || c<0) { output1=-1; } else if(a>32767 || b>32767 || c>32767) { output1=-2; } else { if(a>b) 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<stdio.h> #include<conio.h> void main() { int n ,sum=0,i; clrscr(); printf("enter the limit:"); scanf("%d",&n);

for(i=0;i<=n;i++) { if(i%3==0) { sum=sum+i; }} printf("%d",sum); getch(); } 55. wap to swap the numbers keeping the middle element constant in a array.input1[] is array input2 is size of the array and store the result in output1[] example: input1:{32,24,4,99,78}; input2:5 output1:{78,99,4,24,32} #include<stdio.h> #include<conio.h> void main() { int n,a[20],i,j; clrscr(); printf("enter the limit:"); scanf("%d",&n); printf("enter the number of elements:"); for(i=1;i<=n;i++) scanf("%d",&a[i]); //for(i=0;i<n;i++)

for(j=n;j>0;j--) printf("%d",a[j]); getch(); } 56. wap to find the maximum repeated elements in a array and store it to output array,where input1 is array and input2 is array size if two or more numbers are reapeted for same number of times all the numbers should be in output variable. input1:{1,2,2,2,3,3,3,4,4,5} input2:10 output1: 2,3 #include<stdio.h> #include<conio.h> void main() { int n,a[100],i,j,k=0,max=0,op[20],count=0,flag=0; clrscr(); printf("Enter the size of the array:"); scanf("%d",&n); if(n<0) { op[0]=-2; } else { printf("Enter the elements in the array:"); for(i=0;i<n;i++) { scanf("%d",&a[i]); if(a[i]<0) flag=1;

} if(flag==1) op[0]=-1; else { for(i=0;i<n;i++) { count=0; for(j=i+1;j<n;j++) { if(a[i]==a[j]) count++; } if(count>max) { max=count; op[k]=a[i]; } else if(count==max) { if(i!=0) k++; max=count; op[k]=a[i]; } else {} } } } for(i=0;i<=k;i++) printf("\n%d",op[i]); getch(); } 57. find the product of digits and check whether the number is divisible by 3 and 5 #include<stdio.h> #include<conio.h> void main() { int r,temp,n,pro=1,rev,output; clrscr(); printf("Enter the value:"); scanf("%d",&n); if(n<0) { output=-1; } else if(n>0) { while(n) { rev=n%10; pro=pro*rev; n=n/10; } printf("Pro = %d",pro); if(pro%3==0 && pro%5==0) { output=1; } else B.R1: store -1 in output if input is negative

{ output=0; } } printf("\n%d",output); getch(); }

58. find the product of prime numbers in a given array B.R1: if input<0 store -1 in output B.R2: if size of the array<0 store -2 in output #include<stdio.h> #include<conio.h> void main() { int input,a[100],i,j,count=0,c,output=1; clrscr(); printf("Enter the size of the array:"); scanf("%d",&input); if(input<0) { output=-1; printf("\n%d",output); } else if(input>0) { printf("Enter the elements of the array:"); for(i=0;i<input;i++) scanf("%d",&a[i]); for(i=0;i<input;i++) { if(a[i]<0) { output=-2; } } if(a[i]>0) { count=0; for(i=0;i<input;i++) { c=0; for(j=2;j<a[i];j++) { if(a[i]%j==0) { c=1; break; } } if(c==0) { output=output*a[i]; count++; } } } printf("\n%d",output); } getch();

} 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<stdio.h> #include<conio.h> void main() { int n,a[100],temp,i,j,output; clrscr(); printf("Enter the size of the array:"); scanf("%d",&n); if(n<0) { output=0; printf("\n%d",output); } else if(n>0) { printf("\nEnter the elements of the array:"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { output=-1; break; } } if(a[i]>0) { for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } output=a[n-2]; } printf("\n%d",output); } getch(); } 60. find the product of maximum and minimum numbers 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<stdio.h> #include<conio.h> void main() { int a[100],n,big,small,output,i; clrscr(); printf("Enter the size of the array:"); scanf("%d",&n);

if(n<0) { output=-2; printf("\n%d",output); } else if(n>0) { printf("\nEnter the elements in the array:"); for(i=0;i<n;i++) scanf("\n%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { output=-1; break; } } if(a[i]>0) { big=a[0]; small=a[0]; for(i=0;i<n;i++) { if(big<a[i]) { big=a[i]; } } for(i=0;i<n;i++) { if(small>a[i]) { small=a[i]; } } output=big*small; } printf("\n%d",output); } getch(); } 61. sort the given array and insert the element in appropriate position in the 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<stdio.h> #include<conio.h> void main() { int out,k=0,i,j,n,temp,a[100],x,value; clrscr(); printf("enter the range \n"); scanf("%d",&n); if(n<0) { out=-2; printf("out=%d",out); } else {{ printf("enter the no. of elements \n");

for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) if(a[i]>0) { k++; } if(k==n) { for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { temp=a[i]; a[i]=a[j]; a[j]=temp; } } } for(i=0;i<n;i++) printf("%d \n",a[i]); printf("enter the position to be inserted \n"); scanf("%d",&x); printf("enter the value to be inserted \n"); scanf("%d",&value); for(i=n;i>=x-1;i--) a[i+1]=a[i]; a[x-1]=value; for(i=0;i<=n;i++) printf("%d \n ",a[i]); } else {out=-1; printf("out=%d",out); } }} getch(); } 62. Perform the operations based on the input given if input3=1 find input1+input2 Input3=2 find input1-input2 Input3=3 find input1*input2 Input3=4 find input1/input2 B.R1: if input1 and input2 is less than 0 store -1 in the output. #include<stdio.h> #include<conio.h> void main() { int input1,input2,input3,n; clrscr(); printf("enter the number \n"); scanf("%d %d",&input1,&input2); printf("enter the choice \n"); scanf("%d",&n); if((input1<0) && (input2<0)) { input3=-1; printf("%d",input3); } else

//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<stdio.h> #include<conio.h> void main() { int n,i,j,a[100],f,c; clrscr(); printf("\nenter the limit:"); scanf("%d",&n); if(n<0) printf("-2"); else { for(i=0;i<n;i++) { scanf("%d",&a[i]); } f=0; for(i=0;i<n;i++) { if(a[i]<0) { printf("-1"); f++; } }

if(f==0) { for(i=0;i<n;i++) { c=0; for(j=2;j<a[i];j++) { if(a[i]%j==0) { c++; } } if(c==0 &&a[i]!=1) printf("%d\n",a[i]); } } } getch(); } 64. Find the product of digits in the number (Business rule:Store -1 in the ouput variable if the given number is negative) #include<stdio.h> #include<conio.h> void main() { int n,r,p=1; clrscr(); printf("enter the number \n"); scanf("%d",&n); if(n<0) { printf("-1"); } if(n>0) { while(n) { r=n%10; p=p*r; n=n/10; } printf("the product of the digits is %d\n",p); } getch(); } 65. Number of denominations (500,100,50,10,1) required for the given amount (Business rule: Store -1 in the output variable if the amount is negative) #include<stdio.h> #include<conio.h> void main() { int amt; clrscr(); printf("\n Enter the amount:"); scanf("\n %d",&amt); if(amt<0) { printf("\n %d",-1); }

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 pay<0 and -2 in the output variable if basic pay>10000 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 <0 and -2 if N >23627) #include<stdio.h> #include<conio.h> void main() { int n,i,sum=0; clrscr(); printf("\n Enter the number:"); scanf("\n %d",&n); for(i=0;i<=n;i++) { if(i%3==0) { sum=sum+i; printf("\n %d",i); } } printf("\n %d",sum); getch(); }

68. Generate perfect numbers upto N natural numbers (Business rule: store -1 in output variable if N <0 and -2 if N >23627) #include<stdio.h> #include<conio.h> void main() { int i,min,max,sum,nu; clrscr(); printf("\n Enter the min: "); scanf("\n %d",&min); if(min<0) { printf("\n %d",-1); } else if(min>0) { printf("\n Enter the max:"); scanf("\n %d",&max); if(max<=23627)

{ for(i=min;i<=max;i++) { nu=1; sum=0; while(nu<i) { if(i%nu==0) sum=sum+nu; nu++; } if(sum==i) printf("\n %d",i); } } else if(max>23627) { printf("\n %d",-2); } } getch(); } 69. Find the second largest element in the array. If any one of the element in input array is negative ,store-1, If input2 is negative,store -2. #include<stdio.h> #include<conio.h> void main() { int i,j,n,t,temp=0,output[100]; clrscr(); printf("enter the number"); scanf("%d",&n); if(n<0) { output[0]=-2; printf("%d",output[0]); } else { printf("enter the elements"); for(i=0;i<n;i++) { scanf("%d",&output[i]); if(output[i]<0) { temp=1; } } if(temp==1) { output[0]=-1; printf("%d",output[0]); } else { for(i=0;i<n;i++) { for(j=i+1;j<n;j++)

{ if(output[i]<output[j]) { t=output[i]; output[i]=output[j]; output[j]=t; } } } printf("the second largest number is :%d",output[1]); } } getch(); } 70. Fahrenheit to celcius If input1 is negative,store -1 #include<stdio.h> #include<conio.h> void main() { float output,input; printf("enter farhenheit temp\n"); scanf("%f",&input); if(input<0) { output=-1; printf("%f",output); } else { output=1.8*input+32; printf("equalent temp id %f\n",output); } getch(); } 71. Celcius to Fahrenheit If input1 is negative,store -1 #include<stdio.h> #include<conio.h> void main() { float output,f; printf("enter farhenheit temp\n"); scanf("%f",&f); if(f<0) { output=-1; printf("%f",c); } else { output=(f-32)/1.8; printf("equalent temp id %f\n",output); } getch(); } 72. Find the count of input3 in the given array. Ex: Input1[]={1,2,4,4,4,5}

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<stdio.h> #include<conio.h> 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<0) { output=-2; printf("%d",output); } else { printf("enter the elements\n"); for(i=0;i<n;i++) { scanf("%d",&input[i]); if(input[i]<0) { temp=1; } } if(temp==1) { output=-1; printf("%d",output); } else { printf("enter element to get count\n"); scanf("%d",&ele); if(ele<0) { output=-3; printf("%d",output); } else { for(i=0;i<n;i++) { if(input[i]==ele) output++; } printf("count is %d",output); } } } getch(); } 73. Find the gross pay for the employee. House rent allowance=50% of basic Special allowance=75% of basic

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 o utput 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 is 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 days 500 extra if he works for 31 days Food expenditure is 50% of salary Travel expenditure is 20% of salary Business rule: If input1 >9000 then store -1 if input1 is negative then store -3 If 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

Business rule if array size is negative store -2 in output1 #include<stdio.h> #include<conio.h> void main() { int a[100],i,j,n,count=0,temp; printf("Enter the number"); scanf("%d",&n); if(n<0) { a[n-2]=-1; } else { printf("Enter the value"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { a[n-2]=-2; count=count+1; break; }} if(count==0) { for(i=0;i<n;i++) {

for(j=i+1;j<n;j++) { temp=a[i]; a[i]=a[j]; a[j]=temp; }} } }

printf("%d",a[n-2]); getch(); } 82. Armstrong no.(if no. is negative output=-1,if no. has digits>3 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 is ve output=-2) 84. print largest repeated element in array(if array has any negative no. output=-1,if size of array is ve output=-2) 85. count no. of digits in number(if no. is ve output=-1) #include<stdio.h> #include<conio.h> void main() { int a,count=0; clrscr(); printf("enter the number"); scanf("%d",&a); if(a<0) count=-1; else { while(a!=0) { a=a/10; count=count+1; } } printf("the number of digit in a number is %d",count); getch(); }

86.. Average of marks of student(if avg>99 output=-1,if 70<avg<80 output=1, if 60<avg<70 output=2, if avg<60 output=3,if any of the marks is ve output=-2) #include<stdio.h> #include<conio.h> void main() {

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<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { out=-2; goto l; } } for(i=0;i<n;i++) sum=sum+a[i]; avg=(float)sum/(float)n; printf("the average is %.2f",avg); if(avg>99) out=-1; else if(avg>70 && avg<80) out=1; else if(avg>60 && avg<70) out=2; else out=3; l: printf("the output should be %d",out); getch(); }

87. sum of multiples of a no. upto N natural no.s Input1:N=15 Input2:3 Output:3+6+9+12+15=45 ( input2 is ve output=-2,if input1 is ve output=-1) #include<stdio.h> #include<conio.h> void main() { int a,b,i,j,sum=0; clrscr(); printf("the number are "); scanf("%d%d",&a,&b); if(a<0) sum=-1; else if(b<0) sum=-2; else { for(i=a;i<=b;i++) { if(i%a==0) { sum=sum+i; printf(" %d +",i);

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

88. write a Program to calculate temperature from celcius to Fahrenheit c/5=f/9-32 Business Rules: a)If given input is negative store -1 to the output variable #include<stdio.h> void main() { float f,c; clrscr(); printf("enter celsius"); scanf("%f",&c); if(c<0) f=-1; else f=((c*9)/5)+32; printf("the fahrenheit is %.2f",f); getch(); } 89. Write a Program to find whether the number is palindrome or not Business Rules a) if given input is negative then store -1 to the output variable b)if given number is palindrome store 1 to the output variable c)if given number is not a palindrome store -2 to the output #include<stdio.h> #include<conio.h> void main() { int n,mod,rev=0,output,temp; clrscr(); printf(" \n Enter a num"); scanf("%d",&n); if(n<0) { output=-1;printf("%d",output); } else { temp=n; while(n!=0) { mod=n%10; rev=(rev*10)+mod; n=n/10; } if(temp==rev) { output=1; printf("%d",output); } else {

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 variable a)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=56 Output=1 #include<stdio.h> #include<conio.h> void main() { int input,output,pdt=1,d; clrscr(); printf("enter number"); scanf("%d",&input); if(input<0) { output=-2; printf("%d",output); } else if(input%3==0||input%5==0) { output=-1; printf("%d",output); } else { while(input) { d=input%10; pdt=pdt*d; input=input/10; } if(pdt%3==0||pdt%5==0) output=1; printf("%d",output); } getch(); } 91. Write a program to find smallest element in an array and store the result to output variable Business Rules: a)if given number is negative then store -1 to output variable b)if size of the input is negative then store -2 to output variable Example: input1={5,4,3,2,1} Input2=5 Output=2 #include<stdio.h> #include<conio.h> void main() { int input1[25],input2,output,count=0,i,j; clrscr();

printf("enter range"); scanf("%d",&input2); if(input2<0) { output=-2; printf("%d",output); } else { printf("enter elements"); for(i=0;i<input2;i++) scanf("%d",&input1[i]); for(i=0;i<input2;i++) { if(input1[i]<0) count++; } if(count==0) { output=input1[0]; for(i=0;i<input2;i++) { if(input1[i]<output) output=input1[i]; } printf("output=%d",output); } else { output=-1; printf("%d",output); } } Getch(); } 92. Write a program to remove the duplicate elements from the given array .Input2 is size of the array Store the result to output array . Business Rules: a)If any of the given input element is negative then store -1 to the first position of the output array b)If the size of the array is negative then store -2 to the first position of the output array .. Example: Input1[10]={1,1,1,2,3} Input2=5 Output={1,2,3} #include<stdio.h> #include<conio.h> void main() { int input1[25],input2,output[25],i,j,k,count=0; clrscr(); printf("enter limit"); scanf("%d",&input2); if(input2<0) { output[0]=-2; printf("%d",output[0]); } else

{ printf("enter elements"); for(i=0;i<input2;i++) scanf("%d",&input1[i]); for(i=0;i<input2;i++) if(input1[i]<0) { count++; } if(count==0) { for(i=0;i<input2;i++) { for(j=i+1;j<input2;) { if(input1[i]==input1[j]) { for(k=j;k<input2;k++) input1[k]=input1[k+1]; input2--; } else j++; } } printf("resultant array\n" ); for(i=0;i<input2;i++) printf("\t%d",input1[i]); } else { output[0]=-1; printf("%d",output[0]); } } getch(); } Write a program to delete the element from the given array and sort those remaining elements Input2 is size of array Input3 is the element which we need to delete and store the results to output array. Business Rules: a)If any of the input is negative then store -1 to the first position of the output array B)If searching element is not present in the array then store -2 to the first position of the output array Example: Input1={5,4,3,2,1} Input2=5 Input3=4 Output={1,2,3,5} #include<stdio.h> #include<conio.h> void main() { int n,a[10],b,pos=0,c,i,j,t; clrscr(); printf("Enter the number"); scanf("%d",&n); printf("Enter the values"); for(i=1;i<=n;i++) scanf("%d",&a[i]); 93.

for(i=0;i<n;i++) { if(a[i]<0) { c=-1; printf("%d",c); goto l; }} printf("Enter the element to be deleted"); scanf("%d",&b); if(b!=a[i]) { a[0]=-2; printf("%d",a[0]); } else { for(i=1;i<=n;i++) { if(a[i]==b) { pos=i; break; } } if(pos!=0) { for(i=pos;i<=n;i++) { a[i]=a[i+1]; } c=n-1; } else c=n; printf("The array after deletion is"); for(i=1;i<=c;i++) printf("%d",a[i]); for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]>a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } } printf("the array is "); for(i=0;i<n-1;i++) printf("%d",a[i]); } getch(); }

94. Second largest in a given array.[if array has -ev elements store -1 , if array size is -ve store -2] #include<stdio.h> #include<conio.h> void main() { int n,i,j,t,a[10]; clrscr(); printf("Enter the number"); scanf("%d",&n); if(n<0) { a[0]=-2; printf("The output is %d",a[0]); goto l; } printf("Enter the values"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { a[0]=-1; printf("%d",a[0]); break; } else { for(i=0;i<n;i++) { for(j=i+1;j<n;j++) { if(a[i]<a[j]) { t=a[i]; a[i]=a[j]; a[j]=t; } } } printf(" The second largest number is %d",a[1]); l: }} getch(); }

95.

Check whether the given element is present in array.[store -2 if array has -ve elements, -2 if array size is -ve and -1 if element not present and 1 if element present] #include<stdio.h> #include<conio.h> void main() { int n,a[10],d,i,output,output1; clrscr(); printf("enter the number"); scanf("%d",&n); if(n<0) { output=-2;

printf("%d",output); goto l; } printf("Enter the values"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { output1=-2; printf("%d",output1); goto l; } } printf("Enter the element to search"); scanf("%d",&d); for(i=0;i<n;i++) { if(d==a[i]) { output=1; printf("%d",output); } } if(output!=1) { output=-1; printf("%d",output); } else { for(i=0;i<n;i++) { if(d==a[i]) { printf(" the element %d in the %d position",d,i); break; } } } l: getch(); }

96.

Employee salary.[if basic > 1000 store -1, no of days > 31 store -2, if basic is -ve store -3, if no Of days is -ve store -4] #include<stdio.h> #include<conio.h> void main() { int n,i,j,bs,c,d; clrscr(); printf("enter the basic salary"); scanf("%d",&bs); if(bs>1000) { c=-1; printf("\n %d",c);

} else if(bs<0) { c=-3; printf("\n %d",c); } printf("enter the no of days"); scanf("%d",&d); if(d>31) { c=-2; printf("\n %d",c); } else if(d<0) { c=-4; printf("\n %d",c); } getch(); }

97.

Grade of the student. [if input array has -ve elements -1,size of array -ve store -2,if average is >99 store -3] #include<stdio.h> #include<conio.h> 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<0) { av=-2; printf("%d",av); goto l; } else { printf("enter the grades "); for(i=0;i<n;i++) { scanf("%d",&a[i]); } for(i=0;i<n;i++) { if(a[i]<0) { av=-1; printf("%d",av); goto l; } } for(i=0;i<n;i++) sum=sum+a[i]; avg=(float)sum/(float)n; if(avg>99) {

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 array has -ve elements store -1, size of array -ve store -2]

#include<stdio.h> #include<conio.h> 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<=n;i++) { scanf("%d",&a[i]); } printf("the order of arrangement is \n"); for(i=1;i<=n/2;i++) b[i]=a[i]; for(i=1;i<=n/2;i++) { if(a[i]%2==0) { for(j=i+1;j<=n/2;j++) { if(a[j]%2==0) { if(a[i]>a[j]) { k=a[i]; a[i]=a[j]; a[j]=k; } } } } }

for(i=1;i<=n/2;i++) { printf("the even number in 1st half %d\n",a[i]);

} for(i=(n/2)+1;i<=n;i++) { if(a[i]%2!=0) { for(j=i+1;j<=n;j++) { if(a[j]%2!=0) { if(a[i]<a[j]) { k=a[i]; a[i]=a[j]; a[j]=k; } } } } }

for(i=(n/2)+1;i<=n;i++) { printf(" the odd is=%d\n",a[i]); } getch(); } 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<stdio.h> #include<conio.h> void main() { long int a,count=0; clrscr(); printf("enter any no"); scanf("%ld",&a); if((a<0)||(a>32767)) { 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 the given no is negative store output1=-1,if given no is >32767 #include<stdio.h> #include<conio.h> void main() { long int a,count=0; clrscr(); printf("enter any no"); scanf("%ld",&a); if((a<0)||(a>32767)) { 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 the given no is negative store output1=-1,if given no is >32767 #include<stdio.h> #include<conio.h> void main() { long int a,count=0; clrscr(); printf("enter any no"); scanf("%ld",&a); if((a<0)||(a>32767)) { 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. 101. Sum of digits of a given number. Input1=given number, if the given no is negative store output1=-1,if given no is >32767 Sum of even numbers up to n numbers if the given no is negative store output1=-1,if given no is >32767

#include<stdio.h> #include<conio.h>

void main() { int n,i,out=0; clrscr(); printf("\n enter the no"); scanf("%d",&n); if(n<0) { out=-1; } else if(n>3276) { out=-1; } else { for(i=1;i<n;i++) { if(i%2==0) { out=out+i; } } } printf("\n the sum of n even no is %d",out); getch(); } 102. Sum of squares of prime numbers up to n note: 1 is not prime. If the given no is negative store output1=-1 #include<stdio.h> #include<conio.h> void main()

{ int n,i,j,out=0; printf("\n enter the range"); scanf("%d",&n); if(n<0) { out=-1; } else { for(i=2;i<=n;i++) { for(j=2;j<=i-1;j++) { if(i%j==0) { break; }} if(j==i) out=out+(i*i); }} printf("\n the sumof square of nprime nos is %d",out); getch(); } Sum of cubes of primes numbers up to n note: 1 is not prime. If the given no is negative store output1=-1 void main() { int n,i,j,out=0; printf("\n enter the range"); scanf("%d",&n); 103.

if(n<0) { out=-1; } else { for(i=2;i<=n;i++) { for(j=2;j<=i-1;j++) { if(i%j==0) { break; }} if(j==i) out=out+(i*i*i); }} printf("\n the sumof square of nprime nos is %d",out); getch(); }

104.

Remove duplicate element from an array. If the size of an array is negative, store output1=-1, If any of the input array element is negative, store output1=-2.

#include<stdio.h> #include<conio.h> void main() { int a[20],i,j,k,n,out[10]; clrscr(); printf("enter the array size:"); scanf("%d",&n);

if(n<0) { out[0]=-1; printf("\n %d",out[0]); } else { printf("\n enter the no:"); for(i=0;i<n;i++) scanf("%d",&a[i]); for(i=0;i<n;i++) { if(a[i]<0) { out[0]=-1; printf("the output should be %d",out[0]); goto l; } } printf("\n orginal array is:"); for(i=0;i<n;i++) { for(j=i+1;j<n;) { if(a[j]==a[i]) { for(k=j;k<n;k++) a[k]=a[k+1]; n--;

} else j++; } } for(i=0;i<n;i++) { out[i]=a[i]; printf("%d",out[i]); } } l: getch(); } 105. Calculate gross salary with house rent allowances and special allowances for given days No of days=input2, basic salary=input1, gross salary=output1,if the person works for 31 days add 500 to the gross salary, if basic is >10000,store output1=-1.