0% found this document useful (0 votes)
3 views21 pages

Coder Abhay Pratap Singh

The document contains a series of C programs that demonstrate various programming concepts such as basic arithmetic operations, salary calculations, quadratic equations, natural number summation, Fibonacci series, factorial computation, multiplication tables, Armstrong number checks, palindrome checks, prime number verification, and pyramid printing patterns. Each program includes its objective, code, and sample output. The programs are designed for educational purposes to illustrate fundamental programming techniques in C.

Uploaded by

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

Coder Abhay Pratap Singh

The document contains a series of C programs that demonstrate various programming concepts such as basic arithmetic operations, salary calculations, quadratic equations, natural number summation, Fibonacci series, factorial computation, multiplication tables, Armstrong number checks, palindrome checks, prime number verification, and pyramid printing patterns. Each program includes its objective, code, and sample output. The programs are designed for educational purposes to illustrate fundamental programming techniques in C.

Uploaded by

abhaysingh999444
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Program-11

Object:- Write a C program to create a simple Calculator


performs Addition , Subtraction ,Multiplication or
Division by using Switch.
Program :-
#include<stdio.h>
void main()
{
int a,b,c;
char ch;
printf("Enter the Vale of A :,");
scanf("%d",&a);
printf("Enter the Operator (+,-,*,/) : ");
scanf(" %c",&ch);
printf("Enter the Value of B : ");
scanf("%d",&b);
switch (ch)
{
case ' + ' : c=a+b;
printf(" Addition is :%d",c);
break;
case ' - ' : c=a-b;
printf(" Subtraction is :%d",c);
break;
case ' * ': c=a*b;
printf(" Multiplication is : %d",c);
break;
case ' / ' : c=a/b;
printf(" Division is : %d",c);
break;
default:
printf("Invalid Operator!");
}
} 14
Output:- Enter the Value of A :2
Enter the Operator (+,-,*,/) :*
Enter the Value of B :3
Multiplication is : 6
Enter the Value of A :4
Enter the Operator (+,-,*,/) : ,
Enter the Value of B :5
Invalid operator!

15
Program-12
Object:- Basic salary of employee is input through the
[Link] DA is 25% of basic [Link] Fund is
deducted at the rate of 10% of the gross salary
(BS+DA+HRA).Write a C Program to calculate the Net
salary.

Program :-
#include<stdio.h>
void main()
{
int bs;
float gsal,hra,da,pro,tsal;
printf("Enter Your Basic Salary :");
scanf("%d",&bs);
da=bs*(25.0/100.0);
hra=bs*(15.0/100.0);
gsal=bs+da+hra;
pro=gsal*(10.0/100.0);
tsal=gsal-pro;
printf("Net Salary is : %f \n",tsal);
}
Output:-
Enter Your Basic Salary :20000
Net Salary is : 25200.000000

16
Program-13
Object:-Write a C Program find all roots of Quadratic
Equation.
Program :-
#include <stdio.h>
#include <math.h>
void main()
{
int a,b,c,r1,r2,D;
printf("Enter the value of a:");
scanf("%d",&a);
printf("Enter the value of b:");
scanf("%d",&b);
printf("Enter the value of c:");
scanf("%d",&c);
D= (b*b-4*a*c);
switch (D>0)
{
case 1:
r1=(-b + sqrt(a))/2*a;
r2=(-b - sqrt(a))/2*a;
printf("r1=%d \n r2=%d",r1,r2);
break;
case 0:
switch (D==0)
{
case 1:
r1= -b/2*a;
r2=r1;
printf("r1=%d \n r2=%d",r1,r2);
break;
case 0:
printf("roots are imaginary");
17
}
}
}

Output:-
Enter the value of a:2
Enter the value of b:5
Enter the value of c:1
r1=-3
r2=-6

18
Program-14
Object:-Write a C program to Calculate the Sum of First
n Natural Number .

Program :-

#include<stdio.h>
void main()
{
int n,s=0,i;
printf("Enter a natural number:");
scanf("%d",&n);
for (i=1;i<=n;i++)
s=s+i;
printf ("sum is = %d",s);

}
Output:-
Enter a natural number:10
sum is = 55

19
Program-15
Object:-Write a C Program to print Fibonacci Series upto
a number of terms.
Program :-
#include<stdio.h>
void main()
{
int n,i,a=-1,b=1,c;
printf("Enter a number:");
scanf("%d\t",&n);
for (i=1;i<=n;i++)
{
c=a+b;
printf ("%d",c);
a=b;
b=c;
}
}
Output:-
Enter a number: 6
0 1 1 2 3 5

20
Program-16
Object:-Write a C program to Find Factorial of a Number
Program :-
#include<stdio.h>
int main()
{
int n,fact=1;
printf("Enter the Value of n :");
scanf("%d",&n);
for (int i = n; i >=1; i--)
{
fact=fact*i;
}
printf("\nFactorial %d",fact);
}

Output:-
Enter the Value of N :5
Factorial 120

21
Program-17
Object:-Write a C program to print Multiplication Table
from 2 to 6.
Program :-
#include<Stdio.h>
void main()
{
int i,j;
for ( i = 1; i<=10; i++) {
for ( j = 2; j <= 6; j++)
{
printf("%d*%d=%d\t",j,i,i*j);
}
printf("\n");
}
}
Output:-
2*1=2 3*1=3 4*1=4 5*1=5 6*1=6
2*2=4 3*2=6 4*2=8 5*2=10 6*2=12
2*3=6 3*3=9 4*3=12 5*3=15 6*3=18
2*4=8 3*4=12 4*4=16 5*4=20 6*4=24
2*5=10 3*5=15 4*5=20 5*5=25 6*5=30
2*6=12 3*6=18 4*6=24 5*6=30 6*6=36
2*7=14 3*7=21 4*7=28 5*7=35 6*7=42
2*8=16 3*8=24 4*8=32 5*8=40 6*8=48
2*9=18 3*9=27 4*9=36 5*9=45 6*9=54
2*10=20 3*10=30 4*10=40 5*10=50 6*10=60 22
Program-18
Object:-Write a C Program to Check Armstrong Number

Program:-
#include<stdio.h>
#include<math.h>
void main()
{
int n, no, c=0 ,d, s=0;
printf("Enter the value of N :");
scanf("%d",&n);
no=n;
while (n>0) {
n=n/10;
c++;
}
n=no;
while (n>0) {
d=n%10;
s=s+pow(d,c);
n=n/10;
}
if (no==s)
printf("\n Number is Armstrong");
else
printf("Number is Not a Armstrong ");
} 23
Output:-
Enter the value of N :371
Number is Armstrong
Enter the value of N :569
Number is Not a Armstrong

24
Program-19
Object:-Write a C Program to Check Whether Number is
Pallindrome or not.

Program:-
#include<stdio.h>
void main()
{
int n , reversed=0,remainder,original;
printf("Enter the value of N :");
scanf("%d",&n);
original=n;
while (n !=0)
{
remainder =n%10;
reversed = reversed * 10 + remainder;
n=n/10;
}
if (original == reversed)
printf("%d is a Pallindrome Number",original);
else
printf("%d is not a Pallindrome Number",original);
}

Output:-
Enter the value of N :121
121 is a Pallindrome Number
Enter the value of N :567
567 is not a Pallindrome Number

25
Program-20
Object:-Write a C Program to Check Whether a Number
is Prime or not.
Program:-
# include<stdio.h>
void main()
{
int n,i,flag=0;
printf("Enter any positive integer : ");
scanf("%d",&n);
if (n==0||n==1)
flag=1;
for (int i = 2; i<=n/2 ; ++i)
{
if (n % i==0)
{
flag=1;
break;
}
}
if (flag==0)
printf("%d is a Prime Number",n);
else
printf("%d is not a Prime Number ",n);
}

Output:-
Enter any positive integer : 29
29 is a Prime Number
Enter any positive integer : 56
56 is not a Prime Number

26
Program-21
Object:- Write a program to print the entire prime no
between 1 and 300.
Program:-
#include<stdio.h >
#include<math.h>
int main()
{
int num, count, i, prime;

printf("Prime Numbers from 1 To 300 are\n");


for(num = 1; num <= 300; num++)
{
if(num == 1)
{
printf("Number 1 is not prime\n");
continue;
}
count = sqrt(num);
prime = 1;
for(i = 2; i <= count; i++)
{
if(num % i == 0)
{
prime = 0;
break;
}
}
if(prime)
{
printf("%d\t", num);
}
}
}
27
Output:-
Prime Numbers from 1 To 300 are
Number 1 is not prime
2 3 5 7 11 13 17 19 23 29
31 37 41 43 47 53 59 61 67 71
73 79 83 89 97 101 103 107 109 113
127 131 137 139 149 151 157 163 167 173
179 181 191 193 197 199 211 223 227 229
233 239 241 251 257 263 269 271 271 281
283 293

28
Program-22
Object:- Write a C Program to Reverse a Number.
Program:-
# include<stdio.h>
void main()
{
int n,rev=0,d;
printf("Enter the Value of N :");
scanf("%d",&n);
while (n>0)
{
d=n%10;
rev=rev*10+d;
n=n/10;
}
printf("Reverse is : %d ",rev);
}

Output:-
Enter the Value of N :123
Reverse is : 321
Enter the Value of N :1234
Reverse is : 4321

29
Program-23
Object:- Write a C Program to print half pyramid using *
*
**
***
****
Program:-
#include<stdio.h>
void main()
{
int n;
printf("Enter the Value Of N :");
scanf("%d",&n);
for (int i = 1; i <=n; i++)
{
for (int j = 1; j <=i; j++)
{
printf("*");
}
printf("\n");
}
}
Output:-
Enter the Value Of N :4
*
**
***
**** 30
Program-24
Object:- Write a C Program to print half pyramid using
alphabets.
A
BB
CCC
DDDD
Program:-
# include<stdio.h>
void main()
{
int n,d;
printf("Enter Value of N : ");
scanf("%d",&n);
for (int i = 1; i<=n; i++)
{
int a=1;
for (int j = 1; j<=i; j++)
{
d=a+64;
char ch=(char)d;
printf("%c",d);
a++;
}
printf("\n");
}
}

Output:-
Enter Value of N : 4
A
AB
ABC
ABCD

31
Program-25
Object:-Write a C Program to print Inverted half
pyramid using numbers.
1234
123
12
1
Program:-
# include<stdio.h>
void main()
{
int n;
printf("Enter the Value of N:");
scanf("%d",&n);
for (int i = 1; i <=n; i++)
{
for (int j = 1; j<=n+1-i; j++)
{
printf("%d",j);
}
printf("\n");
}
}

Output:-
Enter the Value of N:4
1234
123
12
1

32
Program-26
Object:- Write a C Program to print full pyramid using *
*
***
*****
*******
Program:-
# include<stdio.h>
void main()
{
int n;
printf("Enter the Value of N :");
scanf("%d",&n);
for (int i = 1; i <=n; i++)
{
for (int j = 1; j<=(n-i); j++)
{
printf(" ");
}
for (int k = 1; k <=i; k++)
{
printf("*");
}

for (int l = (i-1); l >=1; l--)


{
printf("*");
}
printf("\n");
}
}
33
Output:-
Enter the Value of N :6
*
***
*****
*******
*********
***********

34

You might also like