wisdomatrix.com

Avatar

C Program to Reverse a Given Number

This c program takes an integer as input, stores the original number in a separate variable, and then reverses the digits of the number using a while loop. The reversed number is then displayed on the screen along with the original number. Program : #include<stdio.h>#include<conio.h>main(){int n,r=0;printf(“Enter a number to reverse : “);scanf(“%d”,&n);while(n!=0){r=r*10;r=r+n%10;n=n/10;}printf(“Reverse of Entered Number is = %d\n”,r);} Output :

C Program to Reverse a Given Number Read More »

C Program to Display Fibonacci Series in a Given Range

The Fibonacci series is a series of numbers where each number is the sum of the two preceding ones, usually starting with 0 and 1. Here’s a simple C program to display the Fibonacci series up to a specified number of terms Program : #include<stdio.h>#include<conio.h>void main(){int a,b,c,i,n;a=0;b=1;printf(“\nEnter n for how many times generate series : “);scanf(“%d”,&n);printf(“\nFibonacci Series : \n”);printf(“%d %d “,a,b);for(i=0;i<=n-3;i++){c=a+b;a=b;b=c;printf(“%d “,c);}getch();} Output :

C Program to Display Fibonacci Series in a Given Range Read More »

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 »

Shopping Basket
Verified by MonsterInsights