ad

Sunday, February 23, 2025

C Program To Print Day of Week using If else case in switch case

c program     

https://webdesigningtheory.blogspot.com/

  C Program To Print Day of Week using  switch case

Example :-


#include<stdio.h>
#include<conio.h>
void main()
{
int num;
clrscr();
printf("enter a number between 1 to 7 :-");
num=getchar ()-'0';
if (num>=1&& num<=7)
{
switch(num)
{
case 1:
printf("monday \n");
break;
case 2:
printf("tuesday \n");
break;
case 3:
printf("wednesday \n");
break;
case 4:
printf("Thursday \n");
break;
case 5:
printf("Friday \n");
break;
case 6:
printf("Saturday \n");
break;
case 7:
printf("Sunday \n");
break;}
}
else{
printf("enter number between 1 to 7");
}
getch();

}



C Program To Print Day of Week using  switch case

Explain Program

Step :1

#include <stdio.h>

 input-output use printf() & scanf() function.

Step :2

int main()

 point of the C program. All execution .

Step :4

int num;

  • Declares an integer variable num.
  • It will store the number the user enters.

Step :5

printf("enter a number between 1 to 7 :-");

  • Displays message to the user to input a number between 1 and 7.

Step :6

num = getchar() - '0';

  • getchar() reads one character from the keyboard (like '1', '2', etc.).
  • Subtracting '0' converts the character to an integer.


Step :7

if (num >= 1 && num <= 7)

  • Checks whether the entered number is between 1 and 7.
  • If true, enter the switch block.
  • If false, go to the else block and print an error message.

Step :8

switch(num)

  • A multi-way branch statement.
  • Based on the value of num, it goes to the correct case.

Step :9

case 1: printf("monday \n"); break;

case 2: printf("tuesday \n"); break;

case 3: printf("wednesday \n"); break;

case 4: printf("Thursday \n"); break;

case 5: printf("Friday \n"); break;

case 6: printf("Saturday \n"); break;

case 7: printf("Sunday \n"); break;

Step :10

else

  • Runs if the user enters something not between 1 and 7.
  • Displays the message: "enter number between 1 to 7".

Output :-

Enter a number between 1 ro 7 :-  5
Friday 

Related post :-

javascript do while loop

Project navigation bar page

php number increasing reverse pyramid


Saturday, February 22, 2025

c program to check number is even or odd use if else

                          c program

c program to check number is even or odd

Examples :-


// even or odd program if else
//if else statement statement only allows
// program to execute one block of code if a check condition
// is true than execute the block or condition is false than exite the block
// of code.

#include<stdio.h>

int main()
{
int number= 0;

printf("enter a number");
scanf("%d",&number);
if(number %2 ==0 )
{
printf("%d is even");
}
else
{
printf("%d is odd");
}

return 0;
}


 c program to check number is even or odd use if else

Explain Program

Step :1

#include <stdio.h>

 input-output use printf() & scanf() function.

Step :2

int main()

 point of the C program. All execution .

Step :3

  • printf("enter a number");
  • Prints a prompt for the user. You could add a newline ("\n") for cleanliness.

Step :4

  • scanf("%d", &number);
  • Reads an integer from the user and stores it in number. The & gives the variable’s memory address.

Step :5

if (number % 2 == 0) {

    printf("%d is even");

} else {

    printf("%d is odd");

}

Step :6

  • If (number % 2) == 0, there's no remainder, so it's even.
  • Otherwise, it's odd.

Step :7

if (number & 1)   // true if odd (LSB is 1)

else              // even (LSB is 0)

Step :8

printf("%d is even\n", number);

Add a newline to output for readability

 c program to check number is even or odd use if else

Output 

enter a number  
7 is Odd


Related post :-

c program add two integer number

left pascal star pattern in php

Friday, February 21, 2025

C Program to Check Number is prime or Not prime

                                      C Program 



 C Program to Check Number is prime or Not prime

Examples :-



#include<stdio.h>
#include<conio.h>
void main()
{
int a, i, flag=0;
printf("enter a positive integer");
scanf("%d", &a);
if(a==0||a==1)
flag=1;
for(i=2;i<=a/2;i++)
{
if(a%i==0)
{
flag =1;
break;
}
}
if (flag==0)
printf("%d is prime number ", a);
else
printf("%d is not prime number",a);
getch();
return 0;
}




C Program to Check Number is prime or Not prime

Explain Program

Step :1

#include <stdio.h>

 Standard Input Output library, which is required for functions like printf() and scanf().

Step :2

void main()

This is the main function, where program execution starts.

Step :3

int a, i, flag = 0;

 stores the number  a, b entered by the user.

Step :4

printf ("enter a positive integer");

scanf ("%d", &a);

 user to enter a number.

 scanf () reads the input and stores it in variable a.

Step :5

if (a == 0 || a == 1)

    flag=1;

0 and 1 are not prime numbers by definition.

Step :6

for (i = 2; i <= a / 2; i++)

{

    if (a % i == 0)

    {

        flag = 1;

        break;

    }

}

loop check if any number between 2 and a/2 divides a completely

Step :7

if (flag == 0)

    printf("%d is prime number ", a);

else

    printf("%d is not prime number", a);

If no divisor was found (flag is still 0), the number is prime.


Output 

 enter a positive integer 133
   133 is not prime number


Thursday, February 20, 2025

C Program to Add Two Integers number

                                        C Program 




1] C Program to Add Two Integers number 

Examples :-

#include<stdio.h>
#include<conio.h>
int  main()
{
int  V, W, sum =0 ;
printf("Enter Two number integer:");
scanf( "%d%d", &V, &W );
sum=V+W;
printf( "sum %d",sum );
getch();
return 0;
}

C Program to Add Two Integers number


Explain Program

Step :1

#include <stdio.h>

 input-output use printf() & scanf() function.

Step :2

int main()

 point of the C program. All execution .

Step :4

  1. int V, W, sum = 0;
  1. Declares three integers: V, W, and initializes sum to 0.

Step :5

  • printf("Enter Two number integer:");
  • Prompts the user.

Step :6

scanf("%d%d", &V, &W);


 two integers from keyboard input and stores them in V and W. %d matches integers and & passes the variable's address so scanf can store values there 

Step :7

sum = V + W;
Adds the twos values and assigns the result to sum

Step :8

printf("sum %d", sum);

Displays the sum. Typically, you'd write printf("sum = %d", sum); to improve readability

Step :9

  • return 0;
  • completed successfully.

1] C Program to Add Two Integers number 

Output 

 Enter Two number integer :

    5
    5
  Sum =10


Related Post :-


Friday, February 14, 2025

What is the C language

 
               What is the C language

1]    full form  c stands for computer programming  language .

  2] C language  developed and father by Dennis Ritchie at the  Bell Laboratories in 1972 .

  3] C is widely use programming language they are important for the c is low level programming       efficiency simplicity and flexibly, portability influence, system and application software embedded  system, large ecosystem, interfacing with hardware is programming language .

 4] C Is a general-purpose programming language.

 5] C is middle level programming language.

  6] Used c language developing computer software, system programming, application, games such as windows and complicated programs such oracle database, python, git, interpreter

 7] C is an imperative procedural language supporting structured programming.

 8] C language is a procedural and general-purpose programming language.

 9] C is portable assembly language. designed to ease to implementation of compiler the produce high quality code

 10] C uses t0 blocks to separate pieces of code that performing different tasks that helps easier clean code and easier to understand and easy to find  mistake of program

 11] C allows low level memory access provide simple  and clean structure.

C Program Structure 

#include<stdio.h>

#include<conio.h>

int main()

{

printf(" Hi Friend");

return 0;

}

Explain Program

Step :1

#include <stdio.h>

  • compiler to include the contents of the Standard Input Output header file (stdio.h) before actual compilation starts.
Step :2

#include <conio.h>


  •  Console Input Output header file.
Step :3

int main() { ... }


  •  main() function — this is where execution 
  •  Indicates that the function returns an integer to the operating system.
  •  returning 0 means the program executed successfully.

Step :4

printf(" Hi Friend");

  • Displays to the text Hi Friend on the output screen
  • message with a space 
Step :5

return 0;


  •  Signals that the program completed successfully.

C Program Structure 

Output :- 

Hi Friend


Related Post :-

php echo function

Creating Sample Customer order Form Using HTML

css column gap property