Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
113 views

File of C Programming

The document contains C program code snippets written by Raheesh Pal Singh. There are 27 code snippets demonstrating various programming concepts like input/output, conditional statements, loops, functions, arrays and more. The code snippets each have a brief description of the program and expected output. Overall the document appears to be notes or examples from a programming course.

Uploaded by

arun
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)
113 views

File of C Programming

The document contains C program code snippets written by Raheesh Pal Singh. There are 27 code snippets demonstrating various programming concepts like input/output, conditional statements, loops, functions, arrays and more. The code snippets each have a brief description of the program and expected output. Overall the document appears to be notes or examples from a programming course.

Uploaded by

arun
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/ 27

Raheesh Pal Singh

Princple & Algorithim

Programming

//wap find the sum two number inputted//


#include<stdio.h>
#include<conio.h>
Void main()
{
int a=20,b=10,c;
clrscr();
c=a+b;
printf("add=%d",c);
getch();
}

Output:

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

//wap to find the marks and its percentage and total


marks also //
#include<stdio.h>
#include<conio.h>
void main()
{
int hindi,english,physics,chemistry,math,total;
float avg;
clrscr();
printf("Enter the mark=: ");
scanf("%d%d%d%d
%d",&hindi,&english,&physics,&chemistry,&math);
total=hindi+english+physics+chemistry+math;
printf("\nTotal is %d",total);
avg=total/5;
printf("\nPercentage is %f",avg);
if(avg>=60)
printf("\nFirst division");
else
if((avg>45)&&(avg<60))
printf("\nSecond division");
2

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

else
if((avg>33)&&(avg<45))
printf("\nThird divisoin");
else
printf("Fail");
getch();
}

Output:

//wap interchange two value using the third variable//


3

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<stdio.h>
#include<conio.h>
void main()
{
int a,b,c;
clrscr();
printf("enter the num=");
scanf("%d%d",&a,&b);
c=a;
a=b;
b=c;
printf("%d%d",a,b);
getch();
}

Output:

//wap area or perimeter of rectangle or area and


4

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

circumference of circle//
#include<stdio.h>
#include<conio.h>
void main()
{
int c,n,l,b,p,a;
float ar,r;
clrscr();
printf("Press below values for operation's: \n");
printf("1.Rectengle\n");
printf("2.Circle\n");
printf("Enter the choice: ");
scanf("%d",&n);
if(n==1)
{
printf("Enter the Length & Breadth for Area & Perimeter of
Rectangle: ");
scanf("%d%d",&l,&b);
a=l*b;
printf("\nArea of Rectangle is : %d",a);
p=2*(l+b);
5

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

printf("\nPerimeter of Rectangle is : %d",p);


}
else
{
printf("Enter the Radius for finding the Area of Circle: ");
scanf("%f",&r);
ar=3.14*r*r;
printf("Area of Circle is : %f",ar);
}
getch();
}

Output:

//wap to check the given number is even or odd //


#include<stdio.h>
6

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int n;
clrscr();
printf("enter the num=");
scanf("%d",&n);
if(n%2==0)
printf("even");
else
printf("odd");
getch();
}

Output:

//wap to check whether a given year is a leap year or not //


#include<stdio.h>
7

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int year;
clrscr();
printf("Enter the year=");
scanf("%d",&year);
if(((year%4==0)&&(year%100!=0))||(year%400==0))
printf("%d is a leap year",year);
else
printf("%d is not leap year",year);
getch();
}

Output:

//wap to convert given seconds to hour, minute and seconds//


#include<stdio.h>

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int h,s,m;
clrscr();
printf("Enter the Second=");
scanf("%d",&s);
m=s/60;
h=s/3600;
printf("h=%d,m=%d,s=%d",h,m,s);
getch();
}

Output:

// wap to print a table 1 to 10 of given number //


#include<stdio.h>
9

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int i,j;
clrscr();
for(i=1;i<=10;i++)
{
for(j=1;j<=10;j++)
{
printf("%d\t",i*j);
}getch();
}

Output:

//wap to print following tringles to given number of rows//


#include<stdio.h>
10

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int i,j,k;
clrscr();
for(i=1;i<=6;i++)
{
for(j=6;j>i-1;j--)
{
printf(" ");
}
for(k=1;k<=i;k++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output:
11

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

//wap a program to check whether a given three digit number is


palindrome or not//
#include<stdio.h>
#include<conio.h>
12

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

void main()
{
int n,r,p,s=0;
clrscr();
printf("Enter the number=");
scanf("%d",&n);
p=n;
while(n>0)
{
r=n%10;
printf("The value of r is%d\n",r);
n=n/10;
printf("The value of n is%d\n",n);
s=s*10+r;
printf("The value of s is%d\n",s);
printf("---------------------\n");
}
printf("%d%d",p,s);

if(p==s)
printf("\n number is palindrome %d",s);
13

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

else
printf("not");
getch();
}
Output:

//wap to reverse a given five digit number//


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

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

void main()
{
int i,n,r;
clrscr();
n=1234;
while(n>0)
{
r=n%10;
printf("%d",r);
n=n/10;
}
getch();
}

Output:

//wap to print the ASCII chart with in a given number//


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

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

void main()
{
char a;
clrscr();
printf("enter the value=");
scanf("%c",&a);
printf("ASCII=%d",a);
getch();
}

Out put

//wap to print, whether number is armstrong or not.


#include<stdio.h>
#include<conio.h>
void main()
16

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

{ int n,r,s=0,p;
clrscr();
printf("enter the num=");
scanf("%d",&n);
p=n;
while(n>0){
r=n%10;
n=n/10;
s=s+(r*r*r); }
if(s==p)
printf("Num Is Armstronge");
else
printf("Not");
getch();
}Output:

// wap to find the factorial of given number.//


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

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

int fact(int);
void main()
{ int a,b;
clrscr();
printf("enter the num=");
scanf("%d",&a);
b=fact(a);
printf("factorial %d",b);
getch(); }
int fact(int n)
{ if(n==1)
return(1);
else
return(n*fact(n-1)); }

Output:

// wap to print the fibonacci series up to a given number //


#include<stdio.h>
18

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int a=0,b=1,c;
clrscr();
while(a<20)
{
c=a+b;
printf("%d\n",a);
a=b;
b=c;
}
getch();
}Output:

// write a program to evaluate xn //


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

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<math.h>
void main()
{
int n,s=0,p;
clrscr();
printf("Enter The Num");
scanf("%d",&n);
printf("Enter The Value For Power");
scanf("%d",&p);
s=pow(n,p);
printf("%d",s);
getch();
}

Output:

// wap to print the prime number in a given number //


#include<stdio.h>

20

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int num,i;
clrscr();
printf("enter the num");
scanf("%d",&num);
i=2;
while(i<=num-1)
{
if (num% i==0)
{
printf("not prime num");
break;
}
i++;
if(num% i==0)
printf("prime num");
}
getch();
}

21

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

Output:

// wap to ask the user for a number . print the square of the number
and user want to continue or not //
#include<stdio.h>
22

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<conio.h>
void main()
{
int a=2,b,n;
clrscr();
while(a<=10)
{
b=a*a;
printf("%d\t",b);
a=a+1;
printf("\n");
printf("Do You want to Continue?");
scanf("%d",&n);
if(n==1)
continue;
else
exit(0);
}
getch();
}

Output:

23

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

// wap to print a triangle(floyds triangle) like the following //


24

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,l,k;
clrscr();
for(i=1;i<=5;i++)
{
for(j=5;j>=i;j--)
{
printf(" ");
}
for(l=1;l<=i;l++)
{
printf("%d",l);
}
for(k=i-1;k>=1;k--)
{
printf("%d",k);
}
printf("\n");
}
25

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

getch();
}

Output:

//wap to evaluate 1/3+2/5+3/7.+n/ ((n*2)+1). //


26

BCA 1

ST

SEM

ROLL NO.140025011050

Raheesh Pal Singh


Princple & Algorithim

Programming

#include<stdio.h>
#include<conio.h>
void main()
{
int i,n;
float sum=0.00;
clrscr();
printf("enter the valueof n=");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+(float)i/((i*2)+1);
}
printf("sum of harmonic series=%f",sum);
getch();}

Output:

27

BCA 1

ST

SEM

ROLL NO.140025011050

You might also like