0% found this document useful (0 votes)
9 views

Program

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views

Program

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 41

PROGRAM-1

Q1. Write a C program to print Hello World.


# include <stdio.h>

int main() {

printf ("HELLO WORLD");

return 0;

TANISHQ SURIYAL
PROGRAM-2

Q2. Write a C program to print addition of 2 number.


#include <stdio.h>

int main() {

int no1,no2,sum;

printf ("enter two number");

scanf("%d%d",&no1,&no2);

sum=no1+no2;

printf("sum is : %d",no1+no2);

return 0;

TANISHQ SURIYAL
PROGRAM-3
Q3. Write a program to print multiplication of two number
#include <stdio.h>

int main() {

int no1,no2,PRODUCT;

printf ("enter two number");

scanf("%d%d",&no1,&no2);

PRODUCT=no1*no2;

printf("sum is : %d",no1*no2);

return 0;

TANISHQ SURIYAL
PROGRAM-4
Q4.Determine The Number is positive ,Negative,Zero
#include <stdio.h>

int main() {

int n;

printf("enter number");

scanf("%d",&n);

if (n>0){

printf("it is positive");

else if (n<0){

printf ("it is negative");

else

printf("neither positive or negative it is zero");

return 0;

TANISHQ SURIYAL
PROGRAM-5
Q5.Determine The number is Even or odd

#include <stdio.h>

int main() {

int n;

printf("enter number");

scanf("%d",&n);

if (n%2==0){

printf("it is even number");

else

printf("it is odd number");

return 0;

TANISHQ SURIYAL
PROGRAM -6
Q6.Determine a maximum of two number
#include <stdio.h>

int main() {

int no1,no2;

printf("enter number");

scanf("%d%d",&no1,&no2);

if (no1>no2) {

printf ("no1 is maximum");

else

printf("no2 is maximum");

return 0;

TANISHQ SURIYAL
PROGRAM-7
Q7.Write The Series From 1-10

#include <stdio.h>

int main() {

int i;

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

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

return 0;

TANISHQ SURIYAL
PROGRAM-8
Q8.Write The Series From 10-1

#include <stdio.h>

int main() {

int i;

for (int i=10; i>=1; i--) {

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

return 0;

TANISHQ SURIYAL
PROGRAM-9
Q9. Determine the sum of first n natural number
#include <stdio.h>

int main() {

int n,sum;

printf("enter number");

scanf("%d",&n);

for(int i=1; i<=n; i++) {

sum=sum+i;

printf("sum is: %d",sum);

return 0;

TANISHQ SURIYAL
PROGRAM-10
Q10. Print the multiplication table for any number
#include <stdio.h>

int main() {

int n;

printf("enter number");

scanf("%d",&n);

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

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

return 0;

TANISHQ SURIYAL
PROGRAM-11
Q11.Sum of digits of a number
#include<stdio.h>

int main()

int n,sum=0,m;

printf("Enter a number:");

scanf("%d",&n);

while(n>0)

m=n%10;

sum=sum+m;

n=n/10;

printf("Sum is=%d",sum);

return 0;

TANISHQ SURIYAL
PROGRAM-12
Q12. Reverse of digits of a number
#include<stdio.h>

int main()

int n, reverse=0, rem;

printf("Enter a number: ");

scanf("%d", &n);

while(n!=0)

rem=n%10;

reverse=reverse*10+rem;

n/=10;

printf("Reversed Number: %d",reverse);

return 0;

TANISHQ SURIYAL
PROGRAM-13
Q13.Count the digit of a number
#include <stdio.h>

int main()

int n; // variable declaration

int count=0; // variable declaration

printf("Enter a number");

scanf("%d",&n);

while(n!=0)

n=n/10;

count++;

printf("\nThe number of digits in an integer is : %d",count);

return 0;

TANISHQ SURIYAL
PROGRAM-14
Q14. Determine the factorial of a given number
#include <stdio.h>

int main()

int n,fact=1;

printf("enter a number");

scanf("%d",&n);

for(int i=1; i<=n; i++) {

fact=fact*i;

printf("factorial is : %d",fact);

return 0;

TANISHQ SURIYAL
PROGRAM 15
Q15.Print Fibonacci series up to n
#include<stdio.h>

int main()

int n1=0,n2=1,n3,i,number;

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)

n3=n1+n2;

printf(" %d\n",n3);

n1=n2;

n2=n3;

return 0;

TANISHQ SURIYAL
TANISHQ SURIYAL
PROGRAM -16
Q16.Program to find out wheather a given number is PRME or NOT
#include <stdio.h>

int main() {

int num;

printf ("enter number");

scanf("%d",&num);

int a=0;

for (int i=2; i<=num-1;i++){

if(num%i==0){

a=1;

break;}

if (a==0){

printf("prime number");

else{

printf("not a prime number");

return 0;

TANISHQ SURIYAL
PROGRAM-17
Q17.Program to find out wheather the given number is PERFECT or NOT

#include<stdio.h>

int main(){

int number,i,result=0;//declare variables and initialize result to 0

printf("enter the number:");

scanf("%d",&number);

for(i=1;i<=number;i++){

if(number%i==0)

result=result+i;

if(result==2*number) //checking the sum of factors==2*number

printf("perfect number");

else

printf("not perfect number");

TANISHQ SURIYAL
PROGRAM-18
Q18Program to find out wheather a given number is PALINDROME or NOT

#include<stdio.h>

int main()

int n,r,sum=0,temp;

printf("enter the number=");

scanf("%d",&n);

temp=n;

while(n>0)

r=n%10;

sum=(sum*10)+r;

n=n/10;

if(temp==sum)

printf("palindrome number ");

else

printf("not palindrome");

return 0;

TANISHQ SURIYAL
PROGRAM-19
Q19.Program to find out wheather the given number is ARMSTRONG or NOT

#include<stdio.h>

int main()

int n,b,t,k,s=0;

printf("enter number");

scanf("%d",&n);

k=n;

while(n>0) {

b=n%10;

t=b*b*b;

s=s+t;

n=n/10; }

if (s==k){

printf("armstrong number");

else{

printf("not armstrong number");

return 0;

TANISHQ SURIYAL
PROGRAM-20
Q20.Program to find out wheather a given number is STRONG or NOT
#include <stdio.h>

int main() {

int n;

int sum=0;

printf("Enter a number");

scanf("%d",&n);

int k=n;

int r;

while(k!=0) {

r=k%10;

int f=fact(r);

k=k/10;

sum=sum+f; }

if(sum==n) {

printf("\nNumber is a strong"); }

else {

printf("\nNumber is not a strong"); }

return 0; }

int fact(int r) {

int mul=1;

for(int i=1;i<=r;i++) {

mul=mul*i; }

return mul;

TANISHQ SURIYAL
TANISHQ SURIYAL
PROGRAM-21
Q21.Swapping of two number using three variable
#include <stdio.h>

int main()

int var1, var2, temp;

printf("Enter two integers \n");

scanf("%d%d", &var1, &var2);

printf("Before Swappingn First variable = %d\nSecond variable = %d \n", var1, var2);

temp = var1;

var1 = var2;

var2 = temp;

printf("After Swappingn First variable = %d\nSecond variable = %d\n", var1, var2);

return 0;

TANISHQ SURIYAL
PROGRAM-22
Q22.Swapping of two number withput using three variable
#include <stdio.h>

int main()

int var1, var2, temp;

printf("Enter two integers\n");

scanf("%d%d", &var1, &var2);

printf("Before Swapping\nFirst variable = %d\nSecond variable = %d\n", var1, var2);

var1 = var1 + var2;

var2 = var1 - var2;

var1 = var1 - var2;

printf("After Swapping\nFirst variable = %d\nSecond variable = %d\n", var1, var2);

return 0;

TANISHQ SURIYAL
PROGRAM-23
Q23.Program to evaluate sine series
#include <stdio.h>

#include <math.h>

int fac(int x) {

int i, fac = 1;

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

fac = fac * i;

return fac;

int main() {

float x, Q, sum = 0;

int i, j, limit;

printf("Enter the value of x of sinx series: ");

scanf("%f", & x);

printf("Enter the limit upto which you want to expand the series: ");

scanf("%d", & limit);

Q = x;

x = x * (3.1415 / 180);

for (i = 1, j = 1; i <= limit; i++, j = j + 2) {

if (i % 2 != 0) {

sum = sum + pow(x, j) / fac(j);

} else

sum = sum - pow(x, j) / fac(j);

printf("Sin(%0.1f): %f", Q, sum);

return 0;

TANISHQ SURIYAL
TANISHQ SURIYAL
PROGRAM -24
Q24. Program to calculate cosine series
#include <stdio.h>

#include <math.h>

void main() {

int n, x1, i, j;

float x, sign, cosx, fact;

printf("Enter the number of the terms in a series\n");

scanf("%d", &n);

printf("Enter the value of x(in degrees)\n");

scanf("%f", &x);

x1 = x;

/* Degrees to radians */

x = x * (3.142 / 180.0);

cosx = 1;

sign = -1;

for (i = 2; i <= n; i = i + 2)

fact = 1;

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

fact = fact * j;

cosx = cosx + (pow(x, i) / fact) * sign;

sign = sign * (-1);

printf("Sum of the cosine series = %7.2f\n", cosx);

printf("The value of cos(%d) using library function = %f\n", x1,

cos(x));

TANISHQ SURIYAL
TANISHQ SURIYAL
PROGRAM-25
Q25. PROGRAM to print PASCAL triangle
a)1
22
333
#include <stdio.h>

int main() {

int i,j;

for(i=1;i<=3;i++){

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

printf("%d",i);

printf("\n");

return 0;

TANISHQ SURIYAL
PROGRAM-26
Q25)b 1
23
456

#include <stdio.h>

int main() {

int i,j,k=1;

for(i=1;i<=3;i++){

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

printf("%d",k);

k++;

printf("\n");

return 0;

TANISHQ SURIYAL
PROGRAM-27
Q25)c 1
2 2
3 3 3

# include <stdio.h>

int main() {

int rows=3;

for(int i=1;i<=rows;i++) {

for(int j=1;j<=rows-i;j++){

printf("");

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

printf("%d",i);

printf("\n");

return 0;

TANISHQ SURIYAL
PROGRAM-29
Q26. Program to find nCR and nPR

#include <stdio.h>

long factorial(int);

long find_ncr(int, int);

long find_npr(int, int);

int main() {

int n, r;

long ncr, npr;

printf("Enter the value of n and r\n");

scanf("%d%d",&n,&r);

ncr = find_ncr(n, r);

npr = find_npr(n, r);

printf("%dC%d = %ld\n", n, r, ncr);

printf("%dP%d = %ld\n", n, r, npr);

return 0; }

long find_ncr(int n, int r) {

long result;

result = factorial(n)/(factorial(r)*factorial(n-r));

return result; }

long find_npr(int n, int r) {

long result;

result = factorial(n)/factorial(n-r);

return result; }

long factorial(int n) {

int c;

long result = 1;

for (c = 1; c <= n; c++)

result = result*c;

TANISHQ SURIYAL
return result; }

TANISHQ SURIYAL
PROGRAM -30
Q27.Find the area and circumference of circle

#include <stdio.h>

#define PI 3.14159

int main() {

double radius, area, circumference;

printf("Enter the radius of the circle: ");

scanf("%lf", &radius);

area = PI * radius * radius;

circumference = 2 * PI * radius;

printf("Area of the circle: %.2lf\n", area);

printf("Circumference of the circle: %.2lf\n", circumference);

return 0;

TANISHQ SURIYAL
PROGRAM-31
Q28.Find the area and parameter of rectangle
#include <stdio.h>

void main() {

/* Variable Declaration. */

float lnth, wdth, perimeter, area;

/* Taking input of the length of the rectangle from the user */

printf("Enter the length of the Rectangle:\n");

scanf("%f", & lnth);

/* Taking input of the width of the rectangle from the user */

printf("Enter the width of the Rectangle:\n");

scanf("%f", & wdth);

/* Calculate perimeter of the rectangle */

perimeter = 2 * (lnth + wdth);

printf("Perimeter of the Rectangle: %0.4f\n", perimeter);

/* Calculate area of the rectangle */

area = lnth * wdth;

printf("Area of the Rectangle: %0.4f\n", area);

TANISHQ SURIYAL
PROGRAM-32
Q29.To perform the arithmetic operations using a switch statement

#include<stdio.h>

int main() {

int a,b;

int op;

printf(" 1.Addition\n 2.Subtraction\n 3.Multiplication\n 4.Division\n");

printf("Enter the values of a & b: ");

scanf("%d %d",&a,&b);

printf("Enter your Choice : ");

scanf("%d",&op);

switch(op) {

case 1 :

printf("Sum of %d and %d is : %d",a,b,a+b);

break;

case 2 :

printf("Difference of %d and %d is : %d",a,b,a-b);

break;

case 3 :

printf("Multiplication of %d and %d is : %d",a,b,a*b);

break;

case 4 :

printf("Division of Two Numbers is %d : ",a/b);

break;

default :

printf(" Enter Your Correct Choice.");

break; }

return 0;

TANISHQ SURIYAL
do {

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

i--;

while (i>=35);

return 0;

TANISHQ SURIYAL
PROGRAM -34
Q31.Write a program to find the factorial of a num using a function
# include <stdio.h>

int fact (int n);

int main () {

int n,r;

printf("enter no=");

scanf("%d",&n);

r=fact (n);

TANISHQ SURIYAL
printf("%d",r);

int fact (int n)

int f;

if (n==1)

return 1;

else {

f=n*fact(n-1);

return (f);

return 0;

PROGRAM- 35
Q32. Multiplication of two numbers using function with aruguments

#include <stdio.h>

int multiply(int a,int b);

TANISHQ SURIYAL
void main() {

int a,b;

printf("enter two number=");

scanf("%d%d",&a,&b);

int mul=multiply(a,b);

printf("%d",mul);

int multiply(int a,int b){

return a*b;

TANISHQ SURIYAL
TANISHQ SURIYAL

You might also like