C Programming

C Program to Check a Given Year is a Leap Year or not

Here’s a simple C program to check whether a given year is a leap year or not. This program prompts the user to enter a year, and then it checks whether the entered year is a leap year or not. The logic for checking leap years is as follows: Then it is a leap year. Otherwise, it is not a leap year. The program displays the result accordingly. Program : #include<stdio.h>#include<conio.h>int main(){int year;printf(“Enter a year to check if it is a leap year : “);scanf(“%d”,&year);if(year%400==0){printf(“%d is a leap year.\n”,year);}else if(year%100==0){printf(“%d is not a leap year.\n”,year);}else if(year%4==0){printf(“%d is a leap year.\n”,year);}else{printf(“%d is not a leap year.\n”,year);}} Output :

C Program to Check a Given Year is a Leap Year or not Read More »

C Program to Print All Star Pattern Program

Star patterns are a series of * or any other character used to create some pattern or any geometrical shape such as – square, triangle(Pyramid), rhombus, heart etc. These patterns are often prescribed by many c program books and are best for practicing flow control statement. Program 1 : #include<stdio.h>#include<stdio.h>int main(){int x;for(x=0;x<=4;x++){printf(“\n*”);}} Output : Program 2 : #include<stdio.h>#include<stdio.h>int main(){int x;for(x=0;x<=4;x++){printf(“*”);}} Output : Program 3 : #include<stdio.h> #include<stdio.h> int main() { int x,y; for(x=0;x<=4;x++) { for(y=0;y<=4;y++) { printf(“*”);         }         printf(“\n”); } } Output : Program 4 : #include<stdio.h> #include<stdio.h> int main() { int x,y,N; printf(“Enter the number of row = “); scanf(“%d”,&N); for(x=1;x<=N;x++) { for(y=1;y<=x;y++) { printf(“*”);         }         printf(“\n”); } } Output : Program 5 : #include<stdio.h> #include<stdio.h> int main() { int x,y; for(x=0;x<=4;x++) { for(y=4;y>=x;y–) { printf(“*”);         }         printf(“\n”); } } Output : Program 6 : #include<stdio.h> #include<conio.h> int main() { int x,y,z,N; printf(“Enter the number of row = “); scanf(“%d”,&N); for(x=1;x<=N;x++) { for(y=N-1;y>=x;y–) { printf(” “);         }         for(z=1;z<=x;z++) { printf(“*”);         }         printf(“\n”); } } Output : Program 7 : #include<stdio.h> #include<conio.h> int main() { int x,y,z; for(x=5;x>=1;x–) { for(y=4;y>=x;y–) { printf(” “);         }         for(z=1;z<=x;z++) { printf(“*”);         }         printf(“\n”); } } Output : Program 8 : #include<stdio.h>#include<conio.h>main(){int x,y;for(x=1;x<=5;x++){for(y=1;y<=9;y++){if(y<=x||y>9-x){printf(“*”);}else{printf(” “);}}printf(“\n”);}} Output : Program 9 : #include<stdio.h> #include<conio.h> int main() { int x,y,z,N; printf(“Enter the number of row = “); scanf(“%d”,&N); for(x=1;x<=N;x++) { for(y=N-1;y>=x;y–) { printf(” “);         }         for(z=1;z<=x;z++) { printf(“* “);         }         printf(“\n”); } } Output : Program 10 : #include<stdio.h> #include<conio.h> int main() { int x,y,z; for(x=5;x>=1;x–) { for(y=4;y>=x;y–) { printf(” “);         }         for(z=1;z<=x;z++) { printf(“* “);         }         printf(“\n”); } } Output : Program 11 : #include<stdio.h> #include<conio.h> int main() { int x,y; for(x=3;x>=-3;x–) { for(y=3;y>=abs(x);y–) { printf(” * “);         }         printf(“\n”); } } Output : Program 12 : #include<stdio.h> #include<conio.h> int main() { int x,y,z; for(x=3;x>=-3;x–) { for(y=1;y<=abs(x);y++) { printf(” “);         }         for(z=3;z>=abs(x);z–) { printf(“*”);         }         printf(“\n”); } } Output : Program 13 : #include<stdio.h>#include<conio.h>int main(){int x,y;for(x=1;x<=5;x++){for(y=1;y<=5;y++){if(y==3||x==3){printf(“*”);}else{printf(” “);}}printf(“\n”);}} Output :

C Program to Print All Star Pattern Program Read More »

C Program to Check Vowels Consonant Digits or Space

In this c program: You can run this program, enter a character, and it will tell you whether it’s a vowel, consonant, digit, or space. Program : #include<stdio.h> #include<conio.h> int main() { char str[100]; int i,vowels,consonants,digits,spaces; vowels=consonants=digits=spaces=0; printf(“Enter the String : “); fgets(str,99,stdin); for(i=0;str[i]!=’\0′;++i) { if(str[i] ==’a’ ||str[i]==’e’||str[i]==’i’||str[i]==’o’||str[i]==’u’||str[i]==’A’||str[i]==’E’||str[i]==’I’||str[i]==’O’||str[i]==’U’) {     printf(“\n %c is a Vowels.”,str[i]); vowels++; } else if((str[i]>=’a’&&str[i]<=’z’)||(str[i]>=’A’&&str[i]<=’Z’)) { printf(“\n %c is a Consonants.”,str[i]); consonants++; } else if(str[i]>=’0’&&str[i]<=’9′) { printf(“\n %c is a Digit.”,str[i]); digits++; } else if(str[i]==’ ‘||str[i]<=’\t’) { spaces++; } } printf(“\nNumber of Vowels : %d.”,vowels); printf(“\nNumber of Consonant : %d.”,consonants); printf(“\nNumber of Digits : %d.”,digits); printf(“\nNumber of White space & Tabs : %d.”,spaces); return 0; } Output :

C Program to Check Vowels Consonant Digits or Space Read More »

C program to Find the Areas of Geometrical Shapes

This program allows the user to choose between a rectangle, circle, and triangle. It then prompts the user for the required parameters (length and width for a rectangle, radius for a circle, and base and height for a triangle) and calculates and prints the area based on the chosen shape. The ‘switch’ statement is used to handle the different cases for each shape.

C program to Find the Areas of Geometrical Shapes Read More »

C Program to Convert Fahrenheit to Celsius and Vice-Versa

In this c program: You can run this program, enter a temperature in Fahrenheit, and it will display the equivalent temperature in Celsius. Fahrenheit to Celsius : #include<stdio.h>#include<conio.h>int main(){float f,c;printf(“Enter The Fahrenheit Value : “);scanf(“%f”,&f);c=(f-32)*5/9; printf(“Celsius Value : %0.3f”,c);} Output : To convert Celsius to Fahrenheit in a C program, you can use the formula: F=9/5×C + 32 Here’s an example C program that takes a temperature in Celsius as input and converts it to Fahrenheit Celsius to Fahrenheit : #include<stdio.h>#include<conio.h>int main(){float f,c;printf(“Enter The Celsius Value : “);scanf(“%f”,&c);f=(c*9/5)+32; printf(“Fahrenheit Value : %0.3f”,f);} Output :

C Program to Convert Fahrenheit to Celsius and Vice-Versa Read More »

C program to Employee Salary Calculation

Below is a simple example of a C program for employee salary calculation. This program takes basic salary as input and calculates the gross salary by adding allowances and deducting taxes. In this program: Note: This is a simple example, and in a real-world scenario, you might need to consider more factors such as other allowances, deductions, and applicable tax rules. Program : #include<stdio.h>#include<conio.h>int main(){float a,da,hra,ta,ma,gross,pf,sal;printf(“Enter Basic Pay : “);scanf(“%f”,&a);da=(a*18)/100;printf(“\nDearness Allowance(DA) is : %0.2f”,da);ta=(a*15)/100;printf(“\nTravel Allowance(TA) is : %0.2f”,ta);hra=(a*10)/100;printf(“\nHouse Rent Allowance(HRA) is : %0.2f”,hra);ma=(a*15)/100;printf(“\nMedical Allowance(MA) is : %0.2f”,ma);gross=a+da+ta+hra+ma;printf(“\nGross salary : %0.2f”,gross);pf=(gross*13)/100;printf(“\nProvident Fund(Pf) is : %0.2f”,pf);sal=gross-pf;printf(“\nNet Salary is : %0.2f”,sal);} Output :

C program to Employee Salary Calculation Read More »

C Program to Sum of First N natural Number

This c program prompts the user to enter the value of n, then it calculates the sum of the first N natural numbers using a for loop, and finally, it prints the result. You can run this program, enter a value for N, and it will display the sum of the first N natural numbers. Program : #include<stdio.h>#include<conio.h>main(){int n,sum,i;i=1;sum=0;printf(“Enter How many numbers do you want to add up to : “);scanf(“%d”,&n);while(i<=n){sum=sum+i;i=i+1;}printf(“%d is the Sum of first %d numbers.”,sum,n);} Output :

C Program to Sum of First N natural Number Read More »

Shopping Basket
Verified by MonsterInsights