// Program for traversing an array
#include<stdio.h>
int main()
{
int a[30],i,size;
printf("Enter the size of the array:");
scanf("%d",&size);
printf("Enter the array elements:\n");
for(i=0 ; i< size ;i++)
{
scanf("%d",&a[i]);
}
//Traversing array elements using for loop
for(i=0 ;i<size ;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
#include<stdio.h>
int main()
{
int a[30],i,size;
printf("Enter the size of the array:");
scanf("%d",&size);
printf("Enter the array elements:\n");
for(i=0 ; i< size ;i++)
{
scanf("%d",&a[i]);
}
//Traversing array elements using for loop
for(i=0 ;i<size ;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
👍20🤯4
What is meant by insertion?
Placing a new element at a specified position of an array is called as insertion.
This operation can help maintain the order or structure of data within the array.
Placing a new element at a specified position of an array is called as insertion.
This operation can help maintain the order or structure of data within the array.
👍5
//Program to insert an element at specific position in a sorted array.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[50],i,size,position,val;
printf("Enter the size of the array :");
scanf("%d",&size);
if(size > 50) //bound checking
{
printf("Invalid size input");
exit(1);
}
printf("Enter elements into the array(sorted):");
for(i=0; i< size ; i++)
scanf("%d",&a[i]);
printf("Enter at which position you want insert element:");
scanf("%d",&position);
printf("Enter the value to be inserted:");
scanf("%d",&val);
for(i=size-1 ; i>=position-1 ; i--)
{
a[i+1]=a[i];
}
a[position-1]=val;
size++;
printf("Resultant array after insertion:\n");
for(i=0 ; i<size ; i++)
printf("%d\t",a[i]);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[50],i,size,position,val;
printf("Enter the size of the array :");
scanf("%d",&size);
if(size > 50) //bound checking
{
printf("Invalid size input");
exit(1);
}
printf("Enter elements into the array(sorted):");
for(i=0; i< size ; i++)
scanf("%d",&a[i]);
printf("Enter at which position you want insert element:");
scanf("%d",&position);
printf("Enter the value to be inserted:");
scanf("%d",&val);
for(i=size-1 ; i>=position-1 ; i--)
{
a[i+1]=a[i];
}
a[position-1]=val;
size++;
printf("Resultant array after insertion:\n");
for(i=0 ; i<size ; i++)
printf("%d\t",a[i]);
return 0;
}
👍12❤4💯1
//Program to insert an element at specific position in a unsorted array.
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[50],i,size,position,val;
printf("Enter the size of the array :");
scanf("%d",&size);
if(size > 50) //bound checking
{
printf("Invalid size input");
exit(1);
}
printf("Enter elements into the array:");
for(i=0; i< size ; i++)
scanf("%d",&a[i]);
printf("Enter at which position you want insert element:");
scanf("%d",&position);
printf("Enter the value to be inserted:");
scanf("%d",&val);
a[size]=a[position-1];
size++;
a[position-1]=val;
printf("Resultant array after insertion:\n");
for(i=0 ; i<size ; i++)
printf("%d\t",a[i]);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[50],i,size,position,val;
printf("Enter the size of the array :");
scanf("%d",&size);
if(size > 50) //bound checking
{
printf("Invalid size input");
exit(1);
}
printf("Enter elements into the array:");
for(i=0; i< size ; i++)
scanf("%d",&a[i]);
printf("Enter at which position you want insert element:");
scanf("%d",&position);
printf("Enter the value to be inserted:");
scanf("%d",&val);
a[size]=a[position-1];
size++;
a[position-1]=val;
printf("Resultant array after insertion:\n");
for(i=0 ; i<size ; i++)
printf("%d\t",a[i]);
return 0;
}
👍15
Deletion:
Deletion is an operation or process that involves removing or eliminating a specific element of an array
Deletion is an operation or process that involves removing or eliminating a specific element of an array
👍2
// Program to delete an element at specific position in an array
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[50],i,size,position,value;
printf("Enter the size of the array:");
scanf("%d",&size);
if(size>50) {
printf("Invalid size input");
exit(1);
}
printf("Enter the array elements:");
for(i=0 ; i<size ; i++)
scanf("%d",&a[i]);
printf("Enter at which position you want to delete the element:");
scanf("%d",&position);
if(position<=0 || position >size) {
printf("Invalid position entered");
exit(1);
}
value=a[position-1];
for(i=position-1 ; i< size-1 ; i++)
{
a[i]=a[i+1];
}
size--;
printf("The deleted element is %d\n",value);
printf("Resultant array after deletion:\n");
for(i=0 ; i< size ;i++)
printf("%d\t",a[i]);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int a[50],i,size,position,value;
printf("Enter the size of the array:");
scanf("%d",&size);
if(size>50) {
printf("Invalid size input");
exit(1);
}
printf("Enter the array elements:");
for(i=0 ; i<size ; i++)
scanf("%d",&a[i]);
printf("Enter at which position you want to delete the element:");
scanf("%d",&position);
if(position<=0 || position >size) {
printf("Invalid position entered");
exit(1);
}
value=a[position-1];
for(i=position-1 ; i< size-1 ; i++)
{
a[i]=a[i+1];
}
size--;
printf("The deleted element is %d\n",value);
printf("Resultant array after deletion:\n");
for(i=0 ; i< size ;i++)
printf("%d\t",a[i]);
return 0;
}
👍36❤3🤝1
❤19👍8💯2👌1
Output of above program
Anonymous Quiz
46%
Error
38%
Hello world 11
10%
Hello world 10
6%
11 Hello world
👍28🤔20🔥8😁7👌3❤2👏1
C Programming Codes
#include<stdio.h> int main() { int i; i=printf("Hello world"); printf(" %d",i); return 0; }
Explaination:
This program prints "Hello world" with printf() , and returns value 11, (the character count) which is assigned to variable i. Then, it uses printf again to display the value of i. The program's output will be "Hello world 11"
This program prints "Hello world" with printf() , and returns value 11, (the character count) which is assigned to variable i. Then, it uses printf again to display the value of i. The program's output will be "Hello world 11"
👍18
👍11❤7
C Programming Codes
#include<stdio.h> int main() { printf(" %d",printf("Hello world")); return 0; }
Output of above program
Anonymous Quiz
45%
Error
34%
Hello world 11
15%
11 Hello world
6%
Hello world 10
👍24👌4❤2
C Programming Codes
#include<stdio.h> int main() { printf(" %d",printf("Hello world")); return 0; }
Explaination:
This program prints "Hello world" using the inner printf() function, which returns the number of characters printed (11 in this case). The outer printf() then prints 11 as the result.
This program prints "Hello world" using the inner printf() function, which returns the number of characters printed (11 in this case). The outer printf() then prints 11 as the result.
🤔6👍5
// Program to print value of a variable using pointer
#include<stdio.h>
int main()
{
int x=5;
int *p;
p=&x;
printf("Value of x :%d",*p);
return 0;
}
#include<stdio.h>
int main()
{
int x=5;
int *p;
p=&x;
printf("Value of x :%d",*p);
return 0;
}
👍19🔥1
// program to increment the value of a variable using pointer
#include<stdio.h>
int main()
{
int x=4;
int *p;
p=&x;
printf("Value of X before incrementing:%d\n",x);
*p=*p+1;
printf("Value of X after incrementing:%d",x);
return 0;
}
#include<stdio.h>
int main()
{
int x=4;
int *p;
p=&x;
printf("Value of X before incrementing:%d\n",x);
*p=*p+1;
printf("Value of X after incrementing:%d",x);
return 0;
}
👍12
// Accessing value of a variable using Pointer to pointer
#include<stdio.h>
int main()
{
int a=10;
int *p,**q;
p=&a;
q=&p;
printf("Value of a :%d",**q);
return 0;
}
#include<stdio.h>
int main()
{
int a=10;
int *p,**q;
p=&a;
q=&p;
printf("Value of a :%d",**q);
return 0;
}
👍13❤6
// program for knowing size of pointer,and also size of the data type that it is pointing to
#include<stdio.h>
int main()
{
int *p;
float *q;
double *r;
char *ch;
//size of the pointers
printf("Size of pointer p: %lu\n",sizeof(p));
printf("Size of pointer q: %lu\n",sizeof(q));
printf("Size of pointer r: %lu\n",sizeof(r));
printf("Size of pointer ch: %lu\n",sizeof(ch));
//sizes of data types that pointers are pointing
printf("Size of int: %lu\n",sizeof(*p));
printf("Size of float: %lu\n",sizeof(*q));
printf("Size of double: %lu\n",sizeof(*r));
printf("Size of char: %lu\n",sizeof(*ch));
return 0;
}
#include<stdio.h>
int main()
{
int *p;
float *q;
double *r;
char *ch;
//size of the pointers
printf("Size of pointer p: %lu\n",sizeof(p));
printf("Size of pointer q: %lu\n",sizeof(q));
printf("Size of pointer r: %lu\n",sizeof(r));
printf("Size of pointer ch: %lu\n",sizeof(ch));
//sizes of data types that pointers are pointing
printf("Size of int: %lu\n",sizeof(*p));
printf("Size of float: %lu\n",sizeof(*q));
printf("Size of double: %lu\n",sizeof(*r));
printf("Size of char: %lu\n",sizeof(*ch));
return 0;
}
👍12❤1