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

Practical File For External 2nd

c++practical

Uploaded by

negiayushsvsv
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)
12 views

Practical File For External 2nd

c++practical

Uploaded by

negiayushsvsv
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/ 19

INTODUCTION TO C LAN

PROJECT-C PROGRAMS

STUDENT NAME-AYUSH NEGI


ROLL NUMBER-21
SEMESTER-I SEMESTER
YEAR-2023

SUBMITTED TO-MR.PARAS NEGI


SUBMITTED BY-AYUSH NEGI
SOBA
N INDEX
 Write a program of adding two number.
SINGH
 Write a program to find out square of
JEENA
number.
 Write a program of swapping two number
UNIVE
with the help of temporary variable.
 Write a program of swapping two number
RSITY
without temporary variable.
 Write a program to find out whether a
,CAM
number is even or odd.
 Write a program to find out sum of first n
PUS
natural number.
ALMO
 Write a program to print table of 5.
 Write a program to find first 20 even
RA
numbers.
 Write a program to find out first 20 odd
numbers.
 Write a program to print a table with the help
of while loop.
 Write a program to find out whether a
number is prime or not.
 Write a program to print number from 1 to
10 while break statement.
 Write a program to print a table of 9 while
continue statement .
 Write a program to find sum of array.
 Write a program to find out maximum from
an array.

1.write a program of adding two number.


Source code-
#include<stdio.h>
int main()
{
int a,b,c;
printf("enter the number");
scanf("%d%d",&a,&b);
c=a+b;
printf("%d",c);
return 0;
}
OUTPUT-

-
2.write a program to find out the square of
number.
SOURCE CODE-
#include<stdio.h>
int main()
{
int a,c;
printf("enter a number");
scanf("%d",&a);
c=a*a;
printf("%d",c);
return 0;
}
OUTPUT-

}
3.write a program of swapping two number with
the help of temporary variable.
SOURCE CODE-
#include<stdio.h>
int main()
{
int a,b,temp;
printf("enter the number");
scanf("%d%d",&a,&b);
temp=a;
a=b;
b=temp;
printf("a=%d b=%d",a,b);
return 0;
}
Output-
4.write a program of swapping two number
without temporary variable.
SOURCE CODE-
#include<stdio.h>
int main()
{
int a,b;
printf("enter two number");
scanf("%d%d",&a,&b);
a=a+b;
b=a-b;
a=a-b;
printf("a=%d b=%d",a,b);
return 0;
}
OUTPUT-
5.write a program to find out whether a number
is even or odd.
SOURCE CODE-
#include<stdio.h>
int main()
{
int n;
printf("enter a number");
scanf("%d",&n);
if(n%2==0)
{
printf("even");
}
else
{
printf("odd");
}
return 0;
}
OUTPUT-
6.write a program to find sum of first n natural
number.
SOURCE CODE-
#include<stdio.h>
int main()
{
int n,sum=0,i;
printf("enter the number");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("%d",sum);
return 0;
}
OUTPUT-
7.Write a program to print a table of 5.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i;
printf("enter table of five\n");
for(i=1;i<=10;i++)
{
printf("%d\n",5*i);
}
return 0;
}
OUTPUT-
8.Write a program to print first 20 even numbers
.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i;
printf("enter first 20 even numbers\n");
for(i=1;i<=20;i++)
{
if(i%2==0)
{
printf("%d\n",i);
}}
return 0;
}
OUTPUT-

9.Write a program to print first 20 odd numbers.


SOURCE CODE-
#include<stdio.h>
int main()
{
int i;
printf("enter first 20 odd numbers\n");
for(i=1;i<=20;i++)
{
if(i%2==1)
{
printf("%d\n",i);
}}
return 0;
}
OUTPUT-

10.Write a program to print a table with the help of


while loop.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i=1,n;
printf("enter the number\n");
scanf("%d",&n);
printf("table of number\n");
while(i<=10)
{
printf("%d\n",n*i);
i++;
}
return 0;}
OUTPUT-
11.Write a program to find out whether the number is
prime or not.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i,n,count=0;
printf("enter a number\n");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
count++;
}
if(count==2)
{
printf("the number is prime");
}
else{printf("the number is not prime");
}
return 0;}
OUTPUT-

12.Write a program to print number from 1 to 10


while break statement.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i;
printf("enter a number\n");
for(i=1;i<=10;i++)
{
printf("%d\n",i);
if(i==5)
break;
}
return 0;
}
OUTPUT-

13.write a program to print a table of 9 while continue


statement.
SOURCE CODE-
#include<stdio.h>
int main()
{
int i;
printf("enter table of 9\n");
for(i=1;i<=10;i++)
{
if(i==5)
continue;
printf("%d\n",9*i);
}
return 0;
}
OUTPUT-

14.Write a program to find sum of array.


SOURCE CODE-
#include<stdio.h>
int main()
{
int a[9]={3,6,9,7,6,3,4,6,7},sum=0,i;
printf("sum of array\n");
for(i=0;i<9;i++)
{
sum=sum+a[i];
}
printf("%d",sum);
return 0;
}
OUTPUT-

15.Write a program to find out maximum from an


array.
SOURCE CODE-
#include<stdio.h>
int main()
{
int a[8]={2,7,5,6,3,4,6,9},i,max;
printf("maximum number from an array\n");
max=a[0];
for(i=0;i<8;i++)
{
if(a[i]>max)
max=a[i];
}
printf("%d",max);
return 0;
}
OUTPUT-

You might also like