wisdomatrix.com

Avatar

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 »

C Program to find the Biggest of Five Numbers

Below is an example of a C program that finds the largest among five numbers. The program compares each number with the current maximum and updates the maximum whenever a larger number is encountered. Method 1 : #include<stdio.h>#include<conio.h>main(){int a,b,c,d,e;printf(“Enter First the Number : “);scanf(“%d”,&a);printf(“Enter Second the Number : “);scanf(“%d”,&b);printf(“Enter Third the Number : “);scanf(“%d”,&c);printf(“Enter Foruth the Number : “);scanf(“%d”,&d);printf(“Enter Fifth the Number : “);scanf(“%d”,&e);if((a>b)&&(a>c)&&(a>d)&&(a>e)){printf(“%d is the Biggest Number.”,a);}else if((b>a)&&(b>c)&&(b>d)&&(b>e)){printf(“%d is the Biggest Number.”,b);}else if((c>a)&&(c>b)&&(c>d)&&(c>e)){printf(“%d is the Biggest Number.”,c);}else if((d>a)&&(d>b)&&(d>c)&&(d>e)){printf(“%d is the Biggest Number.”,d);}else{printf(“%d is the Biggest Number.”,e);}} Output : Method 2 : #include<stdio.h>#include<conio.h>main(){int a,b,c,d,e,max;printf(“Enter First the Number : “);scanf(“%d”,&a);printf(“Enter Second the Number : “);scanf(“%d”,&b);printf(“Enter Third the Number : “);scanf(“%d”,&c);printf(“Enter Fourth the Number : “);scanf(“%d”,&d);printf(“Enter Fifth the Number : “);scanf(“%d”,&e);if(a>b)max=a;elsemax=b;if(c>max)max=c;if(d>max)max=d;if(e>max)max=e;printf(“Biggest Number is : %d”,max);} Output :

C Program to find the Biggest of Five Numbers Read More »

C Program to find the Biggest of Three Numbers

This c program prompts the user to enter three numbers, reads them using scanf, and then uses a series of if and else if statements to determine and print the largest number among the three. Program : #include<stdio.h>#include<conio.h>main(){int a,b,c;printf(“Enter First the Number : “);scanf(“%d”,&a);printf(“Enter Second the Number : “);scanf(“%d”,&b);printf(“Enter Third the Number : “);scanf(“%d”,&c);if((a>b)&&(a>c)){printf(“%d is the Biggest Number.”,a);}else if((b>a)&&(b>c)){printf(“%d is the Biggest Number.”,b);}else{printf(“%d is the Biggest Number.”,c);}} Output :

C Program to find the Biggest of Three Numbers Read More »

C Program to Swap Two Numbers without Third Variable

In C programming, you can swap the values of two variables without using a third variable by using arithmetic operations. The key idea is to use addition and subtraction (or multiplication and division) to perform the swap. Here’s an example: Program : #include<stdio.h>#include<conio.h>main(){int a,b;printf(“Enter the First Number : “);scanf(“%d”,&a);printf(“Enter the Second Number : “);scanf(“%d”,&b);a=a+b;b=a-b;a=a-b;printf(“\nAfter Swapping…\nFirst Number : %d”,a);printf(“\nSecond Number : %d”,b);} Output :

C Program to Swap Two Numbers without Third Variable Read More »

Shopping Basket
Verified by MonsterInsights