ad

Showing posts with label c programming. Show all posts
Showing posts with label c programming. Show all posts

Friday, March 7, 2025

Write C Program To Print Multiplication Table using For Loop

C Program 

Write  C Program  To Print  Multiplication Table  using For Loop



Write  C Program  To Print  Multiplication Table  using For Loop

Examples :-    


#include<stdio.h>

void main()
{
int n,i;

printf("Enter Any Number:");
scanf("%d",&n);
for(i=1;i<=10;i++)
printf("%d\t",i*n);

}


Explain Program

Step :1

#include<stdio.h>

Standard Input/Output header file.

Step :2

void main()

 defines the main function which is the entry point of any C program.

Step :3

int n, i;

  1. n: to store the number entered by the user.
  2. i: loop control variable for the for loop.

Step :4

printf("Enter Any Number:");

Prints a message to the screen to the user to enter a number

Step :5

scanf("%d", &n);

  • input from the user and stores it in the variable n.
  • %d is used to read an integer.
  • &n means the address of n, because scanf needs to modify the variable.

Step :6

for(i = 1; i <= 10; i++)

  1. A for loop that runs from i = 1 to i = 10.
  1. Purpose: to generate and display the multiplication table of the number n

Step :7

 printf("%d\t", i * n);

  • In each iteration, prints i * n (which is a multiplication result).
  • \t is a tab character, used to separate the numbers with space.


Write  C Program  To Print  Multiplication Table  using For Loop

 Program Output 





Related Post :-


Thursday, March 6, 2025

C Program find Sum and Average of the Three Number

                                    C Program 

C Program find Sum and Average of the Three Number

 C Program find Sum and Average of the Three Number

Examples :-    


#include<stdio.h>

void main()
{
int a,b,c,s,v;

printf("Enter First Number:");
scanf("%d",&a);
printf("Enter Second Number:");
scanf("%d",&b);
printf("Enter Third Number:");
scanf("%d",&c);
s
=a+b+c;
printf("sum of given Numbers is %d\n",s);
v
=s/3;
printf("Average of given Number is %d",v);

}


Explain Program

Step :1

#include<stdio.h>

  •  use functions like printf() and scanf().

Step :2

void main()

  • Defines the main function

Step :3

int a, b, c, s, v;

  1. a, b, c: To store the three input numbers.
  1. s: To store the sum of the numbers.
  1. v: To store the average of the numbers.

Step :4

printf ("Enter First Number");

  • Displays a message  user to enter the first number.

Step :5

scanf("%d", &a);

  1.  input to the user and stores it in variable a.
  2. %d  specifies that the inputs is an integer.
  3. & a is the address of variable a

Step :6

s = a + b + c;

  • Add the three integer and stores the result in s.

Step :7

printf ("Sum of given Number  %d\n", s);

  • Prints the calculated sum using %d 

Step :8

v =  s / 3;

Divides the sum by 3 to find the average.

Step :9

printf("Average of given Numbers is %d", v);

  • Prints the calculated average.

C Program find Sum and Average of the Three Number

 Program Output 

C Program find Sum and Average of the Three Number


Related Post :-

javascript logical operator

php program to print alphabet pattern l

Css padding property

Wednesday, March 5, 2025

C Program for Printing Alphabet Patterns

                                   C Program 

C Program for Printing Alphabet Patterns



 C Program for Printing Alphabet Patterns

Example :-


#include<stdio.h>

void main()
{
int r,c;

clrscr();
for(r=65;r<=69;r++)
{
for(c=r;c>=65;c--)
{
printf("%c",r);
}
printf("\n");
}
getch();
}


Explain Program

Step :1

#include<stdio.h>

standard input/output header file

Step :2

void main()

Declares the main function

Step :3

Variable Declarations

int r, c;

  • Two integer variables r [rows] and c [columns] are declared.

Step :4

 Outer  Loop : 

for (r = 65; r <= 69; r++)

 loop iterates from ASCII value 65 (' A ') to 69 (' E ')

So r takes values:

ASCII Char

65

A

66

B

67

C

68

D

69

E

Step :5

Inner for Loop:

 for (c = r; c >=  65; c--)

This loop prints r [ASCII character]  repeatedly, starting from c = r down to c = 65.

  • printing the same character r, multiple times.
  • The number of times is (r - 65 + 1).

Step :6

Iteration : 1 

r = 65 (' A ')

  1. Inner loop:
  2.  c = 65 → 1 time
  3. Prints: A

Step :7

Iteration 2: 

r = 66 ('B')

  • Inner loop:
  •  c = 66, 65 → 2 times
  • Prints: BB

Step :8

Iteration 3:

 r = 67 ('C')

  • Inner loop:
  •  c = 67, 66, 65 → 3 times
  • Prints: CCC

Step :9

Iteration 4:

 r = 68 (' D ')

  1. Inner loop:
  2.  c = 68, 67, 66, 65 → 4 times
  3. Prints: DDDD

C Program for Printing Alphabet Patterns

Output :-


A
BB
CCC
DDDD



Tuesday, March 4, 2025

c program to find grade of a student code example

                                      C Program 

c program  to find grade of a student code example  

Example :



#include<stdio.h>
#include<conio.h>
void main()
{
int marks;
clrscr();
printf("Enter Marks");
scanf("%d",&marks);

if((marks<100)&&(marks>70))
{
printf("Destinction");
}


else if((marks>60)&&(marks<69))
{
printf("First Class");
}
else if((marks>=50)&&(marks<59))
{
printf("Second Class");
}
else if((marks>=40)&&(marks<=49))
{
printf("Third Class");
}
else{
printf("Fail");
}
getch();
}


C program to find grade of a Student 

Explanation:-

  1. 100 To 70  :- destinction
  2. 60  To  69  :- First Class
  3. 50 To  59   :- Second Class
  4. 40 To  49   :- Third Class
  5. fail

C program to find grade of a Student 

Program Output :

Enter Marks :- 98
Destinction

Related Post :-

Project home page html and CSS

Tuesday, February 25, 2025

C Program Print Right Half Pyramid pattern

c program


C Program  Print Right Half Pyramid pattern
C Program  Print Right Half Pyramid pattern

Examples :-     


#include<stdio.h>
#include<conio.h>
int main()
{
int i,j,row;
printf("enter the number");
scanf("%d",&row);
for(i=1;i<=row;i++)
{
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
return 0;
}



C Program  Print Right Half Pyramid pattern

 Program Output 

Q.1] C Program  Print Right Half Pyramid pattern   Program Output

C Program  Print Right Half Pyramid pattern

Explain Program

Step 1 ]  

#include<conio.h>

 input/output  functions like printf() and scanf()

Step 2

int main()

 function, the entry point of your C program.

Step 3

int i, j, row;

Declares three integer variables 

i: outer loop counter (for rows) 

j: inner loop counter (for printing *) 

row: stores the number of rows entered by the user

Step 4

printf("enter the number");

 user to input the number of rows.

Step 5

scanf("%d", &row);

Takes input from the user and stores it in the row variable. 

%d is for reading an integer. 

&row means you're passing the address of the variable row to store the user input.

Step 6

for(i = 1; i <= row; i++)

This is the outer loop. 

It runs from 1 to the number entered by the user (row).

Step 7

for(j = 1; j <= i; j++)

This is the inner loop. 

For each row i, it prints i number of asterisks *.

Step 8

 printf("*");

Prints a single asterisk * without moving to the next line.

Step 9

printf("\n");

 moves the cursor to the next line.


Related Post :-

javascript assignment operators

PHP Program to print Alphabet Pattern


Monday, February 24, 2025

C Program to Check Whether a People is Eligible to Vote or Not

                     C Program  

C Program to Check Whether a People is Eligible to Vote or Not


C Program to Check Whether a People is Eligible to Vote or Not  

Example  :-

#include<stdio.h>
 #include<conio.h>
int main()
{
int age;
clrscr();
 printf("enter your age :-");
scanf("%d", &age);
if(age>=18)
{
printf("you are eligible to vote");
}
else
{
printf("you are not eligible for vote");
}
getch();
return 0;
}


C Program to Check Whether a People is Eligible to Vote or Not  

Explain Program

Step :1

      #include <stdio.h>

use input/output library for functions like printf() and scanf().

Step :2

     int main() {

  int main is use Start of the main function the execution.

Step :3

int age;

  • Declares an integer variable named age.
  •  used to store the age input by the user

Step :4

printf("enter your age :-");

  • Displays the message “enter your age :-” on the screen.
  •  user to enter their age.

Step :5

scanf("%d", &age);

  • Reads an integer input from the user.
  • %d tells scanf to expect an integer.
  • &age is the address of the variable age, where the entered value will be stored.

Step :6

if (age >= 18)

  •  user's age  greater than or equal to 18.
  • If true, it mean the person is eligible to vote.

Step :7

{

 printf("you are eligible to vote"); 

}

  • If the condition is true (age >= 18), this message is printed.

Step :8

else { 

printf("you are not eligible for vote");

 }

  • this  condition is use  false (ie. age < 18) this block run.
  • It print the message “you are not eligible for vote”


 Program Output 

enter your age :- 18 
you are eligible to vote 

Related Post :-

type of css

php syntax

c program to check number prime or not

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 :-