Showing posts with label Addition. Show all posts
Showing posts with label Addition. Show all posts

Monday, 6 November 2017

Program to find K' th smallest number in Array In C,C++

#include<iostream>
using namespace std;

main()
{
int n,t,k;
cout<<"Enter No Of Testcases:";
cin>>t;
cout<<"Enter Number Of Elements:";
cin>>n
cout<<"Enter K'th Number To be finded:";
cin>>k;
int a[n],count=0,i,j,countb=0;
int b[n],p,q;
for(q=0;q<t;q++)
{
for(p=0;p<n;p++)
{
    cin>>a[p];
}

for(i=0;i<6;i++)
{
count=0;

int temp=a[i];
for(j=0;j<6;j++)
{
if(temp==a[j])
count++;

}
if(count==k)
{
b[i]=a[i];
countb++;
}
}
int small=b[0];
for(i=0;i<countb;i++)
{
if(small>b[i])
small=b[i];
}
cout<<"K'th Smallest Number Is:"<<small;

}

}


Tuesday, 14 March 2017

Insertion In Array by Pointers C++ Program Exampe

#include<iostream>
using namespace std;
#include<conio.h>
 main()
{
int num[50],n, num1, i, pos,*p;
cout<<"Enter Array Size : ";
cin>>n;
cout<<"Enter Numbers : ";
for(i=0; i<n; i++)
cin>>num[i];
p=num;
cout<<"Enter Number to be inserted : ";
cin>>num1;
cout<<"Enter position :";
cin>>pos;
for(i=n; i>pos; i--)
{
*(p+i)=*(p+i-1);
}
*(p+pos)=num1;
for(i=0; i<n+1; i++)
{
cout<<*(p+i)<<" ";
}
getch();
}


Thursday, 9 March 2017

Addition Of String without using strcat() function in C++

#include<iostream>
#include<stdio.h>
#include<string.h>
using namespace std;
main()
{
char n[20],s[50];
int i,j=0,len;
gets(n);
gets(s);
len=strlen(n);
for(i=len;s[j]!='\0';i++)
{
n[i]=s[j];
j++;
}
puts(n);

}

Amazon1Ads