C Program To Print "Welcome" without using semicolon's using "Switch-case"

  Program Using switch case:



#include<stdio.h>
void main()
{
switch(printf("welcome"))
{}

}



Above Program show's the following output:


C Program To Print "Welcome" without using semicolon's using "Switch-case"


C Program To Print "Welcome" without using (;) "semicolon's" using if-statement

  Print welcome without using semicolons:



#include<stdio.h>
void main()
{
       if(printf("welcome"))
        {}




Above Program show's the following output:



C program to print welcome without using semicolons using if statement



C Program To Print Number Is Even or Odd Without Using "if-else" Statement Using "Switch-Case"

Program to Print number is even or odd without using if-else statement using switch case:


#include<stdio.h>
int main()
{
int no;
printf("enter the no\n");
scanf("%d",&no);
/*If number is completely divisible by 2 means (no%2=0) is true then inside the case 0: print number is even, otherwise inside the case 1: print number is odd.*/
switch(no%2)
{
case 0: printf("no is even");
break;
case 1: printf("no is odd");
}
    return 0;
}



Above Program show's the following output:


C Program To Print Number Is Even or Odd Without Using  "if-else" Statement Using "Switch-Case"


C Program To Print Maximum Number Between Two Numbers Using Switch Case

Ex: write a C program to find maximum number between two numbers without using if-else using switch case. How to write a C program to find maximum number between two numbers without using if-else using switch case.
c program to print maximum out of two numbers without using if-else statement using Switch Case.


Input from user:

Enter value of a: 5

Enter value of b: 15

Expected Output:

Maximum is b=15.


In below code we will print max out of two numbers without using if-else statement's. Here we will use switch-case to find the max number of given two numbers.




  Step by Step Logic of the program:

1. First we will accept two numbers from user which say a & b.


2. After that we will store the output of a/b in the switch. Switch (a/b)

3. If output in zero then case 0 will work means max is b.


4. Otherwise in default- a is max.




  C Program To Print Maximum Number  Between Two Numbers  Using Switch Case:


#include<stdio.h>

int main()
{
  int a,b;


printf("enter value of a\n");

scanf("%d",&a);
printf("enter value of b\n");

scanf("%d",&b);

  switch(a/b)

  {
   case 0:

   printf("max is b=%d",b);
   break;

  default:

   printf("max is a=%d",a);

}

  return 0;


}


Above Program show's the following output:



C Program To Print Maximum Number  Between Two Numbers  Using Switch Case




C Program To Reverse the String without using "strrev()" function

Ex: Write a C Program To Reverse the String without using "strrev()" function. How to write a C Program To Reverse the String without using "strrev()" function. C Program To Reverse the String without using "strrev()" function.




Program:

#include<stdio.h>
#include<string.h>
void main()
{
char a[100],b[100];
int i,j,len;

printf(" \n Please Enter Any String : ");
gets(a);

j=0;
/*Calculate length of string using strlen() function and store result in variable len*/
len=strlen(a);

//Run for loop from len-1 to 0.
for(i=len-1;i>=0;i--)
{
//store reversed string in array b.
b[j]=a[i];
    j++;
}
//Print reversed string
printf("\n String After Reversing = %s",b);

}



Above Program show's the following output:

C Program To Reverse the String without using "strrev()" function


C Program to Reverse the Given String Using String Function

Ex: Write a C program to reverse the given string  using String function. How to write a C program to reverse the given string  using String function. C program to reverse the given string  using String function.




Program:

#include <stdio.h>
#include <string.h>
void main()
{
   char s[100];
  //Accept string from user using gets() function
   printf("\n Please Enter Any String : ");
   gets(s);
 //Reverse the given string using strrev() function
   strrev(s);
//Print reversed string on the output screen
   printf("\n string After Reversing : %s\n", s);

}


Above Program show's the following  output:

C program to reverse the given string  using String function


C Program To Print Sum Of Two Numbers Without Using Arithmetic '+' Operator

Ex: Write a C Program To Print Sum Of Two Numbers Without Using Arithmetic  '+' Operator. How to write a C Program To Print Sum Of Two Numbers Without Using Arithmetic  '+' Operator. C Program To Print Sum Of Two Numbers Without Using Arithmetic  '+' Operator.

Input from user:
Enter number 1: 10
Enter number 2: 5

Expected output:
Sum = 15





Program:


#include<stdio.h>
void main()
{
int no1,no2,no3;

printf("enter no1\n");    
     scanf("%d",&no1);
     printf("enter no2\n");    
     scanf("%d",&no2);
    /*Here, we have used minus minus become plus logic*/
    no3=no1-(-no2);
   
   printf("Addition is=%d",no3);

}


Above Program show's the following output:


C program to print sum of two numbers without using arithmetic operator




C Program to Print Alternate Prime Numbers from 1 to n

Ex: Write a C program to print alternate prime numbers from 1 to n. How to write a C program to print alternate prime numbers from 1 to n. C program to print alternate prime numbers from 1 to n.

Input from user:
Enter the number: 100

Expected output:
2 5 11 17 23 31 41 47 59 67 73 83 97


  • What is prime number?
Prime number means a number that is divisible only by 1 and itself.




  Step by step logic of the given program:


1. Accept input from user declare variable say no.

2. Declare e=2.

3. Run one outer for loop from 1 to no:
for(i=1;i<=no;i++)

4. Run one inner for loop from 1 to i and inside that check condition if i%j == 0 then increment c by 1:
for(j=1;j<=i;j++)
  {
  if(i%j==0)
   {
  c++;
   }
  } 


5. After that outside the inner for loop check if c==2 (it means if given number is prime) then, inside that if-statement check one more condition if e%2==0 means if e is even number then print value of (it prints   prime numbers only if e is completely divisible by 2, in short it prints alternate prime numbers):
if(c==2)
 {
 if(e%2==0)
 { 
 printf("%d ",i);
 }

6. After that, Outside the block of inner if statement increment value of e by 1.

7. Last make c=0.





  Program to Print Alternate Prime Numbers:


#include<stdio.h>
void main()
{
 int no,i,j,c=0,e;
 printf("Enter the number:\n");
 scanf("%d",&no);
 e=2;
 printf("Alternate Prime Number's Are:\n");
 for(i=1;i<=no;i++)
  {
  for(j=1;j<=i;j++)
  {
  if(i%j==0)
   {
  c++;
   }
  } 
 if(c==2)
 {
 if(e%2==0)
 { 
 printf("%d ",i);
 }
    e=e+1;
 }
 c=0;
 }
}


Above Program show's the following output:

C program to print alternate prime numbers from 1 to n, prime numbers




C program to print following numbers series 7.5 9.5 15.5 27.5 47.5

Ex: Write a C program to print following numbers series 7.5 9.5 15.5 27.5 47.5...How to write a C program to print following numbers series 7.5 9.5 15.5 27.5 47.5.....C program to print following numbers series 7.5 9.5 15.5 27.5 47.5.


Input from user:
Enter a number: 5

Expected output:
7.5 9.5 15.5 27.5 47.5





Program:

#include<stdio.h>
void main()
{
int i,no;
float z=7.5;

printf("Enter a number:\n");
scanf("%d",&no);
//First print current value of z
printf("%f ",z);
for(i=1;i<no;i++)
{
z=(z)+i*(i+1);
printf("%f ",z);
}

}

Above Program show's the following output:
C program to print following numbers series 7.5 9.5 15.5 27.5 47.5.......







C program to devide the intiger number without using division "/" sign

Ex: Write a C program to devide the intiger number without using division "/" sign. How to write a C program to devide the intiger number without using division "/" sign. C program to devide the intiger number without using division "/" sign.

Input from user:
Enter number1: 25
Enter number2: 5

Expected output:
Division is 5




Program:

#include<stdio.h>
void main()
{
int no1,no2,c=1;

printf("enter the no1\n");
scanf("%d",&no1);
printf("enter the 2nd no\n");
scanf("%d",&no2);

while(no1>=no2)
{
no1=no1-no2;
c++;
if(no1==no2)
{
printf("division is %d",c);
}
}

}


Above program shows the following output:

C program to devide the intiger number without using division "/" sign