Write a program to check prime number in C Programming?

#include #include void main() { int n,i,m=0,flag=0; //declaration of variables. clrscr(); //It clears the screen. printf(“Enter the number to check prime:”); scanf(“%d”,&n); m=n/2; for(i=2;i<=m;i++) { if(n%i==0) { printf("Number is not prime"); flag=1; break; //break keyword used to terminate from the loop. } } if(flag==0) printf("Number is prime"); getch(); //It reads a character from the keyword. … Read more

Write a program to print Fibonacci series using recursion?

#include #include void printFibonacci(int n) // function to calculate the fibonacci series of a given number. { static int n1=0,n2=1,n3; // declaration of static variables. if(n>0){ n3 = n1 + n2; n1 = n2; n2 = n3; printf(“%d “,n3); printFibonacci(n-1); //calling the function recursively. } } void main(){ int n; clrscr(); printf(“Enter the number of … Read more

Write a program to print Fibonacci series without using recursion?

#include #include void main() { int n1=0,n2=1,n3,i,number; clrscr(); printf(“Enter the number of elements:”); scanf(“%d”,&number); printf(“\n%d %d”,n1,n2);//printing 0 and 1 for(i=2;i<number;++i)//loop starts from 2 because 0 and 1 are already printed { n3=n1+n2; printf(” %d”,n3); n1=n2; n2=n3; } getch(); } Certainly! You can achieve the Fibonacci series without using recursion by using a simple iterative approach. … Read more

Write a program to swap two numbers without using the third variable?

#include #include main() { int a=10, b=20; //declaration of variables. clrscr(); //It clears the screen. printf(“Before swap a=%d b=%d”,a,b); a=a+b;//a=30 (10+20) b=a-b;//b=10 (30-20) a=a-b;//a=20 (30-10) printf(“\nAfter swap a=%d b=%d”,a,b); getch(); } Certainly! Here’s a program in C to swap two numbers without using a third variable, using arithmetic operations: cCopy code #include <stdio.h> int main() … Read more

Write a program to print “hello world” without using a semicolon?

#include void main(){ if(printf(“hello world”)){} // It prints the ?hello world? on the screen. } To print “hello world” without using a semicolon in a C program, you can use the \n escape sequence to represent a newline character instead of a semicolon. Here’s the program: cCopy code #include <stdio.h> int main() { if (printf(“hello … Read more