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

ARRAY IN C

The document contains multiple examples of C programming code demonstrating various operations such as arithmetic calculations, temperature conversions, interest calculations, and conditional statements. Each example includes code snippets for tasks like calculating sums, areas, percentages, and checking voting eligibility. The document serves as a tutorial for beginners to understand basic programming concepts in C.

Uploaded by

anushya.course
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)
17 views

ARRAY IN C

The document contains multiple examples of C programming code demonstrating various operations such as arithmetic calculations, temperature conversions, interest calculations, and conditional statements. Each example includes code snippets for tasks like calculating sums, areas, percentages, and checking voting eligibility. The document serves as a tutorial for beginners to understand basic programming concepts in C.

Uploaded by

anushya.course
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/ 72

Printf and scanf

Example 1

Write a program to calcultate the sum two integer number

#include<stdio.h>

#include<conio.h>

main()

int a,b,t;

clrscr();

printf("enter the vaue of a,b");

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

t=a+b;

printf("addition of two number=%d",t);

Example 2

Write a program to calcultate the sub two integer number

#include<stdio.h>

#include<conio.h>

main()

int a,b,sub;

clrscr();

printf("enter the vaue of a,b");


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

sub=a-b;

printf("subtaction of two number=%d",sub);

Example 3

Write a program to calcultate the multiple two integer number

#include<stdio.h>

#include<conio.h>

main()

int a,b,mul;

clrscr();

printf("enter the vaue of a,b");

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

mul=a+b;

printf("multiple of two number=%d",mul);

Example 4

Write a program to calcultate the sum four integer number

#include<stdio.h>

#include<conio.h>

main()

{
int a,b,c,d,t;

clrscr();

printf("enter the vaue of a,b,c,d");

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

t=a+b+c+d;

printf("addition of four number=%d",t);

Example 5:-

write a program to calculate the area of reactangle

#include<stdio.h>

#include<conio.h>

main()

int l,b,area;

printf("enter the values of length and width=");

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

area=l+b;

printf("Area of a rectangle=%d",area);

getch();

Example 6:-

write a program to calculate the area of square

#include<stdio.h>

#include<conio.h>

main()
{

int l,b,area;

printf("enter the values of length and width=");

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

area=l*b;

printf("Area of a square=%d",area);

getch();

Example 7:-

Write a c program to calculate the percentage of marks

#include<stdio.h>

#include<conio.h>

main()

int a,os,cit,pc,ee,fed;

float to,per;

clrscr();

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

printf("\n enter the marks of 5 subjects=");

scanf("%d%d%d%d%d",&os,&cit,&pc,&ee,&fed);

to=os+cit+pc+ee+fed;

per=to/5;

printf("\n total of 5 subjects=%f",to);

printf("\n percentage of 5 subjects=%f",per);


}

Example

Relationship between celsius and fahrenhiet is governerd by the fprmula

F=9c/5+32

Write a program to convert the temprature

a) from celsius to fahrenhiet

b)from fahrenhiet to celsius

(A)

#include<stdio.h>

#include<conio.h>

Void main()

Float c,f;

Clrscr();

Printf(“enter the temprature in cel”);

Scanf(“%f”,&c);

F=1.8*c+32;

Printf(“%f”,f);

Getch();

(B)

(A)

#include<stdio.h>

#include<conio.h>
Void main()

Float c,f;

Clrscr();

Printf(“enter the temprature in fah”);

Scanf(“%f”,&f);

c=.5556*(f-32);

Printf(“%f”,c);

Getch();

Example

Write a program in c to find simple interest for give principal, rate and no of years.

I=prt/100

#include<stdio.h>

#include<conio.h>

Void main()

Int p,r,t,I;

Clrscr();

Printf(“enter the value of prt”);

Scanf(“%d%d%d”,&p,&r,&t);

I=p*r*t/100;

Printf(“%d”,i);

Getch();

}
Example 8

Write a program to read the value of x and y and print the result of the following expression in line.

(a) x+y/x-y
(b) x+y/2
(c) (x+y)(x-y)

#include<stdio.h>

#include<conio.h<

void main()

int x,y,z;

clrscr();

printf(“\n enter any two address”);

scanf(“%d%d”,&x,&y);

z=x+y;

t=x-y;

s=z/t;

printf(“%d”,s);

getch();

Example 9

Write a program inter change into number without using third variable.

#include<stdio.h>

#include<conio.h>

void main()

int a,b;
clrscr();

printf(“enter any two number”);

scanf(“%a%b”,&a,&a);

a=a+b;

b=a-b;

a=a-b;

printf(“a=%d”,a);

printf(“b=%d”,b);

getch();

(b) Using third variable

#include<stdio.h>

#include<conio.h>

void main()

int a,b;

clrscr();

printf(“enter any two number”);

scanf(“%a%b”,&a,&a);

c=a;

a=b;

b=c;

printf(“a=%d”,a);

printf(“b=%d”,b);

getch();
}

Example 10

Write a program to read a four digits and print the sum of the first and last digit.

#include<stdio.h>

#include<conio.h>

void main()

int n,l,f,sum;

clrscr();

printf(“enter any four digits”);

scanf(“%d”,&n);

l=n%10;

f=n/1000;

sum=l+f;

printf(“%d”,sum);

getch();

Example 11

Write a program to read a four digits and print the sum of the four digits.

#include<stdio.h>

#include<conio.h>

void main()

int n,l,t,k,k1,sum;
clrscr();

printf(“\n enter any four digits”);

scanf(“%d”,&n);

l=n%10;

k=n/10;

t=k%10;

k1=k/10;

s=k1%10;

f=k1/10;

sum=l+k+t+k1+s+f;

printf(“/n%d”,sum);

getch();

If statement
example

c program to check voting eligibility

#include<stdio.h>

#include<conio.h>

main()

char name;

int age;

clrscr();

printf("Enter the name of person=");


scanf("%s",&name);

printf("Enter the age of person=");

scanf("%d",&age);

if(age>18)

printf("You can vote%s",name);

else

printf("You can not vote%s",name);

Example

Write a program to find the sum of four digits number.

#include<stdio.h>

#include<conio.h>

void main()

int f,l,s,t,x,y,h,d,n,sum;

clrscr();

printf ("enter any four digit no/n");

scanf("%d",&n);

f=n/1000;

l=n%10;

x=n/100;

s=x%10;
y=n/10;

t=y%10;

sum=f+l+s+t;

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

getch();

Example

Write a program to find the sum and their reverse of four digits number.

#include<stdio.h>

#include<conio.h>

void main()

int f,l,s,t,x,y,h,d,n,sum,reverse;

clrscr();

printf ("enter any four digit no/n");

scanf("%d",&n);

f=n/1000;

l=n%10;

x=n/100;

s=x%10;

y=n/10;

t=y%10;

sum=f+l+s+t;

h=l*10+t;
d=h*10+s;

reverse=d*10+f;

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

printf("%d",reverse);

getch();

Example

Write a program to find the sum of first and last number in four digits number.

#include<stdio.h>

#include<conio.h>

void main()

int f,l,n,sum;

clrscr();

printf ("enter any four digit no/n");

scanf("%d",&n);

f=n/1000;

l=n%10;

sum=f+l;

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

getch();

Example

Write a program to calcultate the


The net salary of person

#include<stdio.h>

#include<conio.h>

main()

int day,age;

char name,add;

float salary,netsalary;

clrscr();

printf("Enter the name=");

scanf("%s",&name);

printf("Enter the add=");

scanf("%s",&add);

printf("Enter the salary=");

scanf("%f",&salary);

printf("Enter the number of day which employee is late=");

scanf("%d",&day);

printf("Enter the age=");

scanf("%d",&age);

if(day>10)

netsalary=salary-salary*5/30;

printf("The netn salary of employee=%f",netsalary);

}
else

netsalary=salary-salary*2/30;

printf("Net salary of employee=%f",netsalary);

Example 16:-

Write a program to calcultate the

The net salary of person

#include<stdio.h>

#include<conio.h>

main()

int day,age;

char name,add;

float salary,netsalary;

printf("Enter the Name");

scanf("%s",&name);

printf("Enter the Add");

scanf("%s",&add);

printf("Enter the Salary");

scanf("%f",&salary);

printf("Enter the nomber of day which employe is late=");


scanf("%d",&day);

printf("Enter the age");

scanf("%d",&age);

if(day>10)

netsalary=salary-salary*5/30;

printf("The net salary of employe =%f",netsalary);

else

netsalary=salary-salary*2/30;

printf("Net salary of employe =%f",netsalary);

getch();

Example

Write a program to calculate the division of student

#include<stdio.h>

#include<conio.h>

main()

int age,m1,m2,m3,m4,m5;

char name,add;

float to,per;

clrscr();
printf("Enter the Name of the student=");

scanf("%s",&name);

printf("Enter the Address");

scanf("%s",&add);

printf("Enter the Age of the student");

scanf("%d",&age);

printf("Enter the marks of the 5 subjects=");

scanf("%d%d%d%d%d",&m1,&m2,&m3,&m4,&m5);

to=m1+m2+m3+m4+m5;

per=to/5;

printf("Total of 5 subjects=%f",to);

printf("Percentage of 5 subjects=%f",per);

if(per>=60)

printf("FIRST DIVISION");

else

if(per>=50)

printf("SECOND DIVISION");

else

if(per>=40)

printf("THIRD DIVISION");

else

printf("FAILED");

}
}

Example

Write a program to calculate the marks of student

#include<stdio.h>

#include<conio.h>

main()

int eng,hindi,maths,science,sst,computer;

float total,per;

clrscr();

printf("\nEnter the marks of 6 subjects");

scanf("%d%d%d%d%d%d",&eng,&hindi,&maths,&science,&sst,&computer);

total=eng+hindi+maths+science+sst+computer;

per=total*100/600;

printf("\nTotal of 6 subjects marks=%f",total);

printf("\nPercentage of 6 subjects marks=%f",per);

if(per>=40)

printf("\n The student is passed");

else

printf("The students is failed");

Example

Write a program to calculate the salary.


#include<stdio.h>

#include<conio.h>

main()

int num,salary,bonus;

clrscr();

printf("Enter a num between 1000 to 500");

scanf("%d",&num);

salary=num+bonus;

if(salary>=3000)

printf("It is a good salary");

Write a program to calculate the basic salary

#include<stdio.h>

#include<conio.h>

main()

int bs,gs,da,hra;

printf("Enter the basic salary");

scanf("%d",&bs);

if(bs<=1500);

hra=bs*10/100;

da=bs*90/100;
}

else

hra=500;

da=bs*98/100;

gs=bs+hra+da;

printf("Gross Salary=Rs%d",gs);

Example

write a program comparision of two no.

#include<stdio.h>

#include<conio.h>

main()

int a,b;

clrscr();

printf("Enter the digit a");

scanf("%d",&a);

printf("Enter the digit b");

scanf("%d",&b);

if(a>b)

printf("\n a is greater than b");

else
printf("\n b is greater than a");

Example

Write a program to calculate the 9 subject marks

#include<stdio.h>

#include<conio.h>

main()

int os,cit,pc,ee,fed,phy,chem,maths,mech;

float tot,per;

clrscr();

printf("Enter the marks of 9 subjects");

scanf("%d%d%d%d%d%d%d%d%d",&os,&cit,&pc,&ee,&fed,&phy,&chem,&maths,&mech);

tot=os+cit+pc+ee+fed+phy+chem+maths+mech;

per=tot*100/450;

printf("total of 9 subjects=%f",tot);

printf("per of 9 subjects=%f",per);

if(per>=80)

printf("First division");

else

if(per>=60)

printf("Second division");

else
{

if(per>=50)

printf("Third division");

else

printf("Failed");

Example

#include <stdio.h>
int main() {
int ID = 500;
int password = 000;
clrscr();
printf("Plese Enter Your ID:\n ");
scanf("%d", & ID);
switch (ID) {
case 500:
printf("Enter your password:\n ");
scanf("%d", & password);
switch (password) {
case 000:
printf("Welcome Dear Programmer\n");
break;
default:
printf("incorrect password");
break;
}
break;
default:
printf("incorrect ID");
break;
}
}

OUTPUT:
Plese Enter Your ID:
500
Enter your password:
000
Welcome Dear Programmer

Write a program to evaluate the switch statement

#include<stdio.h>

#include<conio.h>

main()

int i=2;

clrscr();

switch(i)

case1:

printf("I am in case1\n");

case2:

printf("I am in case2\n");

case3:

printf("I am in case3\n");

default:

printf("I am in default \n");

Example 19:-

Write a program to evaluate switch statement


#include<stdio.h>

#include<conio.h>

main()

int i=7;

clrscr();

switch(i)

case 121:

printf("\n I am in case 121");

break;

case 7:

printf("\n I am in case 7");

break;

case 22:

printf("\n I am in case 22");

break;

default:

printf("\n I am in default");

Example 20:-

Write a program to check alphabat

#include<stdio.h>

#include<conio.h>
main()

char c='A';

clrscr();

switch(c)

case 'A':

printf("\n I am i

n case A");

case 'B':

printf("\n I am in case B");

case 'C':

printf("\n I am in case C");

case 'X':

printf("\n I am in case X");

default:

printf("n I am in default");

Example 21:-

Write a program to check alphabat

#include<stdio.h>

#include<conio.h>

main()

{
char ch;

printf("\n Enter any of the alphabet a,b,c");

scanf("%c",&ch);

switch(ch)

case 'A':

printf("\n 'A'as in ashar");

break;

case 'B':

printf("\n 'B' as in brain");

break;

case 'C':

printf("\n 'C' as in cookie");

break;

default:

printf("\n WISH YOU KNEW WHAT ARE ALPHABETS");

Example 22:-

Write a program to print days Sunday to monday

#include<stdio.h>

#include<conio.h>

main()

int sun,mon,tue,wed,thu,fri,sat,day;
printf("Enter an integer in the range 1 to 7");

scanf("%d",&day);

switch(day)

case 1:

printf("Today is Sunday=%d",sun);

break;

case 2:

printf("Today is=%d",mon);

break;

case 3:

printf("Today is=%d",tue);

break;

case 4:

printf("Today is=%d",wed);

break;

case 5:

printf("Today is=%d",thu);

break;

case 6:

printf("Today is=%d",fri);

break;

case 7:

printf("Today is=%d",sat);

break;
default:

printf("Today is not valid");

Go to statement
Write a program to detect the entered number as to wheter it is even or odd.

Use go to statement.

#include<stdio.h>

#include<conio.h>

Void main()

Int n;

Clrscr();

Printf(“\n enter any no”);

Scanf(“%d”,&n);

If(n%2==2)

Go to even;

Else

Go to odd;

Even:

Printf(“no is even”);

Return:
Odd:

Printf(“no is odd”);

Getch();

While loop
Example

Write a program to print thehte string hello 10 times.

#include<stdio.h>

#include<conio.h>

Void main()

Int i=1;

Clrscr();

While(i<=10)

Printf(“\n hello”);

I++;

Getch()’

}
Example

Write a program to print the consiclucive numbers starting from 1.

#include<stdio.h>

#include<conio.h>

Void main()

Int i=1;

Clrscr();

While(i<=10)

Printf(“\n%d”,i);

I++;

Getch()’

Example

Write a program to print the consiclucive numbers starting from 10.

#include<stdio.h>

#include<conio.h>

Void main()

Int i=10;

Clrscr();
While(i>=1)

Printf(“\n%d”,i);

I--;

Getch()’

Example

Write a program to print the sum of consiclucive numbers starting from 1.

#include<stdio.h>

#include<conio.h>

Void main()

Int i=1,sum=0;

Clrscr();

While(i<=10)

Sum=sum+i

I++;

Printf(“\n%d”,sum);

Getch()’

Example
Write a program to print the frist five number starting from one to gether squires

#include<stdio.h>

# inckude <conio.h>

Void main(){

Int I,sum=0;

Clrser();

While (i<=5)

Squ = sum + I *I;

i++;

Printf(“%d%”,I ,sum);

Getch ();

Example

Write a program to read a four digits integer and print the reverse of digit.

#include<stdio.h>

#include<conio.h>

Void main()

Int n,l,sum=0;

Clrscr();

Printf(“\n enter any interger no”);

Scanf(“%d”,&n);

While(n>=0)

{
L=n%10;

N=n/10;

Sum=sum*10+l;

Printf(“%d”,sum);

Getch();

Example

Write a program to check whether number given palindrum or not.

#include<stdio.h>

#include<conio.h>

Void main()

Int n,l,sum=0,c,p;

Clrscr();

Printf(“\n enter any interger no”);

Scanf(“%d”,&n);

Cp=n;

While(n>=0)

L=n%10;

N=n/10;

Sum=sum*10+l;

If(sum==cp)

{
Printf(“palindrum”);

Else

Printf(“not palindrum”);

Getch();

Example

Example

Write a program to check a number through keywords and find the sum of it digits.

#include<stdio.h>

#include<conio.h>

Void main()

Int n,k,sum=0;

Clrscr();

Printf(“enter any four digit number”);

Scanf(“%d”,&n);

While(n>0)

K=n%10;

N=n/10;

Sum=sum+k;

}
Printf(“%d”,sum);

Getch();

Example

Write a program to check whether number given armstrong or not.

#include<stdio.h>

#include<conio.h>

Void main()

Int n,i=1,l,sum=0,c,p,cube;

Clrscr();

Printf(“\n enter any interger no”);

Scanf(“%d”,&n);

Cp=n

While(i<=n)

L=n%10;

N=n/10;

Cube=l*l*l;

Sum=sum+cube;

If(sum==cp)

Printf(“armstrong”);

Else
{

Printf(“not armstrong”);

Getch();

Write a program create a series of 2 number .

#include<stdio.h>

#include<conio.h>

Void main()

Int i=2;

Clrscr ();

While (i<=20)

Printf(“%d”,i);

I=i+2;

Gatch();

Write a program create a series of any number .

#include<stdio.h>

#include<conio.h>

Void main()

Int n,i=1,s;
Clrscr ();

Printf(“\n enter any no”);

Scanf(“%d”,&n);

While (i<=10)

S=n*I;

Printf(“%d”,s);

I=i++;

Gatch();

Write a program to calculate factorial of a givan number use while loop

# include <stdio.h>

#include<conio.h>

Void main()

Int n,i=1,fact=1;

Clrscr();

Printf(“\n enter any number”);

Scanf(“%d”,&n);

While(i<=n)

Fact=fact*I;

I++;

Printf(“%d”,fact);

Getch();
}

DO WHILE

Example

Write a program use the do while loop

#include<stdio.h>

#include<conio.h>

Void main()

Int i=1;

Clrscr();

Do {

Printf(“welcome to c”);

I++;

While(i<5);

Getch();

Example

Write a program to evaluate the series such as 1+2+3+…….i. use do while loop ahee I can we finite value
the should be read through the keyboard.

#include<stdio.h>

#include<conio.h>

Void main()

{
Int I,sum=0,n=1;

Clrscr();

Printf(“enter any no\n”);

Scanf(“%d”,&n);

Do

Sum=sum+I;

I++;

While(n<i);

Printf(“%d”,sum);

Getch();

Example

Write a program to print the ten numbers starting from 1 using the do while loop.

#include<stdio.h>

#include<conio.h>

Void main()

Int i=1;

Clrscr();

Do

Printf(“%d”,i);
I++;

while((i<10);

getch();

Example

Write a program to calculate the factorial of a number using do while loop .

#include<stdio.h>

#include<conio.h>

Void main()

Int i=1,n,fact=1;

Clrscr();

Printf(“enter any no”);

Scanf(“%d”,&n);

Do

Fact=fact*I;

I++;

While(i<n);

Printf(“%d”,fact);

Getch();

Write a orogeam to entered a number throught keyboard and to print lucas series.
#include<stdio.h>

#include<conio.h>

Void main()

Int a=1,b=3, c,n,i=1;

Clrscr();

Printf(“enter any number”);

Scanf(“%d”,$n);

While (i<=n-0)

}c= a=b;

A=b;

B=c;

Printf(“5d”;

I=I;

});

Getch();

Example

Write a program to binary to decimal.

#include<stdio.h>

#include<conio.h>

Void main()

In n, s=0,k i=1;

Clrscr();

Printf(“enter any binary number”);


Scanf(“%d”,&n);

While(n!=0)

K= n% 10;

N=n/10;

S=s+k *I;

I=i*2;

Printf(“decimal=%=d”s):

Getch();

Write a program to find the cubes 1 to 10 numbers using the do loop.

#include<stdio.h>

#include<conio.h>

Void main()

Int y,x=1,pow;

Clrser();

Printf(“in print the number and their(cubes”);

Printf(in”);

Do

While (x<=10);

Getch ();

}
Example

Write a program to check whether number given palindrum or not.

#include<stdio.h>

#include<conio.h>

Void main()

Int n,l,sum=0,c,p;

Clrscr();

Printf(“\n enter any interger no”);

Scanf(“%d”,&n);

Cp=n;

do

L=n%10;

N=n/10;

Sum=sum*10+l;

While(n>=0);

If(sum==cp)

Printf(“palindrum”);

Else

Printf(“not palindrum”);
}

Getch();

Example

Write a program to check whether number given armstrong or not.

#include<stdio.h>

#include<conio.h>

Void main()

Int n,i=1,l,sum=0,c,p,cube;

Clrscr();

Printf(“\n enter any interger no”);

Scanf(“%d”,&n);

Cp=n

Do

L=n%10;

N=n/10;

Cube=l*l*l;

Sum=sum+cube;

While(i<=n);

If(sum==cp)

Printf(“armstrong”);
}

Else

Printf(“not armstrong”);

Getch();

Example

Lucas series ucsing do while

#include<stdio.h>

#include<conio.h>

Void main()

Int a=1, b=3,c. n, i=1;

Clrscr();

Printf(“enter any number”);

Scanf(“%d”,&n);

Do

C=a+b,

A=b;

B=c;

Printf(“%d”,c);

While(i<=n-2);

I++;
}

Getch();

write a program to calculate the sum of any numbers and their square display there result.

#include<stdio.h>

#include<conio.h>

Void main()

Int n, I, sqr, sum=0, sqrsum=0;

Clrscr();

Printf(“enter any no\n”);

Scanf(“%d”,&n);

Do

Sqr=i*I;

Sqrsum=sqrsum+sqr;

Sum=sum+I;

Printf(“%d%d”,I,sqr);

I++;

While(i<n);

Printf(“%d%d”,sum, sqesum);

Getch();

}
Example

Write a program to add all odd integer between 0 to 100.

#include<stdio.h>

#include<conio.h>

Void main()

Int i=0, sum=0;

Clrscr();

Do

If(i%2!=0)

Sum=sum+I;

I++;

While(i<100);

Printf(“%d”,sum);

Getch();

For loop
Write c program to print a message

#include<stdio.h>

#include<conio.h>
main()

int a;

for(a=0;a<=10;a=a+1)

printf("\n Here is a some Mail for you");

Write c program to print a series 1 to 10 using for loop

#include<stdio.h>

#include<conio.h>

main()

int a;

clrscr();

for(a=0;a<=10;a=a+1)

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

Write c program to print a series 10 to 1 using for loop

#include<stdio.h>

#include<conio.h>

main()

int a;

clrscr();
for(a=100;a<=1;a--)

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

Write a program to check whether pass and fail

#include<stdio.h>

#include<conio.h>

main()

int i;

float marks;

clrscr();

for(i=0;i<=3;i++);

printf("Enter your marks");

scanf("%f",&marks);

if(marks>=300)

printf("Student is pass");

else

printf("Fail");

Nested loop
Example 1

#include<stdio.h>

#include<conio.h>

void main()

int i,j;

clrscr();

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

for(j=1;j<=3;j++)

printf("*");

printf("\n");

Example 2

#include<stdio.h>

#include<conio.h>

void main()

int i,j;
clrscr();

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

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

printf("#");

printf("\n");

}
Example 3

#include<stdio.h>

#include<conio.h>

void main()

int i,j;

clrscr();

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

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

printf("%d",i);

}
printf("\n");

}
Example 4

#include<stdio.h>

#include<conio.h>

void main()

int i,j;

clrscr();

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

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

printf("%d",i );

printf("\n");

}
Example 5

#include<stdio.h>

#include<conio.h>

void main()
{

int i,j;

clrscr();

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

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

printf("%d",j);

printf("\n");

}
Example 6

#include<stdio.h>

#include<conio.h>

void main()

int i,j;

clrscr();

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

for(j=i;j>=1;j--)

{
printf("%d",j);

printf("\n");

}
Example 7

#include<stdio.h>

#include<conio.h>

void main()

int i,j;

clrscr();

for(i=4;i>=1;i--)

for(j=i;j>=1;j--)

printf("*",j);

printf("\n");

}
Example 8

#include<stdio.h>
#include<conio.h>

void main()

int i,j;

clrscr();

for(i=4;i>=1;i--)

for(j=i;j>=1;j--)

printf("*",j);

printf("\n");

}
Example 9

#include<stdio.h>

#include<conio.h>

void main()

int i,j,mult;

clrscr();

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

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

mult=i*j;

printf("%3d",mult);

printf("\n");

Function
Example 1

Write a program to calculate the sum of interger no. using function


#include<stdio.h>

#include<conio.h>

int sum()

return(30+20);

main()

int total;
clrscr();

total=sum(30,20);

printf("Sum of two no. is: %d",total);

Example2

Write a program to evaluate the subtraction of no. using function


#include<stdio.h>

#include<conio.h>

void sub(int a,int b)

int result;

result=a-b;

printf("Subtraction of %d and %d is %d.\n\n",a,b,result);

void main()

clrscr();

sub(10,5);

sub(80,50);

sub(45,20);

#include<stdio.h>

#include<conio.h>

int multiply(int a,int b)


{

int result;

result=a*b;

printf("multiply of %d and %d is %d.\n\n",a,b,result);

void main(){

clrscr();

multiply(20,5);

multiply(50,78);

multiply(41,52);

Example 3

Function without argument and return value.


#include<stdio.h>

#include<conio.h>

Void main()

Int z:

Clrscr();

Z=sub();

Printf(“%d”,z);

Getch();

Int sub()
{

Int a, b, c;

Printf(“enter any two number”);

Scanf(“%d%d”,&a,&b);

C=a-b;

Return c;

Example 4

function with argument and no return value.


#include<stdio.h>

#include<conio.h>

Void sum(int x, int y);

Void main()

Int a, b;

Clrscr();

Printf(“enter any two number”);

Scanf(“%d%d”,&a,&b);

Sum(a, b);

Getch();

Void sum(int a, int b)

Int c;
C=a+b;

Printf(“%d”,c);

Example 5

function with argument and return value.


#include<stdio.h>

#include<conio.h>

Void sum(int x, int y);

Void main()

Int a, b,C;

Clrscr();

Printf(“enter any two number”);

Scanf(“%d%d”,&a,&b);

C=Sum(a, b);

Printf(“%d”,c);

Getch();

Void sum(int a, int b)

Int c;

C=a+b;

Return c;

}
Example 6

function with no argument and no return value.


#include<stdio.h>

#include<conio.h>

Void sum();

Void main()

Clrscr();

Sum();

Getch();

Void sum()

Int a, b, c;

Printf(“enter any two no”);

Scanf(“%d%d”,&a,&b);

C=a+b;

Printf(“%d”,c);

}
ARRAY
Write a program to evaluate an array

#include<stdio.h>

#include<conio.h>

main()

int arr[7],i;

clrscr();

arr[0]=10;

arr[1]=20;

arr[3]=30;

arr[4]=40;

arr[5]=50;

arr[6]=60;

printf("Value in array arr[0]:%d\n",arr[0]);

printf("Value in array arr[1]:%d\n",arr[1]);

printf("Value in array arr[2]:%d\n",arr[2]);

printf("Value in array arr[3]:%d\n",arr[3]);

printf("Value in array arr[4]:%d\n",arr[4]);

printf("Value in array arr[5]:%d\n",arr[5]);

printf("Value in array arr[6]:%d\n",arr[6]);

printf("\n");

for(i=0;i<7;i++)

printf("Value in array arr[%d]:%d\n",i,arr[i]);


}

Example 36:-

Write a program to evaluate ASCI code

#include<stdio.h>

#include<conio.h>

main()

int sub[50],i;

for(i=0;i<=48;i++)

sub[i]=i;

printf("\n %d",sub[i]);

Example 37:-

Write a program display the student mark using array.

#include<stdio.h>

#include<conio.h>

main()

int b[]={10,20,30,40,50};

int i;

for(i=0;i<=4;i++)

{
printf("\n %d",*(b+i));

Example 38:-

Write a program to evaluate an array.

#include<stdio.h>

#include<conio.h>

main()

int b[]={0,20,30,40,50};

int i,*k;

k=b;

for(i=0;i<=4;i++)

printf("\n %d",*k);

k++;

Example 39:-

Write a program display the student mark using array.

#include<stdio.h>

#include<conio.h>

main()

{
int i;

int marks[]={55,65,75,56,78,90};

for(i=0;i<=6;i++)

display(marks[i]);

display(int m)

printf("%d",m);

Example 40:-

Write a program display the student mark using array.

#include<stdio.h>

#include<conio.h>

main()

int stud[4][2];

int i,j;

for(i=0;i<=3;i++)

printf("\n Enter roll and marks");

scanf("%d%d",&stud[i][0],&stud[i][1]);

for(i=0;i<=3;i++)

printf("\n %d%d",stud[i][0],stud[i][1]);

}
Example 41:-

Write a program display the student mark using array.

#include<stdio.h>

#include<conio.h>

main()

int stud[4][2];

int i,j;

for(i=0;i<=3;i++)

printf("\n Enter roll and marks");

scanf("%d%d",&stud[i][0],&stud[i][1]);

for(i=0;i<=3;i++)

printf("\n %d%d",stud[i][0],stud[i][1]);

Example 42:-

Write a program to evaluate an array

#include<stdio.h>

#include<conio.h>

main()

int b[]={10,20,30,40,50,60,70,80};

int i;

clrscr();
for(i=0;i<=7;i++)

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

Example 43:-

Write a program to evaluate an array

#include<stdio.h>

#include<conio.h>

main()

int marks[4],i;

float to,per;

clrscr();

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

printf("Enter the marks of 5 subjects=");

scanf("%d%d%d%d%d",&hindi,&eng,&maths,&sci,&arts);

to=hindi+eng+maths+sci+arts;

per=to/5;

printf("\n Total of 5 subjects=%f",to);

printf("\n Percentage of 5 subjects=%f",per);

Example 44:-
Write a program to evaluate an array

#include<stdio.h>

#include<conio.h>

main()

int num[9],i;

clrscr();

for(i=0;i<=8;i++)

printf("\n Enter the number==");

scanf("%d",&num[i]);

printf("The number=%d",i,num[i]);

Example 45:-

Write a program to print name using array

#include<stdio.h>

#include<conio.h>

main()

char name[9];

int i;

clrscr();

printf("Enter the name=");


scanf("%s",&name);

for(i=0;i<8;i++)

printf("%c",name[i]);

Example 46:-

Write a program to evaluate the pointer

#include<stdio.h>

#include<conio.h>

main()

int a=20;

int *b;

clrscr();

b=&a;

printf("The value of a is :%d",a);

printf("\n The address of a is :%u",b);

Example 47:-

Write a program to evaluate an array

#include<stdio.h>

#include<conio.h>

main()

{
int x[5][50];

long y[5][10];

char z[18];

short a[20];

clrscr();

printf("The number of elements in each array=x[5][50],y[5][10]");

Example 48:-

Write a program to calculate lowest and higest no.

#include<stdio.h>

#include<conio.h>

main()

int v[50],large,small;

int i,n;

printf("Enter how many elements (max 50)? \n");

scanf("%d",&n);

printf("Enter the values in the vector \n");

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

scanf("%d",&v[i]);

large=v[1];

small=v[1];

for(i=0;i<n;i++)
{

if(v[i]>large)

large = v[i];

else

if(v[i]<small)

small= v[i];

printf("\n Large elements=%d",large);

printf("\n Small elements=%d",small);

#include <stdio.h>
int main()
{
int marks[10], i, n, sum = 0, average;
Clrscr();
printf("Enter number of elements: ");
scanf("%d", &n);

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


{
printf("Enter number%d: ",i+1);
scanf("%d", &marks[i]);

// adding integers entered by the user to the sum variable


sum += marks[i];
}

average = sum/n;
printf("Average = %d", average);

return 0;
}

#include <stdio.h>
int main()
{
int avg = 0;
int sum =0;
int x=0;

/* Array- declaration – length 4*/


int num[4];
clrscr();
/* We are using a for loop to traverse through the array
* while storing the entered values in the array
*/
for (x=0; x<4;x++)
{
printf("Enter number %d \n", (x+1));
scanf("%d", &num[x]);
}
for (x=0; x<4;x++)
{
sum = sum+num[x];
}

avg = sum/4;
printf("Average of entered number is: %d", avg);
return 0;
}
Output:

Enter number 1
10
Enter number 2
10
Enter number 3
20
Enter number 4
40
Average of entered number is: 20

You might also like