C PROGRAMMING
Ir al canal en Telegram
Sin datos
Suscriptores
-824 horas
-347 días
+8830 días
Archivo de publicaciones
Subscribe our channel for termux hacking,python animation,coding,html ,telegram bot tips & trick related - 👉 https://youtube.com/@CODEBOMBS Subscribe our channel for termux hacking, designing, tips & trick, bot making related - 👉 https://youtube.com/@TECHINDNN
Kya abhi bhi Google pe hi search krte ho 😒
Smart bniye use kijiye hmara Chatgpt telegram bot
👉 @imabhiAI_bot
✅ unlimited message
✅ 24×7 Support
✅ support all languages
✅ translation features
✅ quick response
✅ easy to use
Our other bot you can try
Compiler bot advance - @IOCompiler_bot
Code compiler - @Cmpbbot
Compiler pro - @CodeCompiler_Bot
Solve maths - @mathsrobot
Group/channel manage -
@Myhurthearts_bot
// 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;
}
//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;
}
Program to calculate power of a number without using pow() function.
Program -
-----------------------------------------------------------
#include<stdio.h>
int main()
{
int base,exp,res=1,i;
printf("Enter the base:");
scanf("%d",&base);
printf("Enter the exponent:");
scanf("%d",&exp);
for(i=1;i<=exp;i++)
{
res=res*base;
}
printf("%d to the power of %d is :%d",base,exp,res);
return 0;
}
-----------------------------------------------------------
-----------------------------------------------------------
#basicprograms
Program to print company bonus on salary
#include<stdio.h>
#include<string.h>
main()
{
int i,j;
float salary,bonus;
char gender;
printf("Enter M for Male and F for Female\n");
scanf("%c",&gender);
printf("Enter Salary\n");
scanf("%f",&salary);
if(gender=='M' || gender=='m')
{
if(salary>10000) bonus=(float)(salary*0.05);
//0.05--5% else bonus=(float)(salary*0.07);
}
if(gender=='F' || gender=='f')
{
if(salary>10000) bonus=(float)(salary*0.1);
//0.1--10% else bonus=(float)(salary*0.12);
}
salary+=bonus;
printf("Bonus=%.2f\nSalary=%.2f\n",bonus,salary);
}Swap to number using 3rd variable
#include<stdio.h>
main()
{
int a,b;
printf("Enter a\n");
scanf("%d",&a);
printf("Enter b\n");
scanf("%d",&b);
printf("The values of a is %d
and b is %d before swaping\n",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("The values of a is %d
and b is %d after swaping\n",a,b);
}*What is an Index?*
To access an element in an array, we use its index. The index is a number that identifies the position of the element in the array. The first element in the array has index 0, the second element has index 1, and so on.
*What is an Array ?*
An array is a collection of elements of the same data type, and all these elements are stored in contiguous memory locations, which means that they are placed next to each other in the memory. This arrangement makes it easy to access and manipulate individual elements within the array.
Program to accept three numbers and print them in ascending and descending order
-----------------------------------------------------------
Program:
#include<stdio.h>
#include<math.h>
int main()
{ int a,b,c;
printf("Enter three numbers:");
scanf("%d %d %d",&a,&b,&c);
printf("Entered numbers are %d,%d,%d",a,b,c);
printf("\n--------------------------------");
if (a>=b && a>=c)
{ if (b>=c){
printf("\nDescending order : %d,%d,%d",a,b,c);
printf("\nAscending order : %d,%d,%d",c,b,a);
}
else{
printf("\nDescending order : %d,%d,%d",a,c,b);
printf("\nAscending order : %d,%d,%d",b,c,a);
}
}
else if (b>=a && b>=c) {
if (a>=c){
printf("\nDescending order: %d,%d,%d",b,a,c);
printf("\nAscending order: %d,%d,%d",c,a,b);
}
}
else{
if (b>=a){
printf("\nDescending order : %d,%d,%d",c,b,a);
printf("\nAscending order : %d,%d,%d",a,b,c);
}
else {
printf("\nDescending order : %d,%d,%d",c,a,b);
printf("\nAscending order : %d,%d,%d",b,a,c);
}
}
return 0;
}
-----------------------------------------------------------
#basicprograms
Program to calculate distance between two points.
-----------------------------------------------------
Program:
#include<stdio.h>
#include<math.h>
int main()
{ float x1,x2,y1,y2,distance;
printf("Enter coardinates of first point(x1,y1):\n");
scanf("%f%f",&x1,&y1);
printf("Enter coordinates of second point(x2,y2):\n");
scanf("%f%f",&x2,&y2);
distance=sqrt(pow((x2-x1),2)+pow((y2-y1),2));
printf ("Distance=%.2f",distance);
return 0;
}
-----------------------------------------------------------
#basicprogramsProgram to accept lower case character and print it in uppercase.
----------------------------------------------------------
Program:
#include<stdio.h>
int main()
{char ch;
printf("Enter any character(Lower case):");
scanf("%c",&ch);
printf("Upper case character= %c",ch-32);
return 0;
}
----------------------------------------------------
#basicprograms
Program to swap two numbers↔️ without🚫 using third variable
-----------------------------------------------------------
Program:👇
#include<stdio.h>
int main()
{int a,b;
printf("Enter a=");
scanf ("%d",&a);
printf("Enter b=");
scanf("%d",&b);
printf("Before Swapping:\n");
printf("a=%d\nb=%d",a,b);
a=a+b;
b=a-b;
a=a-b;
printf("\nAfter Swapping:");
printf("\na=%d\nb=%d",a,b); return 0;
}
----------------------------------------------------
#basicprograms
Program to calculate area of triangle.
-----------------------------------------------------
Program:
#include<stdio.h>
int main()
{ float a,b,area;
printf("Enter base and height of triangle:");
scanf("%f%f",&a,&b);
area=(a*b)/2;
printf("Area=%.2f",area);
return 0;
}
-----------------------------------------------------
#basicprograms
Program to print leap years from m to n'th year 🫥
-----------------------------------------------------------
Program:
#include<stdio.h>
int main()
{
int m,n;
printf("Enter the year m:");
scanf("%d",&m);
printf("Enter the year n:");
scanf("%d",&n);
do
{
if((m%4==0 && m%100!=0) || (m%400==0))
{
printf("%d is a leap year\n",m);
}
else{
printf("%d is not a leap year\n",m);
}
m+=1;
}while(m<=n);
return 0;
}
-----------------------------------------------------------
#basicprograms
Program to make a simple calculator 📱using Switch case.♨️💯
-----------------------------------------------------------
Program:
#include <stdio.h>
int main()
{
char operator;
float num1, num2, result;
printf("Enter an operator (+, -, *, /): ");
scanf("%c", &operator);
printf("Enter two operands: ");
scanf("%f %f", &num1, &num2);
switch(operator)
{ case '+':
result = num1 + num2;
printf("%.2f + %.2f = %.2f", num1, num2, result);
break;
case '-':
result = num1 - num2;
printf("%.2f - %.2f = %.2f", num1, num2, result);
break;
case '*':
result = num1 * num2;
printf("%.2f * %.2f = %.2f", num1, num2, result);
break;
case '/':
result = num1 / num2;
printf("%.2f / %.2f = %.2f", num1, num2, result);
break;
default:
printf("Error: Invalid operator!");
break;
}
return 0;
}
-----------------------------------------------------------
#basicprograms
Here is a C program to calculate the factorial of a given number using recursion:
#include <stdio.h>
int factorial(int n) {
if(n == 0 || n == 1) { // Base case
return 1;
}
else { // Recursive case
return n * factorial(n - 1);
}
}
int main() {
int n, fact;
printf("Enter a positive integer: ");
scanf("%d", &n);
if(n < 0) {
printf("Error: Factorial of negative number doesn't exist.");
}
else {
fact = factorial(n);
printf("Factorial of %d = %d", n, fact);
}
return 0;
}
Factorial of a number using while loop.
-----------------------------------------------------------
Program:
#include<stdio.h>
int main()
{ int i=1,fact=1,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("The factorial of %d is : %d",n,fact);
return 0;
}
-----------------------------------------------------------
#basicprograms
Program to calculate area of triangle.
-----------------------------------------------------
Program:
#include<stdio.h>
int main()
{ float a,b,area;
printf("Enter base and height of triangle:");
scanf("%f%f",&a,&b);
area=(a*b)/2;
printf("Area=%.2f",area);
return 0;
}
-----------------------------------------------------
#basicprograms
Find factorial of a number using while loop.
-----------------------------------------------------------
Program:
#include<stdio.h>
int main()
{ int i=1,fact=1,n;
printf("Enter the value of n:");
scanf("%d",&n);
while(i<=n)
{
fact=fact*i;
i++;
}
printf("The factorial of %d is : %d",n,fact);
return 0;
}
-----------------------------------------------------------
#basicprograms
