Search for notes by fellow students, in your own course and all over the country.
Browse our notes for titles which look like what you need, you can preview any of the notes via a sample of the contents. After you're happy these are the notes you're after simply pop them into your shopping cart.
Title: Over 70 C programs for beginners
Description: This book include more than 70 C programs helpful for beginners with a user friendly layout. If you are studying programming subject, you must have this book. There is much probability that you will get questions in test which are in this book. if you want discount or format or custom changes in document or want to order any document or want to design your professional CV/Resume to get job fast please email me at harishassan1995@gmail.com
Description: This book include more than 70 C programs helpful for beginners with a user friendly layout. If you are studying programming subject, you must have this book. There is much probability that you will get questions in test which are in this book. if you want discount or format or custom changes in document or want to order any document or want to design your professional CV/Resume to get job fast please email me at harishassan1995@gmail.com
Document Preview
Extracts from the notes are below, to see the PDF you'll receive please use the links above
Table of content
(Click on any to move to solution place)
1
...
Calculating total marks ………………………………………………………………………4
3
...
4
4
...
………5
5
...
A menu driven program for calculator using functions and pointers …………………………6
7
...
…9
8
...
10
9
...
11
10
...
11
11
...
12
12
...
12
13
...
13
14
...
14
15
...
14
16
...
15
17
...
Leap year or not?
...
Leap year or not? (Using conditional operator) ……………………………………………16
20
...
17
21
...
17
22
...
18
23
...
18
24
...
19
25
...
19
26
...
20
27
...
…20
28
...
21
29
...
Insurance fee ………………………………………………………………………………
...
Table of X upto Y ……………………………………
...
X raise to power Y …………………………………………………………………………
...
The sum of the integers 73 through 415 inclusive …………………………………………
...
Even number from 1 to n …………………………………………………
...
Input characters from the user until a blank is read …………………………………………29
36
...
29
37
...
The sum, mean, minimum, and maximum of a series of numbers
...
Pythagorean triple …
...
Function to print the sum of five integers and return the average to main ……………
...
The prime factors of the number …………………………………………………………
...
Function to raise a floating point number to an integer power ……………………………
...
Function to calculate average and percentage of marks of three subjects
...
Function of power(a, b) by recursion and non-recursive
...
Adding 10 to the value of each integer (Using Pointers)
...
Recursive Function to obtain sum of first 25 natural numbers
...
Recursive Function gcd that returns the greatest common divisor of x and y
...
Recursive Function to obtain the first 25 numbers of a Fibonacci sequence ………………40
49
...
41
50
...
……42
51
...
……44
52
...
45
53
...
46
54
...
48
55
...
49
56
...
Forty students, quality of food and poll ……………………………………………………50
58
...
51
59
...
Converting all lowercase characters in a given string to uppercase ………………………52
61
...
Function returning 1 if Strings are equal else 0
...
Counting the number of occurrences of any two vowels in succession in a line of text ……
...
Replacing two or more consecutive blanks in a string by a single blank …………………
...
Deleting all vowels from a sentence ………………………………………………………
...
Opening a file to print it contents on screen ………………………………………………
...
Display its own Source Code ………………………………………………………………58
Pattern and shapes programs
……………………………………………58
3|Page
©Haris
1
...
#include
h>
int main()
{
float area, radius, pi=3
...
Write a program to calculate total marks
...
h>
#include
Write a program to calculate total marks and percentage of three subjects
...
h>
#include
Write a program to find out power of any number
...
h>
#include
Write a program to Sum, Subtract, Multiply and Division of two numbers
...
h>
#include
Write a menu driven program for calculator using functions and pointers, which has
following options: When user selects an option, that specific function is performed
...
h>
#include
h>
void repeat();
void add(int,int);
void subtract(int,int);
void product(int,int);
void division(int,int);
void modulus(int,int);
int power(int,int);
main()
{printf("press 'a' for add, 's' for subtract, 'q' for multiplication, 'd' for division, 'm' for modulus, 'p' for
power,'e' for exit\t");
int a,b;
char c;
while(c!='e'){
printf("\n\nEnter the option:\t");scanf("%c", &c);
switch(c)
{
case 'a':
printf( "\nEnter the number\t" ) ;
scanf("%d", &a);
printf( "\nEnter the number\t" ) ;
scanf("%d", &b);
6|Page
©Haris
add (a,b);
break;
case 's':
printf( "\nEnter the first number\t" ) ;
scanf("%d", &a);
printf( "\nEnter the second number\t" ) ;
scanf("%d", &b);
subtract(a,b);
break;
case 'd':
printf( "\nEnter the numerator\t" ) ;
scanf("%d", &a);
printf( "\nEnter the denominator\t" ) ;
scanf("%d", &b);
division(a,b);
break;
case 'q':
printf( "\nEnter the number\t" ) ;
scanf("%d", &a);
printf( "\nEnter the number\t" ) ;
scanf("%d", &b);
product(a,b);
break;
case 'm':
printf( "\nEnter the first number\t" ) ;
scanf("%d", &a);
printf( "\nEnter the second number\t" ) ;
scanf("%d", &b);
modulus(a,b);
break;
case 'p':
printf( "\nEnter the number\t" ) ;
scanf("%d", &a);
printf( "\nEnter its power\t" ) ;
scanf("%d", &b);
power(a,b);
break;
case 'e':
7|Page
©Haris
break;
}}getch();}
void add(int q1,int w1)
{float y1;
y1=q1+w1;
printf("\nAddition of the numbers is\t%f", y1);}
void subtract(int q2,int w2)
{float y2;
y2=q2-w2;
printf("\nSubtraction of the numbers is\t%f", y2);}
void product(int q3,int w3)
{float y3;
y3=q3*w3;
printf("\nproduct of the numbers is\t%f", y3);}
void division(int q4,int w4)
{float y4;
y4=q4/w4;
printf("\ndivision of the numbers is\t%f", y4);}
void modulus(int q5,int w5)
{float y5;
y5=q5%w5;
printf("\nremainder of %d/%d is\t%f", q5,w5,y5);}
int power(int q6,int w6)
{int y6=1;
for(int i=1;i<=w6;i++)
{y6=y6*q6;}
printf("\n\n\t\t%d^%d is %d", q6, w6, y6);
}
8|Page
©Haris
7
...
” The “encrypt” function should encrypt the
sentence/text that is passed to it and “decrypt” should decrypt the encrypted sentence/text
passed to it
...
To decrypt: replace each character of encrypted sentence/text by the
character reached by subtracting the index of that character from it
...
” Similarly, you can subtract each character’s index
from it to decrypt it
...
h>
#include
h>
void encrypt(int ,char );
void decrypt(int ,char );
int main()
{
int a=1;
int pp;
printf("\npress 1 for encryption and 2 for decryption\t");
scanf("%d", &pp);
int i;
printf("enter the number of words\t");
scanf("%d", &i);
int n;
char k[i];
printf("Write the word:\n");
switch(pp)
{
case 1:
for(int j=0;j<=i;j++)
encrypt(j,k[i]);
break;
9|Page
©Haris
case 2:
for(int j=0;j<=i;j++)
decrypt(j,k[i]);
break;
}
main(); getch();
}
void encrypt(int j1,char k1)
{char ch;
{
scanf("%c", &ch);
k1=ch+j1-1;
printf("\t%c",k1);}}
void decrypt(int j2,char k2)
{char ch;
{
scanf("%c", &ch);
k2=ch-j2+1;
printf("\t%c",k2);
}
}
8
...
Write a
program to convert this temperature into Centigrade degrees
...
h>
#include
The length & breadth of a rectangle and radius of a circle are input through the keyboard
...
#include
h>
int main()
{
float leng, brea, rad, arearec, areacir, peri, circum;
printf("Enter the length of rectangle\t");
scanf("%f", &leng);
printf("\nEnter the breadth of rectangle\t");
scanf("%f", &brea);
printf("\nEnter the radius of circle\t");
scanf("%f", &rad);
arearec=leng*brea;
peri=2*(brea+leng);
areacir=3
...
141* rad;
printf("\n\nArea of rectangle is\t\t%f", arearec);
printf("\nPerimeter of rectangle is\t%f", peri);
printf("\nArea of circle is\t\t%f", areacir);
printf("\nCircumference of circle is\t%f", circum);
getch();
}
10
...
Write a program
to interchange the contents of C and D
...
h>
#include
Write function distance that calculates the distance between two points (x1, y1) and (x2, y2)
...
Use math library function where
required
...
h>
#include
h>
#include
The distance between two cities (in km
...
Write a program to
convert and print this distance in meters, feet, inches and centimeters
...
h>
12 | P a g e
©Haris
#include
3048;
inch=feet*12;
centi=metr*100;
printf("\n\nThe distance between two cities in meters is\t\t%f",metr);
printf("\nThe distance between two cities in feet is\t\t%f",feet);
printf("\nThe distance between two cities in inches is\t\t%f",inch);
printf("\nThe distance between two cities in centimeters is\t%f",centi);
getch();
}
13
...
In other
words if x = 5, y = 8, z = 10 after circular shift y = 5, z = 8, x =10 after circular shift y = 5, z
= 8 and x = 10
...
#include
h>
#include
Write a program that calculates the squares and cubes of the numbers from 0 to 10 and
uses tabs to print table of values:
#include
h>
main()
{
int n=10, a, squ, cub;
printf("\t\t\tNumber\tSquare\tCube\n\n");
for(a=0 ; a<=n; a++)
{
squ=a*a ;
cub=a*a*a;
printf("\t\t\t%d\t%d\t%d\n\n", a, squ, cub);
}
getch();
}
15
...
His dearness allowance is 40% of basic
salary, and house rent allowance is 20% of basic salary
...
#include
h>
main ()
{
float basic, gross, dear, rent;
printf("Enter the basic salary\t");
scanf("%f",&basic);
dear=0
...
2*basic;
14 | P a g e
©Haris
gross=basic+dear+rent;
printf("\n\nThe gross salary is\t%f",gross);
getch();
}
16
...
Write a program to find out whether it is an odd
number or even number
...
h>
#include
A five-digit number is entered through the keyboard
...
#include
h>
main()
{
int n, a, b, c, d, e, f;
printf("Enter a five digit number\t");
scanf("%d",&n);
a=n%10;
b=((n%100)-a)/10;
c=((n%1000)-b)/100;
d=((n%10000)-c)/1000;
e=((n%100000)-d)/10000;
printf("\nReversed number is\t%d%d%d%d%d", a, b, c, d, e);
15 | P a g e
©Haris
if(a==e && b==d)
printf(a==e && b==d ? "\n\noriginal and reversed numbers are equal":"\n\noriginal and reversed
numbers are not equal");
else if(a!=e && b!=d)
printf("\n\noriginal and reversed numbers are not equal");
getch();
}
18
...
Write a program to determine whether the year is
a leap year or not
...
h>
#include
Write a program using conditional operators to determine whether a year entered through
the keyboard is a leap year or not
...
h>
#include
If the ages of X, Y and Z are input through the keyboard, write a program to determine the
youngest of three
...
h>
#include
Write a program to check whether a triangle is valid or not, when the three angles of the
triangle are entered through the keyboard
...
#include
h>
main()
{
17 | P a g e
©Haris
int a, b, c;
printf("Enter first angle of triangle\t");
scanf("%d",&a);
printf("Enter second angle of triangle\t");
scanf("%d",&b);
printf("Enter third angle of triangle\t");
scanf("%d",&c);
if(a+b+c==180)
printf("\nTriangle is valid");
else
printf("\nTriangle is not valid");
getch();
}
22
...
#include
h>
main()
{
int num;
printf("Enter a number to find its absolute value\t");
scanf("%d",&num);
if(num<0)
num=(-1)*num;
printf("\nAbsolute value of number is %d", num);
getch();
}
23
...
#include
h>
main()
{
int a, b, c;
printf("Enter first number\t");
18 | P a g e
©Haris
scanf("%d",&a);
printf("Enter second number\t");
scanf("%d",&b);
printf("Enter third number\t");
scanf("%d",&c);
(a>b&&a>c?printf("Greater number is %d", a):b>a&&b>c?printf("Greater number is %d", b):printf("Greater
number is %d", c));
getch();
}
24
...
#include
h>
main( )
{
char c;
printf( "Enter the alphabet\t" ) ;
scanf("%c", &c);
if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
printf( "\n\tAlphabet you enter is vowel" ) ;
else
printf( "\n\tYou enter a consonant" ) ;
getch();
}
25
...
#include
h>
main( )
{
float area, s, a, b, c;
printf( "Enter the sides of a triangle a,b,c\n" ) ;
scanf("%f%f%f", &a,&b,&c);
s=(a+b+c)/2;
if(a+b>c&&b+c>a&&a+c>b)
19 | P a g e
©Haris
printf( "\n\tArea of triangle is\t%f", area= s*(s-a)*(s-b)*(s-c) );
else
printf("triangle is not valid");
getch();
}
26
...
#include
h>
main( )
{
int num;
printf( "Enter the number\t" ) ;
scanf("%d", &num);
if(num%2==0)
printf( "\n\tNumber you enter is even");
else
printf("\n\tNumber is odd");
getch();
}
27
...
After
displaying the message (“Even” or “Odd”), it ask the user Do you want to enter another
number (y/n)
...
(Note: use dowhile loop)
#include
h>
main( )
{
int x;
char y;
do
{
printf( "\n\nEnter the number\t" ) ;
scanf("%d", &x);
20 | P a g e
©Haris
if (x%2==0)
printf("\n\tNumber is even\n");
else
printf("\n\tNumber is odd\n");
printf("\n\nif you want to test another number?(y/n)");
scanf("%c", &y);
y=getch();
}
while(y=='y');
getch();
}
28
...
#include
h>
main( )
{
float d;
int a,b;
char c;
printf("press '+' to add two number, '-' to subtract, '/'to divide, \n'*' to multiply and 'r' for remainder
operation");
printf("\nEnter your option\t");
scanf("%c", &c);
printf( "\nEnter the number\t" ) ;
scanf("%d", &a);
printf( "\nEnter the number\t" ) ;
scanf("%d", &b);
d=a/b;
switch(c)
{
21 | P a g e
©Haris
case '+':
printf("\nAddition of the numbers is\t%d", a+b);
break;
case '-':
printf("\nSubtraction of the numbers is\t%d", a-b);
break;
case '/':
printf("\ndivision of the numbers is\t%f", d);
break;
case '*':
printf("\nproduct of the numbers is\t%d", a*b);
break;
case 'r':
printf("\nremainder of %d/%d is\t%d", a, b, a%b);
break;
}
getch();
}
29
...
The student gets a division as per the following rules:
1
...
Percentage between 50 and 59 - Second division
3
...
Percentage less than 40 – Fail
Write a program to calculate the division obtained by the student
...
h>
#include
Write a program that prints the insurance fee to pay for a pet according to the following
rules:
A dog that has been neutered costs $40
...
A cat that has been neutered costs $450
...
A bird or reptile costs nothing
...
The program should prompt the user for the appropriate information, using a code to
determine the kind of animal (i
...
D or d represents a dog, C or c represents a cat, B or b
represents a bird, R or r represents a reptile, and anything else represents some other kind of
animal)
...
Implement the code with switch statement
...
h>
#include
");
break;
case 'n':
printf("\n\n\tYour insurance fee is $50
...
");
break;
case 'n':
printf("\n\n\tYour insurance fee is $65
...
");
break;
case 'r':
printf("\n\n\tYour insurance fee is $0
...
Write a program that input two integers x and y from the user
...
g
...
2x1=2
2x2=4
2x3=6
#include
h>
main( )
{
int x, y, z;
26 | P a g e
©Haris
printf( "Enter the number\t" ) ;
scanf("%d", &x);
printf( "\nEnter the next number\t" ) ;
scanf("%d", &y);
for(z=1;z<=y;z++)
{
printf("\n\t\t%d x %d = %d\n", x,z,x*z);
}
getch();
}
32
...
It calculates and then
displays the x raise to power y (xy)
...
h>
#include
Write a C program using for loop to find the sum of the integers 73 through 415 inclusive
...
h>
#include
Write a program that input one integer n from the user
...
#include
h>
main()
{
int n,i;
printf("Enter the number\t");
scanf("%d", &n);
if(n%2==0)
for(i=2;i<=n;i+=2)
{
printf("\t\t%d\n", i);
}
else
for(i=2;i
28 | P a g e
©Haris
printf("\t\t%d\n", i);
}
getche();
}
35
...
Use a for loop to
find the number of nonblank characters read from the keyboard
...
h>
#include
Write a program for a matchstick game being played between the computer and a user
...
Rules for the game are as
follows:
−
−
−
−
There are 21 matchsticks
...
Whoever is forced to pick up the last matchstick loses the game
After the person picks, the computer does its picking
...
h>
#include
There are 21 matchsticks
...
you will be asked pick 1 to 4 match sticks
...
Only pick 1 to 4 sticks otherwise you will lose game
...
Whoever is forced to pick up the last matchstick loses the game
...
After you picks, the computer does its picking
...
Write a program that reads a non-negative integer and prints its factorial
...
(e
...
5! = 5*(5-1)*(5-2)*(5-3)*(5-4)
which equals 5*4*3*2*1=120)
...
#include
h>
30 | P a g e
©Haris
main()
{
int a,s=1;
printf("Enter a non negative integer to find its factorial\t");
scanf("%d", &a);
if(a==0||a==1)
printf("\nThe factorial is 1");
else if(a<0)
printf("\nError");
else if(a>=1)
{
while(a>=1)
{ s=s*a;
a--;
}printf("\nFactorial is\t%d", s);
}
getch();
}
38
...
#include
h>
main()
{
int a,count=1,i=1;
float g,h,d,f,s=0,m;
printf("Enter the numbers of numbers in series\t");
scanf("%d", &a);
if(a==1)
{
31 | P a g e
©Haris
printf("Enter number\t");
scanf("%f", &d);
printf("\nThe sum of series is\t%f", d);
printf("\nMean of series is\t%f", d);
printf("\nThe maximum number is\t%f", d);
printf("\nThe minimum number is\t%f", d);
}
else
{
printf("\nEnter 1st numbers in series\t");
scanf("%f", &d);
while(i{printf("Enter the other numbers in series\t");
scanf("%f", &f);
if(f>d)
{g=f;}
if(f>d)
{h=d;}
s=s+f;
count++;
i++;
}
s=s+d;
m=s/count;
printf("\nThe sum of series is\t%f", s);
printf("\nMean of series is\t%f", m);
printf("\nThe maximum number is\t%f", g);
printf("\nThe minimum number is\t%f", h);}
getch();
}
32 | P a g e
©Haris
39
...
The set of three integer values
for the lengths of the sides of a right triangle is called a Pythagorean triple
...
Write an application that displays a table of the
Pythagorean triples for side1, side2 and the hypotenuse, all no larger than 500
...
This method is an example of “brute-force”
computing
...
#include
h>
#include