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.

My Basket

You have nothing in your shopping cart yet.

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

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 ...
Write a function that is called by function main () and receives five integers
...
The average is printed
in main
...
h>
#include ...
h>
float average(int,int,int,int,int,float*);
main()
{
int a,b,c,d,e;
33 | P a g e
©Haris

float y,ave;
printf("Enter five integer\n");
scanf("%d%d%d%d%d", &a,&b,&c,&d,&e);
average(a,b,c,d,e,&ave);
printf("\nAverage is %f", ave);
getch();
}
float average(int p, int q, int r,int s,int t,float *av)
{
int sum;
sum=p+q+r+s+t;
*av=sum/5;
printf("sum is %d", sum);
}

41
...

#include ...
h>
#include ...
Write a function to raise a floating point number to an integer power
...
h>
#include ...
h>
float power(float, int);
main()
{
float a,n;
int p;
printf("Enter the number and its power\n");
scanf("%f %d", &n,&p);
a=power(n,p);
printf("%f^%d=\t%f", n,p,a);
getch();
}
float power(float z, int x)
{
float pow=1;
for(x;x>0;x--)
pow=pow*z;
return(pow);
}

43
...
Call this function from main( ) and print the results
in main( )
...
h>

35 | P a g e
©Haris

#include ...
h>
void marks(float*,float*);
main()
{
float ave,per;
printf("Enter the marks of subjects\n");
marks(&ave,&per);
printf("Average is %f\n", ave);
printf("percentage is %f", per);
getch();
}
void marks(float *av, float *pe)
{
int a,s,d;
scanf("%d%d%d", &a,&s,&d);
*av=(a+s+d)/3;
*pe=(a+s+d)*100/300;
}

44
...
by non-recursive method
#include ...
h>
#include ...
by recursion method
#include ...
h>
#include ...
Write a program to take the values of two integers and use pointers to add 10 to the value of
each integer
...
h>
#include ...
h>
int main()
{
int a,s, *p, *q, sum,pf,qf;
printf("Enter values of first and second number\n");
scanf("%d%d", &a, &s);
p = &a;
q = &s;
pf = *p + 10;
qf = *q + 10;

printf("After addition value of first number\t%d\n",pf);
printf("After addition value of second number\t%d\n",qf);
getch();
}

46
...

#include ...
h>
#include ...
The greatest common divisor of integers x and y is the largest integer that evenly divides
both x and y
...

#include ...
h>
#include ...
",num1,num2,gcd(num1,num2));
getch();
}
int gcd(int num1, int num2){
if(num2==0)
return num1;
39 | P a g e
©Haris

else return gcd(num2,num1%num2);
}

48
...

#include ...
h>
#include ...
Write a function countEven(int*, int) which receives an integer array and its size, and
returns the number of even numbers in the array
...
A factory has 3 division and stocks 4 categories of products
...
There are three independent
suppliers of products to the factory:
a
...

b
...

c
...

#include ...
h>
int main()
{
int *inven[3][4];
int comp[3];
int*c;
42 | P a g e
©Haris

char ch='y';
int t,i,j,pno,d,comp-no;
int tot=0,cost[4]={100,200,300,400,};
long int tot-in-val=0;
clscr()
for(i=0;i<=2;i++)
{
for(j=0;j<=3;j++)
{
c=(int*)malloc(sizeof(int)*3);
invent[i][j]=c;
*(invent[i][j]+0)=0;
*(invent[i][j]+1)=0;
*(invent[i][j]+2)=0;
}
}
clscr();
while(ch=='y'||ch=='Y')
{
clscr();
printf("\n Enter the division 0,1,2:")
scanf("%d",&d);
if(d,0||d>2)
{
printf("\nInvalid Division");
continue;
}
printf("\nSlect product number \n from 0,1,2 or 3 which represents its category");
scanf("%d",&pno);
if (pno<0||pno>3)
{

43 | P a g e
©Haris

printf("\n Invalid Division");
continue;
}
printf("\n Enter the company number 0,1,2\n where the product is purchased:");
scanf("%d", &compno);if(comp_no>=0&&comp_no<=2)*(invent[d][pno]+comp_no)=*(inven[d][pno]+comp_no]+1;])
}
}

51
...

#include ...
h>
main()
{
int array[10];
printf("Enter the 10 values you want to put in an array\n");
for(int i=0;i<10;i++)
scanf("%d", &array[i]);
for(int i=0;i<10;i++)
printf("%d", array[i]);
getch();
}

51
...

#include ...
h>
void func(int arr[])
{for(int i=0;i<10;i++)
printf(" %d", arr[i]);}
main()
{
int array[10];

44 | P a g e
©Haris

printf("Enter the 10 values you want to put in an array\n");
for(int i=0;i<10;i++)
scanf("%d", &array[i]);
func(array);
getch();
}

51
...

#include ...
h>
void func(int arr[])
{int sum=0;
for(int i=0;i<10;i++)
{sum=sum+arr[i];}
float ave;
ave=sum*0
...
Write a program which takes 10 number as input in an array and then prints smallest and
largest number in the array
...
h>
#include ...
Write a program that solves the quadratic equation
...
The program should
implement following three functions:
1
...

3
...
h>
#include ...
h>
#include ...
your values of a, b and c are invalid\n");
}

47 | P a g e
©Haris

void repeat()
{
char lp;
printf("\nif u want to solve another equation('y' for yes)");
scanf("%c", &lp);
lp=getch();
if (lp=='y') main();
else;
printf("\npress enter one more time to exit");
}

54
...
Write a program to determine how many of
them are positive, negative, even and odd
...
h>
#include ...
Write a program that reads any number (ask user) of integers from a user, and then prints
total number of even, and odd integers entered
...

#include ...
h>
main()
{
printf("Some instructions:\n");
printf("It read also '0' as even including those divisible by 2 and ");
printf("1 as odd number and it will not count starting zeros of a number");
printf("\nmeans for'0090' it will count only one zero");
int a, e=0, o=0, z=0, k;
printf("\nEnter the number\t");
scanf("%d", &a);
for(;a!=0;)
{
k=a%10;
a/=10;
if(k%2==0&&k!=1)
e++;
if(k%2==1||k==1)
o++;
if(k==0)
z++;
}
printf("\n\n3Total number of even integers are %d",e);
printf("\nTotal number of odd are integers %d",o);
printf("\nTotal number of zeros are integers %d",z);
getch();
}
49 | P a g e
©Haris

56
...
Write a program to search a specific value in
the array
...

#include ...
h>
main()
{
int array[10];
printf("Enter the 10 values you want to put in an array\n");
for(int i=0;i<10;i++)
scanf("%d", &array[i]);
int num;
printf("Enter the number to search in array\n");
scanf("%d", &num);
int check;
for(int i=0;i<10;i++){if(num==array[i]){check=1;break;} else check=0;}
if (check==1){for(int i=0;i<10;i++){array[i]=array[i]+num;}}
printf("Array is");
for(int i=0;i<10;i++)printf(" %d",array[i]);
getch();
}

57
...
Place the forty responses in an integer array
and summarize the results of the poll
...
h>
#include ...
Write a program which performs the following tasks:





initialize an integer array of 10 elements in main( )
pass the entire array to a function modify( )
in modify( ) multiply each element of array by 3
return the control to main( ) and print the new array elements in main( )

#include ...
h>
void modify(int arr[])
{
for(int i=0;i<10;i++)
{arr[i]=arr[i]*3;}
}
main()
{
int array[10]={1,2,32,3,43,2,1,4,5,6};
modify(array);
for(int i=0;i<10;i++)
printf(" %d", array[i]);
getch();
}

51 | P a g e
©Haris

59
...

#include ...
h>
main()
{
int array[10],b[10],i,j;
printf("\nEnter Elements of array");
for(i=0;i<10;i++)
{
scanf("%d",&array[i]);
}
for(i=0,j=9;i<10;i++,j--)
{
b[i]=array[j];
}
printf("\nArray after Copying in Reverse Order ");
for(i=0;i<10;i++)
{
printf("%d ",b[i]);
}
getch();
}

60
...

#include ...
h>
#include ...
Write a program that search a string from multidimensional array of characters
...
h>
#include ...
h>
#include ...
Write your own string compare function that compares the two string and return 1 if they
are equal else 0
...
h>
#include ...
h>
main()
{
char a[100], b[100];
printf("Enter the first string\n");
gets(a);
printf("Enter the second string\n");
gets(b);
if( strcmp(a,b) == 0 )
printf("Entered strings are equal
...
\n");
getch();
}

54 | P a g e
©Haris

63
...
For example, in the sentence “Pleases read this application and give me
gratuity” such occurrences are ea, ea, ui
...
h>
#include ...
h>
main()
{
char sent[100];
gets(sent);
int i,c=0;
for(i=0;sent[i]!='\0';i++)
{
if((sent[i]==97||sent[i]==101||sent[i]==111||sent[i]==105||sent[i]==117)&&(sent[i+1]==97||sent[i+1]==1
01||sent[i+1]==105||sent[i+1]==111||sent[i+1]==117))
c++;
}
printf("\nThere are %d occurences of two vowels in succession",c);
getch();
}

64
...

For example, if the input is Grim return to the planet of apes!! the output should be
Grim return to the planet of apes!!
...
h>
#include ...
h>
main()
{
char sent[100];
int i;
gets(sent);
for(i=0;sent[i]!=0;i++)
55 | P a g e
©Haris

{
if(sent[i]==32&&sent[i+1]==32)
{
for(;sent[i+1]!=0;i++)
{
sent[i]=sent[i+1];
}
sent[i]='\0';
i=0;
}
}
printf("\n%s",sent);
getch();
}

65
...
Assume that the sentence is not more
than 80 characters long
...
h>
#include ...
h>
main()
{
char sent[80];
int i;
gets(sent);
for(i=0;sent[i]!=0;i++)
{
if(sent[i]==97||sent[i]==101||sent[i]==105||sent[i]==111||sent[i]==117)
{
for(;sent[i+1]!=0;i++)
sent[i]=sent[i+1];

56 | P a g e
©Haris

sent[i]='\0';
i=-1;
}
}
printf("\n%s",sent);
getch();
}

66
...

#include ...
h>
int main()
{
char ch, file_name[25];
FILE *fp;
printf("Enter the name of file you wish to see\n");
gets(file_name);
fp = fopen(file_name,"r"); // read mode
if( fp == NULL )
{
perror("Error while opening the file
...
C program to display its own Source Code
#include ...
cpp","r");
do{
c= getc(fp);
putchar(c);
}
while(c!=EOF);
fclose(fp);
return 0;
}

Pattern and shapes programs
68
...
h>
#include ...
Write a program using while loop to generate the following pattern on screen
...
h>
#include ...
Write a program that reads in the size of the side of a square and then prints a hollow
square of that size out of asterisks and blanks
...
For example, if your program reads a size of 5, it should print:

#include ...
h>
main()
{
int i;
printf("Enter the size of sides of square\t");
scanf("%d", &i);
printf("\n");
for(int n=1; n<=i;n++)
printf("*");
printf("\n");

for(int r=3;r<=i;r++)
{ printf("*");
for(int k=3; k<=i;k++)
printf(" ");
printf("*");
printf("\n"); }
for(int n=1; n<=i;n++)
printf("*");
getch();
}

60 | P a g e
©Haris

71
...
Use for
loops to generate the patterns
...

Hint: The last two patterns require that each line begin with an appropriate number of
blanks
...

#include ...
h>
main()
{
int i, j;
for(i=1;i<=10;i++)
{
for(j=1;j<=i;j++)
cout<<"*";
cout << endl;
}
getch();
}

(B)
...
h>
#include ...

#include ...
h>
main()
{
int i, j, k,z=10;
for(i=1;i<=10;i++)
{
for(j=2;j<=i;j++)
cout<<" ";
for(k=1;k<=z;k++)
cout<<"*";
z--;
cout << endl;
}
getch();
}

(D)
...
h>
#include ...
com

63 | P a g e
©Haris


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