Friday, 29 June 2018
Thursday, 28 June 2018
second largest of array
#include<stdio.h>
int main()
{
int a[100],n,i,max,max2;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
max=max2=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max2=max;
max=a[i];
}
else if(max2<a[i])
{
max2=a[i];
}
}
printf("%d",max2);
return 0;
}
int main()
{
int a[100],n,i,max,max2;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%d",&a[i]);
max=max2=a[0];
for(i=0;i<n;i++)
{
if(a[i]>max)
{
max2=max;
max=a[i];
}
else if(max2<a[i])
{
max2=a[i];
}
}
printf("%d",max2);
return 0;
}
double diognal
#include<stdio.h>
int main()
{
int i,j,k,n;
printf("enter the number");
scanf("%d",&n);
int a=1,b=20,c=n+1;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("%d ",a);
a++;
}
for(k=i+1;k<c;k++)
{
printf("%d ",b);
b--;
}
printf("\n");
}
return 0;
}
output:
enter the number4
1 20 19 18 17
2 3 16 15 14
4 5 6 13 12
7 8 9 10 11
int main()
{
int i,j,k,n;
printf("enter the number");
scanf("%d",&n);
int a=1,b=20,c=n+1;
for(i=0;i<n;i++)
{
for(j=0;j<=i;j++)
{
printf("%d ",a);
a++;
}
for(k=i+1;k<c;k++)
{
printf("%d ",b);
b--;
}
printf("\n");
}
return 0;
}
output:
enter the number4
1 20 19 18 17
2 3 16 15 14
4 5 6 13 12
7 8 9 10 11
number pattern
#include<stdio.h>
int main()
{
int i,j,n;
printf("enter the number");
scanf("%d",&n);
int l=n;
for(i=0;i<n;i++)
{
int x=n;
for(j=l;j>0;j--)
{
printf("%d",x);
x--;
}
l--;
printf("\n");
}
l=2;
for(i=0;i<n-1;i++)
{
int x=n;
for(j=1;j<=l;j++)
{
printf("%d",x);
x--;
}
l++;
printf("\n");
}
return 0;
}
output:
enter the number4
4321
432
43
4
43
432
4321
int main()
{
int i,j,n;
printf("enter the number");
scanf("%d",&n);
int l=n;
for(i=0;i<n;i++)
{
int x=n;
for(j=l;j>0;j--)
{
printf("%d",x);
x--;
}
l--;
printf("\n");
}
l=2;
for(i=0;i<n-1;i++)
{
int x=n;
for(j=1;j<=l;j++)
{
printf("%d",x);
x--;
}
l++;
printf("\n");
}
return 0;
}
output:
enter the number4
4321
432
43
4
43
432
4321
Anagrams
#include<stdio.h>
#include<string.h>
int main()
{
char s1[20],s2[20];
printf("enter string1");
scanf("%s",s1);
printf("enter string2");
scanf("%s",s2);
int f1[26]={0},f2[26]={0};
int i;
int l1=strlen(s1),l2=strlen(s2),flag=0;
for(i=0;i<l1;i++)
{
int a=s1[i]-'a';
f1[a]++;
}
for(i=0;i<l2;i++)
{
int a=s2[i]-'a';
f2[a]++;
}
for(i=0;i<26;i++)
{
if(f1[i]!=f2[i])
{
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
printf("anagrams");
else
printf("not anagrams");
return 0;
}
#include<string.h>
int main()
{
char s1[20],s2[20];
printf("enter string1");
scanf("%s",s1);
printf("enter string2");
scanf("%s",s2);
int f1[26]={0},f2[26]={0};
int i;
int l1=strlen(s1),l2=strlen(s2),flag=0;
for(i=0;i<l1;i++)
{
int a=s1[i]-'a';
f1[a]++;
}
for(i=0;i<l2;i++)
{
int a=s2[i]-'a';
f2[a]++;
}
for(i=0;i<26;i++)
{
if(f1[i]!=f2[i])
{
flag=1;
break;
}
else
flag=0;
}
if(flag==0)
printf("anagrams");
else
printf("not anagrams");
return 0;
}
Wednesday, 21 February 2018
Zeros and Ones
Zeros and Ones
The zeros tool returns a new array with a given shape and type filled with 's.
import numpy
print numpy.zeros((1,2)) #Default type is float
#Output : [[ 0. 0.]]
print numpy.zeros((1,2), dtype = numpy.int) #Type changes to int
#Output : [[0 0]]
The ones tool returns a new array with a given shape and type filled with 's.
import numpy
print numpy.ones((1,2)) #Default type is float
#Output : [[ 1. 1.]]
print numpy.ones((1,2), dtype = numpy.int) #Type changes to int
#Output : [[1 1]]
Task
You are given the shape of the array in the form of space-separated integers, each integer representing the size of different dimensions, your task is to print an array of the given shape and integer type using the tools
numpy.zeros
and numpy.ones
.
Input Format
A single line containing the space-separated integers.
Constraints
Output Format
First, print the array using the
numpy.zeros
tool and then print the array with the numpy.ones
tool.
Sample Input 0
3 3 3
Sample Output 0
[[[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]]
[[0 0 0]
[0 0 0]
[0 0 0]]]
[[[1 1 1]
[1 1 1]
[1 1 1]]
[[1 1 1]
[1 1 1]
[1 1 1]]
[[1 1 1]
[1 1 1]
[1 1 1]]]
Explanation 0
Print the array built using
numpy.zeros
and numpy.ones
tools and you get the result as shown.
Program:
import numpy
a = []
for x in raw_input().split():
a.append(int(x))
print numpy.zeros(a, dtype = numpy.int)
print numpy.ones(a, dtype = numpy.int)
Sorted Merge of Two Linked Lists
Given two sorted linked lists, Merge them so that result is also sorted.
Input Format
N - Elements in first list.
N space separated integers.
M - Elements in second list.
M space separated integers.
N space separated integers.
M - Elements in second list.
M space separated integers.
Constraints
--
Output Format
Single Line of space separated integers.
Sample Input
3
1 3 7
4
2 4 5 9
1 3 7
4
2 4 5 9
Sample Output
1 2 3 4 5 7 9
Explanation
Self explanatory.
Program:
Node *sortedMergeLists(Node *h1, Node *h2)
{
Node *n;
if(h1==NULL)
return h2;
if(h2==NULL)
return h1;
if(h1->data < h2->data)
{
n=h1;
h1->next=sortedMergeLists(h1->next,h2);
}
else
{
n=h2;
h2->next=sortedMergeLists(h1,h2->next);
}
return n;
}
Mindless Algebra
Suppose,
a = 50
b = 2000
c = 40
a = 50
b = 2000
c = 40
Define a mathematical function Fun(n) that does the following:
Fun(n) = n - c, if n > b
Fun(n) = Fun(a + Fun(a + Fun(a + Fun(a + n)))), if n ≤ b.
Fun(n) = n - c, if n > b
Fun(n) = Fun(a + Fun(a + Fun(a + Fun(a + n)))), if n ≤ b.
Print result of calling this Fun() for n-1, n and n+1.
Input Format
N : an integer N >= 0
Output Format
R1 R2 R3 : 3 integers representing result of function calls - Fun(N-1), Fun(N), Fun(N+1).
Sample Input
2000
Sample Output
2039 2040 1961
Explanation
Well, that's mindless function output for inputs N = 1999, 2000 and 2001.
Program:
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int Fun(int n)
{
if(n>2000)
return n-40;
else
return Fun(50+ Fun(50 + Fun(50 + Fun(50 + n))));
}
int main() {
int n;
cin>>n;
cout<<Fun(n-1)<<" "<<Fun(n)<<" "<<Fun(n+1);
return 0;
}
Subscribe to:
Posts (Atom)
ASP.NET Core: How to implement Azure Active Directory (AAD) Authentication in ASP.NET Core
In this tutorial, we will implement security for ASP.NET Core Application using Azure Active Directory (AAD). In this tutorial, I will co...
-
////////// HANDS-ON 1 ///////////////// 1) az network vnet create -g resourceaddressgiveninkatacoda -n myvnet 2) az network vnet delete...
-
Operations Rio quiz 1.Discipline in execution+pursuit of excellnce+customer experience 2.consistent+proactive risk management,discipli...
-
Merge handson Step1 git branch git checkout feature1 Step2 git checkout master git merge feature1 Step3 git checkout feature2 gi...