From 8115da6d68c40e905c337229fb38afb5a49efb13 Mon Sep 17 00:00:00 2001 From: swaaz Date: Mon, 12 Aug 2019 22:44:57 +0530 Subject: [PATCH] added --- C/program-21/program.c | 39 +++++++++++++++++++++++-------------- C/program-33/program.c | 14 +++++++++++++ C/program-34/program.c | 37 +++++++++++++++++++++++++++++++++++ C/program-35/program.c | 25 ++++++++++++++++++++++++ Python/program-2/program.py | 2 +- 5 files changed, 101 insertions(+), 16 deletions(-) create mode 100644 C/program-33/program.c create mode 100644 C/program-34/program.c create mode 100644 C/program-35/program.c diff --git a/C/program-21/program.c b/C/program-21/program.c index 0cfb05d1..3fa728fa 100644 --- a/C/program-21/program.c +++ b/C/program-21/program.c @@ -1,17 +1,26 @@ -#include +/* +You are given a sorted (either in the increasing or in the decreasing order) sequence of numbers, ending with a -1. You can assume that are at least two numbers before the ending -1. + +Let us call the sequence x0 x1 ... xn -1. + +You have to output the number of distinct elements in the sorted sequence. + +Kindly do not use arrays in the code. +*/ + + +#include +#include + int main() { - int a,i,count=0; - printf("enter the number\n"); - scanf("%d",&a); - for(i=2;i<=a/2;i++) - { - if(a%i==0) - { - count=1; - break; - }} -if(count) printf("not prime"); -else printf("prime"); -return 0; -} \ No newline at end of file + int count=0,n=0; + while(n!=-1) + { + scanf("%d",&n); + count++; + + } +printf("%d",count-1); + return 0; +} diff --git a/C/program-33/program.c b/C/program-33/program.c new file mode 100644 index 00000000..80f7131f --- /dev/null +++ b/C/program-33/program.c @@ -0,0 +1,14 @@ +/* Arithematic operation using pointers */ +#include +void main() +{ +int a,b; +int *x,*y; +scanf("%d%d",&a,&b); +x=&a; +y=&b; +//s=; +printf("%d\t%d",*x+*y,abs(*x-*y)); + +} + diff --git a/C/program-34/program.c b/C/program-34/program.c new file mode 100644 index 00000000..8d193871 --- /dev/null +++ b/C/program-34/program.c @@ -0,0 +1,37 @@ +/*In this assignment, you will be given an NxN matrix. You have to +determine whether the matrix is a triangular matrix. +First, you will be given N, which is the size of the matrix. + +Then you will be given N rows of integers, where each row consists of +N integers separated by spaces. +If the input matrix is triangular, then print yes. Otherwise, print +no. */ + + + + + +#include +#include + +int main() +{ +int a[10][10],n,i,j,flag=0; + scanf("%d",&n); + for(i=0;ij || j>i) ) flag=1; + } + } + if(!(flag))printf("no\n"); + else printf("yes"); + return 0; +} diff --git a/C/program-35/program.c b/C/program-35/program.c new file mode 100644 index 00000000..97c5c795 --- /dev/null +++ b/C/program-35/program.c @@ -0,0 +1,25 @@ +/* You are given a sequence of non-negative integers terminated by -1. + You have to output 1 if there are atleast 2 distinct elements in the sequence and 0 if the sequence consists of only 1 integer. + Note that -1 is not part of the sequence. The sequence is not necessarily sorted. */ + + +#include +#include + +int main() +{ + int a=0,n=0,count=0; + while(n!=-1) + { + scanf("%d",&n); + if(a!=n) + { + a=n; + count++; + } + + } +if(count>=2) printf("%d",1); +else printf("%d",0); + return 0; +} diff --git a/Python/program-2/program.py b/Python/program-2/program.py index 4648e701..7df869a1 100644 --- a/Python/program-2/program.py +++ b/Python/program-2/program.py @@ -1 +1 @@ -print("Hello, World!") \ No newline at end of file +print("Hello, World!")