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

C Assignment

The document contains a series of C programming exercises submitted by Karan Sojitra, a student at Smt. Z. S. Patel College of Management & Technology. Each program demonstrates various programming concepts such as arithmetic operations, area calculations, conditional statements, loops, and patterns. The document includes code snippets, outputs, and is structured as a submission for a Computer Programming and Programming Methodology course.

Uploaded by

ravalkaran187
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)
32 views

C Assignment

The document contains a series of C programming exercises submitted by Karan Sojitra, a student at Smt. Z. S. Patel College of Management & Technology. Each program demonstrates various programming concepts such as arithmetic operations, area calculations, conditional statements, loops, and patterns. The document includes code snippets, outputs, and is structured as a submission for a Computer Programming and Programming Methodology course.

Uploaded by

ravalkaran187
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
You are on page 1/ 40

Smt. Z. S.

Patel College Of Management & Technology


Computer Programming &
Programming Technology

Karan Sojitra
FY BCA B
Roll No.:51
Submitted to-
Mrs. Reema Singh

KARAN SOJITRA
SMT. Z. S. PATEL COLLEGE OF MANAGEMENT & TEECHNOLOGY Palanpur Patiya-Adajan
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B

#Program<1>: Write a Program to Addition of Two Numbers.

#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
clrscr();
printf("Enter Number1=");
scanf("%d",&a);
printf("Enter Number2=");
scanf("%d",&b);
c=a+b;
printf("Your Answer is %d",c);
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<2>: Write a Program to Perform Arithmetic Operations.
#include<stdio.h>
#include<conio.h>
void main()
{
int choice, n1, n2, res;
clrscr();
printf("------------Calculator--------------");
printf("\nEnter No 1=");
scanf("%d",&n1);
printf("Enter No 2=");
scanf("%d",&n2);
printf("-------Select Anyone Operation -------");
printf("\n1 Addition \n2 Subtaction \n3 Multipication \n4 Division");
printf("\n---------------------------------------");
printf("\nEnter Your Choice=");
scanf("%d",&choice);
switch(choice)
{
case 1: Output:-
res=n1+n2;
printf("Answer is %d",res);
break;
case 2:
res=n1-n2;
printf("Answer is %d",res);
break;
case 3:
res=n1*n2;
printf("Answer is %d",res);
break;
case 4:
res=n1/n2;
printf("Answer is %d",res);
break;
}
getch();
}

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B

#Program<3>: Write a Program to find area of Rectangle.


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

void main() {
int l, b, area;
clrscr();

printf("\n\tEnter the Length of Rectangle : ");


scanf("%d", &l);

printf("\n\tEnter the Breadth of Rectangle : ");


scanf("%d", &b);

area = l*b;
printf("\n\tArea of Rectangle : %d", area);

getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B

#Program<4>: Write a Program to fine Area of Circle.

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

void main() {
int r, pi=3.14, area;
clrscr();

printf("\n\tEnter the Length of Radious : ");


scanf("%d", &r);

area = pi*r*r;
printf("\n\tArea of Circle : %d", area);

getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<5>: Write a Program that Viewing an Example of Symbollic
Constant.

#include<stdio.h>
#include<conio.h>
#define pi 3.14

void main() {
int r, area;
clrscr();

printf("\n\tEnter the Length of Radious : ");


scanf("%d", &r);

area = pi*r*r;
printf("\n\tArea of Circle : %d", area);

getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<6>: Write a Program to Check whether the number is
POSITIVE or NAGATIVE.

#include<stdio.h>
#include<conio.h>
void main()
{
int n1;
clrscr();
printf("\tEnter the Number= ");
scanf("%d",&n1);
if(n1<0)
{
printf("\n\t*************************\n");
printf("\t*Your Number is Nagative*\n");
printf("\t*************************\n");
}
else if(n1>0)
{
printf("\n\t*************************\n");
printf("\t*Your Number is Positive*\n");
printf("\t*************************\n");
}
else
{
printf("\n\txxx You Enter A Wrong Number or The Number is Zero
xxx");
}
getch();
Output:-
}

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<7>: Write a Program to check Whether the Number is ODD
or EVEN.

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

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<8>: Write a Program to Find Largest number among three
using IF statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int a, b, c;
printf("Enter three numbers: ");
scanf("%d %d %d", &a, &b, &c);
if(a>=b && a>=c)
printf("Largest number = %d", a);
else if(b>=a && b>=c)
printf("Largest number = %d", b);
else
printf("Largest number = %d", c);
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<9>: Write a program to Find the Result is PASS or FAIL from
given Percentage.
#include<stdio.h>
#include<conio.h>
void main()
{
int M1,M2,M3,M4,M5,total,Per;
clrscr();
printf("Enter M1,M2,M3,M4,M5 : ");
scanf("%d %d %d %d %d",&M1,&M2,&M3,&M4,&M5);
total = M1+M2+M3+M4+M5;
Per = total / 5;
if(M1<40 || M2<40 || M3<40 || M4<40 || M5<40)
{
printf("\nFail");
}
else
{
if(Per >= 70)
printf("\nDistinction");
else if(Per >= 60 && Per<70)
printf("\nFirst Class");
else if(Per >= 50 && Per<60)
printf("\nSecond Class");
else if(Per >= 40 && Per<50)
printf("\nPass Class");
} Output:-
getch();
}

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<10>: Write a Program to Check Weather the Year is LEAP
Year or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
printf("Enter the Valid Digit Year= ");
scanf("%d",&a);
if((a%4==0&&a%100!=0)||(a%400==0))
{
printf("%d is leapyear",a);
}
else
{
printf("%d is not Leapyear",a);
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<11>: Display 1 to 5 Numbers using GOTO Statement.
#include<stdio.h>
#include<conio.h>
void main()
{
int a,label;
clrscr();
goto label;
a=0;
printf("%d",a);
label:
printf("\t\tGO TO STATMENT\n");
a=1;
printf("\t\t\t%d\n",a);
a=2;
printf("\t\t\t%d\n",a);
a=3;
printf("\t\t\t%d\n",a);
a=4;
printf("\t\t\t%d\n",a);
a=5;
printf("\t\t\t%d\n",a);
getch();
} Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<12>: Write a Program to Print 1 to 10 numbers using FOR
loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int a;
clrscr();
for(a=1;a<=10;a=a+1)
{
printf("\t\t\t %d\n",a);
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<13>: Write a Program to Print 1 to 10 numbers using
WHILE loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i=1;
clrscr();
while(i<=10)
{
printf("\n\t\t\t** %d ** ",i);
i++;
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<14>: Write a Program to Display ODD numbers between 1
to 10.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=1;i<=10;i=i+2)
{
printf("\n\t\t\t*%d*\n",i);
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<15>: Write a Program to Display EVEN numbers between 1
to 10.
#include<stdio.h>
#include<conio.h>
void main()
{
int i;
clrscr();
for(i=2;i<=10;i=i+2)
{
printf("\n\t\t\t*%d*\n",i);
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<16>: Write a Program to Print 1 to N Number using For
Loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,N;
clrscr();
printf(“\n\t\t\t===========”);
printf("\n\t\t\tEnter N : ");
scanf("%d",&N);

for(i=1;i<=N;i++)
{
printf("\t\t\t %d ",i);
}

getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<17>: Write a Program to Print Square Of 1 to N Number
using For Loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,N;
clrscr();
printf(“\n\t\t\t===========”);
printf("\n\t\t\tEnter N : ");
scanf("%d",&N);

for(i=1;i<=N;i++)
{
printf("\t\t\t %d ",i*i);
}

getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<18>: Write a Program to Print Cube Of 1 to N Number
using For Loop.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,N;
clrscr();
printf(“\n\t\t\t===========”);
printf("\n\t\t\tEnter N : ");
scanf("%d",&N);

for(i=1;i<=N;i++)
{
printf("\t\t\t %d ",i*i*i);
}

getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<19>: Write a Program to Print Pattern of Start at alignment
of Left Above.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,no=5;
for(i=1;i<=no;i++)
{
for(j=1;j<=1;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<20>: Write a Program to Print Pattern of Start at alignment
of Left Below.

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

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<21>: Write a Program to Print Pattern of Start at alignment
of Right Above.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n=5;
clrscr();
printf("\n ");
for(i=1;i<=n;i++)
{
for(j=i;j<=n-1;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<22>: Write a Program to Print Pattern of Start at alignment
of Right Below.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n=5;
clrscr();
printf("\n ");
for(i=n;i<=n;i--)
{
for(j=i;j<=n-1;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<23>: Write a Program to Print Pattern of Start at alignment
of Center Above.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n=5;
clrscr();
printf("\n ");
for(i=1;i<=n;i++)
{
for(j=i;j<=n-1;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf(" *");
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<24>: Write a Program to Print Pattern of Start at alignment
of Right Below.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,n=5;
clrscr();
printf("\n ");
for(i=n;i<=n;i--)
{
for(j=i;j<=n-1;j++)
{
printf(" ");
}
for(j=1;j<=i;j++)
{
printf("*");
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<25>: Write a Program to Print Pattern 1, 22, 333, 4444.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,N;
clrscr();

printf("Enter N : ");
scanf("%d",&N);

for(i=1;i<=N;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<26>: Write a Program to Print Pattern 1, 22, 333, 4444.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,N;
clrscr();

printf("Enter N : ");
scanf("%d",&N);

for(i=1;i<=N;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<27>: Write a Program to Print Pattern 1, 22, 333, 4444.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,j,c,N=5;
clrscr();
c=1;
for(i=1;i<=N;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",c);
c++;
}
printf("\n");
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<28>: Write A Program to Print A Factorial of the Number.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,f,N;
clrscr();
printf("Enter N : ");
scanf("%d",&N);
f=1;
for(i=1;i<=N;i++)
{
f=f*i;
}
printf("\n fact = %d",f);
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<29>: Write a program to find out fibonacci series of N
numbers.
#include<stdio.h>
#include<conio.h>

void main()
{
int a,n,b,c,i;
clrscr();
printf("\nEnter n:");
scanf("%d",&n);
printf("\n%d terms of fibonacci series are\n",n);
a=0;
b=1;
for(i=1;i<=n;i+=1)
{
c=a+b;
printf("%5d",a);
a=b;
b=c;
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<30>: Write a program to check a given number is prime
number or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int no,i,p;
clrscr();
printf("\nEnter NO:");
scanf("%d",&no);
p=0;
for(i=2;i<=no/2;i++)
{
if(no % i==0)
{
p=1;
break;
}
}
if(p==1)
printf("\n%d is not prime",no);
else
printf("\n%d is prime",no);
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<31>: Write a program to find out a given number is perfect
number or not.
#include<stdio.h>
#include<conio.h>
void main()
{
int i,n,s;
clrscr();
printf("\nEnter number : ");
scanf("%d",&n);
s=0;
for(i=1;i<n;i++)
{
if(n%i == 0)
s=s+i;
}
if (s==n)
printf("\n%d is perfect",n);
else
printf("\n%d is not perfect",n);
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<32>: Write a program to Display Reverse of the Number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,rn;
rn=0;
clrscr();
printf("\nEnter no:");
scanf("%d",&n);
while(n !=0 )
{
r=n % 10;
rn=rn*10+r;
n=n/10;
}
printf("\nReverse no=%d",rn);
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<33>: Write a program to Display Number is PELINDROM or
NOT.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,r,rn,n1;
rn=0;
clrscr();
printf("\n\nENTER NO:");
scanf("%d",&n);
n1=n;
while(n !=0 )
{
r=n % 10;
rn=rn*10+r;
n=n/10;
}
printf("\n\nREVERSE NO=%d",rn);
if(rn==n1)
{
printf("\nNO IS PLAINDROM");
}
else
{
printf("\nNO IS NOT PALINDROM");
}
getch(); Output:-
}

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<34>: Write a program to Display Armstrong of the Number.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,n1,s,r;
clrscr();
printf("\nEnter number : ");
scanf("%d",&n);
n1=n;
s=0;
while(n!=0)
{
r=n%10;
n=n/10;
s=s+r*r*r;
}
if (s==n1)
{
printf("\n%d is amstrong",n1);
}
else
{
printf("\n%d is not amstrong",n1);
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<35>: Write a Program to Convert Decimal to Binary.
#include<stdio.h>
#include<conio.h>
void main()
{
int n,n1,i=0,b[100],j;
clrscr();
printf("\nEnter decimal number: ");
scanf("%d", &n);
n1=n;
i=0;
while (n>0)
{
b[i]=n%2;
n=n/2;
i++;
}
printf("\nDecimal No = %d ",n1);
printf("\nBinary No = ");
for (j=i-1;j>=0;j--)
{
printf("%d", b[j]);
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<36>: Write a Program to Display Multiplication Table of a
Given Number.
#include<stdio.h>
#include<conio.h>
void main ()
{
int x, i;
printf("Enter the x : ");
scanf("%d", &x);
printf("\n Multiplication table of %d:", x);
printf("\n --------------------------");
for ( i = 1;i <= 10;i++)
{
printf("\n %d x %d = %d ", x, i, x * i);
}
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<37>: Write a Program to Display Power of Number.
#include<stdio.h>
#include<conio.h>
void main ()
{
int x, y, ans, i;
printf("Enter x : ");
scanf("%d", &x);
printf("Enter it's power y : ");
scanf("%d", &y);
ans=1;
for(i=1;i<=y;i++)
{
ans = ans * x;
}
printf("%d^%d is %d", x, y, ans);
getch();
}

Output:-

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B
#Program<38>:Write a Program to Find GCD And LCM of given
Numbers.
#include<stdio.h>
#include<conio.h>
void main()
{
int n1, n2, m, i, lcm;
clrscr();

printf("Enter the Nums:");


scanf("%d%d", &n1, &n2);
if(n1>n2)
{
m=n2;
}
else
{
m=n1;

for(i=m;i>=1;--i)
{
if(n1%i==0 && n2%i==0)
{
printf("\nHCF of %d and %d is %d", n1, n2, i);
break;
}
} Output:-
lcm=(n1*n2)/i;
printf("\nYour LCM is %d",lcm);
getch();
}
}

Karan Sojitra
Roll No.:51
Smt. Z. S. Patel College Of Management & Technology
Computer Programming & Programming Methodology
FY BCA B

Karan Sojitra
Roll No.:51

You might also like