// 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
// program to swap two numbers using pointers
#include<stdio.h>
void swap(int *,int *);
int main()
{
int a=5,b=10;
printf("Values of a and b before swapping:\n");
printf("a=%d , b=%d\n",a,b);
swap(&a,&b);
printf("Values of a and b after swapping:\n");
printf("a=%d , b=%d\n",a,b);
return 0;
}
void swap(int *a,int *b){
int temp;
temp=*a;
*a=*b;
*b=temp;
}
#include<stdio.h>
void swap(int *,int *);
int main()
{
int a=5,b=10;
printf("Values of a and b before swapping:\n");
printf("a=%d , b=%d\n",a,b);
swap(&a,&b);
printf("Values of a and b after swapping:\n");
printf("a=%d , b=%d\n",a,b);
return 0;
}
void swap(int *a,int *b){
int temp;
temp=*a;
*a=*b;
*b=temp;
}
👍14❤5
// Program to print sum of three numbers and also find maximum of three
void sumAndMax(int ,int ,int ,int*,int*);
#include<stdio.h>
int main()
{
int a=50,b=90,c=20,sum,max;
sumAndMax(a,b,c,&sum,&max);
printf("Sum= %d , Maximum number= %d",sum,max);
return 0;
}
void sumAndMax(int x,int y,int z,int *p,int *q){
*p=x+y+z;
*q=(x>y && x>z)?x:(y>z?y:z); // greatest of three numbers using ternary operator
}
void sumAndMax(int ,int ,int ,int*,int*);
#include<stdio.h>
int main()
{
int a=50,b=90,c=20,sum,max;
sumAndMax(a,b,c,&sum,&max);
printf("Sum= %d , Maximum number= %d",sum,max);
return 0;
}
void sumAndMax(int x,int y,int z,int *p,int *q){
*p=x+y+z;
*q=(x>y && x>z)?x:(y>z?y:z); // greatest of three numbers using ternary operator
}
👍15
// Program to print array elements using pointers
#include<stdio.h>
void printArray(int*,int);
int main()
{
int a[]={10,20,30,40,50};
printArray(a,sizeof(a)/sizeof(a[0]));
return 0;
}
void printArray(int *ptr_arr,int size){
int i;
for(i=0;i<size;i++)
{
printf("%4d",*(ptr_arr+i));
}
}
#include<stdio.h>
void printArray(int*,int);
int main()
{
int a[]={10,20,30,40,50};
printArray(a,sizeof(a)/sizeof(a[0]));
return 0;
}
void printArray(int *ptr_arr,int size){
int i;
for(i=0;i<size;i++)
{
printf("%4d",*(ptr_arr+i));
}
}
👍12
// program to read a string from the user and convert characters in lower case to upper
// and the characters which are in uppercase to lower uaing pointers.
#include<stdio.h>
void toggleChar(char*);
int main()
{
char str[50];
printf("Enter the string:");
scanf("%[^\n]",str);
toggleChar(str);
printf("Converted string is: %s",str);
return 0;
}
void toggleChar(char *ptr_ch){
int i;
for(i=0;*(ptr_ch+i)!='\0';i++){
if(*(ptr_ch+i)>='A' && *(ptr_ch+i)<='Z'){
*(ptr_ch+i)=*(ptr_ch+i)+32;
}
else if(*(ptr_ch+i)>='a' && *(ptr_ch+i)<='z'){
*(ptr_ch+i)=*(ptr_ch+i)-32;
}
}
}
// and the characters which are in uppercase to lower uaing pointers.
#include<stdio.h>
void toggleChar(char*);
int main()
{
char str[50];
printf("Enter the string:");
scanf("%[^\n]",str);
toggleChar(str);
printf("Converted string is: %s",str);
return 0;
}
void toggleChar(char *ptr_ch){
int i;
for(i=0;*(ptr_ch+i)!='\0';i++){
if(*(ptr_ch+i)>='A' && *(ptr_ch+i)<='Z'){
*(ptr_ch+i)=*(ptr_ch+i)+32;
}
else if(*(ptr_ch+i)>='a' && *(ptr_ch+i)<='z'){
*(ptr_ch+i)=*(ptr_ch+i)-32;
}
}
}
👍11❤3👏1
// program to store data dynamically using malloc and print it
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p,n,i;
printf("Enter number of elements to be stored:");
scanf("%d",&n);
p=(int*)malloc(n*sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter %d elements:",n);
for(i=0;i<n;i++)
{
scanf("%d",p+i);
}
printf("The entered elements are:");
for(i=0;i<n;i++){
printf("%4d",*(p+i));
}
free(p);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p,n,i;
printf("Enter number of elements to be stored:");
scanf("%d",&n);
p=(int*)malloc(n*sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter %d elements:",n);
for(i=0;i<n;i++)
{
scanf("%d",p+i);
}
printf("The entered elements are:");
for(i=0;i<n;i++){
printf("%4d",*(p+i));
}
free(p);
return 0;
}
👍10👏2🥰1
// program to store data dynamically using calloc and print it
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p,n,i;
printf("Enter number of elements to be stored:");
scanf("%d",&n);
p=(int*)calloc(n,sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter %d elements:",n);
for(i=0;i<n;i++)
{
scanf("%d",p+i);
}
printf("The entered elements are:");
for(i=0;i<n;i++){
printf("%4d",*(p+i));
}
free(p);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p,n,i;
printf("Enter number of elements to be stored:");
scanf("%d",&n);
p=(int*)calloc(n,sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter %d elements:",n);
for(i=0;i<n;i++)
{
scanf("%d",p+i);
}
printf("The entered elements are:");
for(i=0;i<n;i++){
printf("%4d",*(p+i));
}
free(p);
return 0;
}
👍11❤1
// program to store data dynamically using calloc and extend the existing data using realloc and print it
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p,n,i,k;
printf("Enter number of elements to be stored:");
scanf("%d",&n);
p=(int*)calloc(n,sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter %d elements:",n);
for(i=0;i<n;i++)
{
scanf("%d",p+i);
}
printf("The entered elements are:");
for(i=0;i<n;i++){
printf("%4d",*(p+i));
}
printf("\nEnter number of elements you want to extend:");
scanf("%d",&k);
p=(int*)realloc(p,k*sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter the next %d elements:",k);
for(i=0;i<k;i++)
{
scanf("%d",(p+n+i));
}
printf("The entered elements after extending are:");
for(i=0;i<n+k;i++){
printf("%4d",*(p+i));
}
free(p);
return 0;
}
#include<stdio.h>
#include<stdlib.h>
int main()
{
int *p,n,i,k;
printf("Enter number of elements to be stored:");
scanf("%d",&n);
p=(int*)calloc(n,sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter %d elements:",n);
for(i=0;i<n;i++)
{
scanf("%d",p+i);
}
printf("The entered elements are:");
for(i=0;i<n;i++){
printf("%4d",*(p+i));
}
printf("\nEnter number of elements you want to extend:");
scanf("%d",&k);
p=(int*)realloc(p,k*sizeof(int));
if(p==NULL){
printf("Cannot allocate memory");
exit(1);
}
printf("Enter the next %d elements:",k);
for(i=0;i<k;i++)
{
scanf("%d",(p+n+i));
}
printf("The entered elements after extending are:");
for(i=0;i<n+k;i++){
printf("%4d",*(p+i));
}
free(p);
return 0;
}
👍38❤10👏5🔥4🤯4🥰3😁1
Which operator is used for finding the remainder of the division in C?
Anonymous Quiz
24%
a. /
65%
b. %
6%
c. *
5%
d. //
👍19👏5❤1