0% found this document useful (0 votes)
14 views8 pages

Codes For C+ Programming Language

The document contains multiple C programming examples that demonstrate basic arithmetic operations, comparisons, control structures, and loops. It includes programs for calculating sums, simple interest, checking prime numbers, and determining if a number is odd or even. Each program is structured with input prompts, calculations, and output statements.

Uploaded by

helloa59294
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views8 pages

Codes For C+ Programming Language

The document contains multiple C programming examples that demonstrate basic arithmetic operations, comparisons, control structures, and loops. It includes programs for calculating sums, simple interest, checking prime numbers, and determining if a number is odd or even. Each program is structured with input prompts, calculations, and output statements.

Uploaded by

helloa59294
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 8

1.

Write a program to enter two variables value and calculate


sum between them and display on output screen.
#include <stdio.h>

int main()
{

int x,y,z;
printf("Enter first number \n");
scanf("%d", &x);
printf("Enter second number \n");
scanf("%d", &y);
z=x+y;
printf(" Sum of two number %d",z);
return 0;
}

2. Write a program to enter two variables & calculate sum,


subtraction, multiplication & division between them .
#include <stdio.h>

int main()
{
int x,y,a,b,c,d;
printf("Enter first number");
scanf("%d/n", &x);
printf("Enter second number");
scanf("%d/n", &y);
a=x+y;
b=x-y;
c=x*y;
d=x/y;

printf(" Sum is %d",x+y);


printf(" Subtraction is %d",x-y);
printf(" Mutiplication is %d",x*y);
printf(" Division is %d",x/y);
return 0;
}
3. Write a program to enter principal, rate & time & calculate
simple interest.

#include <stdio.h>
int main()
{
float p, q, r, si;

printf("Enter principal amount: ");


scanf("%f", &p);

printf("Enter rate amount: ");


scanf("%f", &q);

printf("Enter time: ");


scanf("%f", &r);

si = (p * q * r) / 100;

printf("\nSimple interest is %f\n", si);

return 0;
}

4. Write a program to enter two variable and compare them.


Print “Maximum value” or “Minimum value” .
#include <stdio.h>

int main()
{
int x,y;
printf("enter value of x,\n");
scanf("%d",&x);
printf("enter value of y,\n");
scanf("%d",&y);
if(x>y);
{
printf("x is maximum number");
}
else
{
printf("y is minimum number");
}
return 0;
}

5. Write a program to enter average & if Average is more than


or equal to 33. Then print “Pass” otherwise “Fail”.
#include <stdio.h>

int main()
{
int m,a,b;
printf("enter marks");
scanf("%d",&m);
if(m>=33)
{
printf("a is pass");
}
else
{
printf("b is fail");
}
return 0;
}

6. Write a program of number 1 to 9 by using for loop.


#include <stdio.h>
int main()
{
int i;
for(i=1;i<10;i++){
printf("%d",i);
}
return 0;
}

7. Write a program any number is prime or not using while


looping.
#include <stdio.h>

int main() {
int num, i, isPrime = 1;

// Ask user for input


printf("Enter a number: ");
scanf("%d", &num);

// Handle numbers less than 2 (not prime)


if (num <= 1) {
isPrime = 0;
} else {
// Check divisibility from 2 to num/2
for(i = 2; i <= num / 2; i++) {
if(num % i == 0) {
isPrime = 0;
break;
}
}
}

// Output result
if(isPrime) {
printf("%d is a prime number.\n", num);
} else {
printf("%d is not a prime number.\n", num);
}

return 0;
}
8. Write a program to print any number tables.
#include <stdio.h>

int main()
{
int n,i,c=0;
printf(" enter any number:");
scanf("%d",&n);
for(i=0;i<=10;i++)
{
c=n*i;
printf("\n %d table is",c);
}
return 0;
}
9. Write a program to print a numb1 to 10.
#include <stdio.h>
int main() {
int i;
// For loop to print numbers from 1 to 20
for(i = 1; i <= 20; i++) {
printf("%d\n", i);
}
return 0;
}
10.Write a program to enter two variables & calculate the swipping value
between them.
#include <stdio.h>
int main() {
int x,y,temp=0;

printf("Enter the first number: ");


scanf("%d", & x);

printf("Enter the second number: ");


scanf("%d", & y);

temp=x;
x=y;
y=temp;

printf("\n swipping value %d , %d", x,y);


return 0;
}
11.Write a program to enter any variables values & calculate the square values
of given number.
#include <stdio.h>
int main() {
int x,y;
printf("Enter a number: ");
scanf("%d", &x);
y=x*x;
printf("The sqaure of %d is %d\n",x,y);
return 0;
}
12. Write a program to enter any variables values & calculate the cube values of
given number.
#include <stdio.h>
int main() {
int x,y;
printf("Enter a number: ");
scanf("%d", &x);
y=x*x*x;
printf("The cube of %d is %d\n",x,y);
return 0;
}
13. write a program to enter any number & check whether number is odd or
even number.
#include <stdio.h>

int main() {
int number;
printf("Enter a number: ");

scanf("%d", &number);
if (number > 0) {
printf("The number is positive.\n");
} else if (number < 0) {
printf("The number is negative.\n");
} else {
printf("The number is zero.\n");
}
return 0;
}

You might also like