Lab 7. Psat
Lab 7. Psat
int main() {
int size;
return 0;
}
Output :
2. // reverse array
#include<stdio.h>
for(int i=0;i<n;i++)
scanf("%d",&arr[i])
;}
{printf("%d\n",arr[i]);
}}
for(int i=n-1;i>=0;i--)
{
printf("%d\n",arr[i] );
} printf("\n"); }
int main(){int n ;
scanf("%d",&n);
int arr[n];
read(arr,n);
disp(arr,n);
show(arr,n);
return 0;}
#include<stdio.h>
for(int i=0;i<n;i++)
scanf("%d",&arr[i]);
for(int j=0;j<n-i-1;j++)
{
if(arr[j]>arr[j+1])
int temp=arr[j];
arr[j]=arr[j+1];
arr[j+1]=temp;}}}}
int end=n-1;
int i=0;
int diff=arr[end]-arr[i];
return diff ; }
for(int i=0;i<n;i++)
{ printf("%d\n",arr[i]);}
int main(){int n;
scanf("%d",&n);
int arr[n];
read(arr,n);
disp(arr,n);
bubble(arr,n);
return 0;}
//second element
#include<stdio.h>
for(int i=0;i<n;i++)
scanf("%d",&arr[i])
;}
for(int j=0;j<n-i-1;j++)
{if (arr[j]>arr[j+1])
int temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;}
}}}
{int end=n-1;
printf("%d",arr[end-1]);
{
for(int i=0;i<n;i++)
printf("%d",arr[i] );
} printf("\n"); }
int main(){int n ;
scanf("%d",&n);
int arr[n];
read(arr,n);
show(arr,n);
sort(arr,n);
disp(arr,n);
return 0;}
//duplicates
#include<stdio.h>
for(int i=0;i<n;i++)
scanf("%d",&arr[i])
;}
{
for(int j=0;j<n-i-1;j++)
{if (arr[j]>arr[j+1])
int temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;}
}}}
{if(arr[i]==arr[i+1] )
}}}
for(int i=0;i<n;i++)
printf("%d\n",arr[i] );
} printf("\n"); }
int main(){int n ;
scanf("%d",&n);
int arr[n];
read(arr,n);
show(arr,n);
sort(arr,n);
disp(arr,n);
return 0;}
//missing number
#include<stdio.h>
for(int i=0;i<n-1;i++)
scanf("%d",&arr[i])
;}
{
for(int j=0;j<n-i-1;j++)
{if (arr[j]>arr[j+1])
int temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;}
}}}
{if(arr[i+1]!=arr[i]+1 )
}}}
void show(int arr[],int n)
for(int i=0;i<n-1;i++)
printf("%d\n",arr[i] );
} printf("\n"); }
int main(){int n ;
scanf("%d",&n);
int arr[n];
read(arr,n);
show(arr,n);
sort(arr,n);
disp(arr,n);
return 0;}
//negative numbers
#include<stdio.h>
for(int i=0;i<n;i++)
scanf("%d",&arr[i])
;}
for(int j=0;j<n-i-1;j++)
{if (arr[j]>arr[j+1])
int temp=arr[j+1];
arr[j+1]=arr[j];
arr[j]=temp;}
}}}
{printf("%d\n",arr[i]);
}}
for(int i=0;i<n;i++)
printf("%d\n",arr[i] );
} printf("\n"); }
int main(){int n ;
scanf("%d",&n);
int arr[n];
read(arr,n);
show(arr,n);
sort(arr,n);
disp(arr,n);
return 0;}
Code :
#include <stdio.h>
int main() {
int x = 10, y = 20;
return 0;
}
Observation : here in this code we are reading the value of x and y from the
user after this we have created a swap functiion . In that swap function the
value of x and y is copied to a and b respectively .
Now we are printing this value in the function. After that in the main loop we
are printintg the value of x and y .first we printed it before the function call it
will give the value before swapping then we called the function and it printed
the swap value of the x and y. now again we printed x and y and it gives the
original value of x without swapping due to the scope of variable.
Output :
#include <stdio.h>
int main() {
int x = 10, y = 20;
return 0;
}