Professional Documents
Culture Documents
Prime Number From 2 To N Code
Prime Number From 2 To N Code
Input Output
6 YES
4 2 1 3 5 6
Spiral Square
#include<iostream>
using namespace std;
int main(){
int n;
cout<<"Enter the size of the array :";
cin>>n; /*n Size of the array*/
int A[n][n];
int len=n,k=1,p=0,i;
/*k is to assign the values to the array from 1...n*n */
/*len is used to update(decrease) array size
so that values cans be assign to them */
while(k<=n*n){
/*Loop to access the first row of the array*/
for(i=p;i<len;i++){
A[p][i]=k++;
}
/*Loop tp access the last column of the array*/
for(i=p+1;i<len;i++){
A[i][len-1]=k++;
}
/*Loop to access the last row of the array*/
for(i=len-2;i>=p;i--){
A[len-1][i]=k++;
}
/*Loop to access the first column of the array*/
for(i=len-2;i>p;i--){
A[i][p]=k++;
}
p++,len=len-1;
}
/*This block will run only if n is even*/
if(!n%2){
A[(n+1)/2][(n+1)/2]=n*n;
/*It will assign the last value to the centermost element*/
}
/*This loop will print the array in matrix format*/
for(i=0;i<n;i++){
for(int j=0;j<n;j++){
cout<<A[i][j]<<"\t";
}
cout<<endl;
}
return 0;
}
Input
5
Output
1 2 3 4 5
16 17 18 19 6
15 24 25 20 7
14 23 22 21 8
13 12 11 10 9
#include <algorithm>
string x;
sort(x.begin(),x.end());
reverse(x.begin(),x.end());
count(x.begin(),x.end(),*target*)
int y[5]
sort(y,y+5);
reverse(y,y+5);
result = count(5,y+5,*target*);
result = max_element(y,y+5);
result = min_element(y,y+5);
#include <cctype>
char x;
islower(x) //lowercase
isupper(x) //uppercase
isdigit(x) //number
ispunct(x) //punctuation
isalpha(x) //alphabetic
isalnum(x) //alphanumeric
isspace(x) //space
toupper(x)
tolower(x)