C Programming Codes
13.4K subscribers
139 photos
2 videos
12 links
C Programming Codes || Quizzes || DSA

Learn along with the community

Any queries
admin - @Pradeep_saii
Download Telegram
//8. Program to read n integers into array and count number of odd and even
#include<stdio.h>
int main()
{
int a[50],i,odd=0,even=0,n;
printf("Enter the value of n:");
scanf("%d",&n);
printf("Enter the elements into the array:\n");
for(i=0 ; i< n ;i++ )
{
scanf("%d",&a[i]);
}
for(i=0 ; i<n ;i++)
{
if(a[i]%2 == 0)
even++; //even = even +1
else
odd++;
}
printf("Number of even numbers entered:%d\n",even);
printf("Number of odd numbers entered :%d",odd);
return 0;
}
👍92🥰2🔥1
//9. Write a C Program to generate Fibonacci series using arrays
#include<stdio.h>
int main()
{
int fib[20],i,n;
printf("Enter number of terms in the fibonacci series:");
scanf("%d",&n);
if(n<=0)
{
printf("Invalid input entered ,Please enter a positive number");
return 1;
}
fib[0]=0;
fib[1]=1;
for(i=2 ; i<n ;i++) //loop to generate fibonacci series
{
fib[i]=fib[i-1]+fib[i-2];
}
printf("Fibonacci series upto %d terms :\n",n);
for(i=0 ; i<n ; i++)
{
printf("%d ",fib[i]);
}
return 0;
}
👍75
//10. Program to add two single dimensional arrays which have 5 elements in each.
#include<stdio.h>
int main()
{
int a[5]={1,5,7,3,9},b[5]={2,6,4,8,10},c[5],i;
for(i=0;i<5;i++)
{
c[i]=a[i]+b[i];
}
printf("Resultant array after adding the two array's:\n");
for(i=0 ;i<5 ;i++)
{
printf("%d\t",c[i]);
}
return 0;
}
👍16🔥2
// 11.Program to find the second largest element of an array
#include<stdio.h>
int main()
{
int a[20],i,large1,large2,size;
printf("Enter the size of the array:");
scanf("%d",&size);
printf("Enter the elements of the array:\n");
for(i=0 ; i< size ; i++)
{
scanf("%d",&a[i]);
}
if(a[0]>a[1]){
large1=a[0];
large2=a[1];
}
else{
large1=a[1];
large2=a[2];
}
for(i=2 ; i<size ;i++)
{
if(a[i]>large1){
large2=large1;
large1=a[i];
}
else if(a[i] > large2 && a[i]<large1){
large2=a[i];
}
}
printf("The second largest element of the array= %d",large2);
return 0;
}
👍115
What is Traversing of an array?
The process of visiting each and every element of an array in a specific order is called Traversing an array.
This can be done using a loop, such as a for loop or a while loop.
5👍5
// 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;
}
👍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.
👍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;
}
👍124💯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;
}
👍15
Deletion:
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;
}
👍363🤝1
#include<stdio.h>
int main()
{
int i;
i=printf("Hello world");
printf(" %d",i);
return 0;
}
19👍8💯2👌1
👍28🤔20🔥8😁7👌32👏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"
👍18
#include<stdio.h>
int main()
{
printf(" %d",printf("Hello world"));
return 0;
}
👍117