Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- q1
- [7:52 pm, 10/10/2022] Pratiyush DSU B3: #include <stdio.h>
- int add(int a, int b)
- {
- return(a+b);
- }
- int sub(int a, int b)
- {
- return(a-b);
- }
- int multiply(int a, int b)
- {
- return(a*b);
- }
- float devide(int a, int b)
- {
- if (b=0)
- {
- return(-999999);
- }
- else{
- return(a/b);
- }
- }
- int main()
- {
- int x,y,z,ch,con=1;
- while(con=1)
- {
- printf("enter 0 for exit\nenter the choice\n'1' for adding\n'2' for substraction\n'3' for multiplication\n'4' for division");
- scanf("%d",&ch);
- if (ch==0)
- {
- con=0;
- break;
- }
- printf("enter the two numbers");
- scanf("%d%d",&x,&y);
- switch (ch)
- {
- case 1:
- printf("the sum is %d",add(x,y));
- break;
- case 2:
- printf("the subtraction is %d",sub(x,y));
- break;
- case 3:
- printf…
- [7:53 pm, 10/10/2022] Pratiyush DSU B3: q2
- [7:53 pm, 10/10/2022] Pratiyush DSU B3: #include <stdio.h>
- int rev (int n )
- {
- int rem;
- if(n==0)
- {
- return 0;
- }
- else{
- rem=n%10;
- printf("%d",rem);
- return(rem+rev(n/10));
- }
- }
- int main()
- {
- int num;
- printf("enter the number");
- scanf("%d",&num);
- printf("\n%d",rev(num));
- return 0;
- }
- Ok thanks
- 3,4,5?
- bhai ussi pdf se karlo
- Ok
- What time are you coming to clg ?
- At 8
- Where ru?
- Ground floor
- Lab?
- Hmmm
- Ok will come there
- Hm
- Kya hmm
- Aao saale
- [8:42 am, 11/10/2022] Pratiyush DSU B3: q3
- [8:42 am, 11/10/2022] Pratiyush DSU B3: #include <stdio.h>
- void main()
- {
- int a[100][100],b[100][100],c[100][100],i,j,k,r1,c1,r2,c2,sum;
- printf("enter the number of rows and column of mm1trix \n");
- scanf("%d%d",&r1,&c1);
- printf("enter the elements in matrix1");
- for(i=0;i<r1;i++)
- for(j=0;j<c1;j++)
- {
- scanf("%d",(*(a + i) + j));
- }
- printf("enter the number of rows and column of mm1trix \n");
- scanf("%d%d",&r2,&c2);
- if(c1!=r2)
- {
- printf("error");
- }
- else{
- printf("enter the elements in matrix2");
- for(i=0;i<r2;i++)
- for(j=0;j<c2;j++)
- {
- scanf("%d",(*(b + i) + j));
- }
- }
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c2;j++)
- {
- for (k=0;k<c1;k++)
- {
- sum=sum+(((a + i) + k)) * (((b + k) + j));
- }
- ((c + i) + j)=sum;
- sum=0;
- }
- }
- printf("the multiplicated of two matrix");
- for(i=0;i<r1;i++)
- {
- for(j=0;j<c2;j++)
- {
- printf("%d\t",((c + i) + j));
- }
- printf("\n");
- }
- }
- [8:42 am, 11/10/2022] Pratiyush DSU B3: q5
- [8:42 am, 11/10/2022] Pratiyush DSU B3: #include <stdio.h>
- void linear(int a[100],int n)
- {
- int i, toSearch, found;
- printf("\nEnter element to search: ");
- scanf("%d", &toSearch);
- found = 0;
- for(i=0; i<n; i++)
- {
- if(a[i] == toSearch)
- {
- found = 1;
- break;
- }
- }
- if(found == 1)
- {
- printf("\n%d is found at position %d", toSearch, i + 1);
- }
- else
- {
- printf("\n%d is not found in the array", toSearch);
- }
- }
- void binary(int a[100],int n)
- {
- int c, first, last, middle, search;
- printf("Enter the value to find:\n");
- scanf("%d",&search);
- first = 0;
- last = n - 1;
- middle = (first+last)/2;
- while (first <= last)
- {
- if (a[middle] < search)
- {
- first = middle + 1;
- }
- else if(a[middle] > search)
- {
- last = middle - 1;
- middle = (first + last)/2;
- }
- else if(a[middle] == search)
- {
- printf("%d is present at index %d.\n", search, middle+1);
- break;
- }
- }
- if (first > last)
- printf("Not found! %d is not present in the list.\n", search);
- }
- void main()
- {
- int a[100],c,n,d,con=1,ch,swap;
- printf("Enter number of elements:\n");
- scanf("%d",&n);
- printf("Enter %d integers:\n", n);
- [8:42 am, 11/10/2022] Pratiyush DSU B3: for (c=0; c < n; c++)
- {
- scanf("%d",&a[c]);
- }
- for (c=0 ; c<n-1; c++)
- {
- for (d=0 ; d <n-c-1; d++)
- {
- if (a[d] > a[d+1])
- {
- swap = a[d];
- a[d] = a[d+1];
- a[d+1] = swap;
- }
- }
- }
- while(con=1)
- {
- printf("enter 0 for exit\nenter the choice\n'1' for linear search\n'2' for binary search\n");
- scanf("%d",&ch);
- if (ch==0)
- {
- con=0;
- break;
- }
- else
- {
- switch (ch)
- {
- case 1:
- linear(a,n);
- break;
- case 2:
- binary(a,n);
- break;
- default:
- printf("error");
- break;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment