Posts

Showing posts with the label array data structure

Array Program #4

Image
7. Read n numbers in an array, read two different numbers, search the first number in an array and replace it with another number in an array and print its index and final array. #include <stdio.h> int main() {     int array[100], x,y, i, n, count = 0;               printf("Enter the number of elements in array\n");      scanf("%d", &n);            printf("Enter %d numbers\n", n);            for (i = 0; i < n; i++)         scanf("%d", &array[i]);             printf("Enter n number by which you want to replace?\n");      scanf("%d",&x);          printf(" By which number?\n");      scanf("%d",&y);   ...

Array Program #3

Image
6. Read two character arrays from user and concat (concatenate)them one after other in third array and print final array. #include<stdio.h> #include<string.h> void main() {      int i,j;      char a[100],b[100],c[100];      printf("Enter the first string\n");      scanf("%s",a);      printf("Enter the second string\n");      scanf("%s",b);      printf("First string  = %s\n", a);      printf("Second string = %s\n", b);      i=0;      while(a[i]!='\0')      {           c[i]=a[i];           i++;      }      c[i]=' ';      i++;       j=0;    ...

Array Program #2

Image
5. Read n numbers in an array and print them in ascending order. #include <stdio.h> void main() {     int i, j, a, n, number[100];      printf("Enter the value of N \n");      scanf("%d", &n);      printf("Enter the numbers \n");      for (i = 0; i < n; ++i)      {          scanf("%d", &number[i]);       }       for (i = 0; i < n;i++)       {         for (j = i + 1; j < n;j++)           {             if (number[i] > number[j])                {                 a =  numbe...