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

Ppa Pratical Programs For Algorithm

Uploaded by

hypergamer.15y
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)
75 views

Ppa Pratical Programs For Algorithm

Uploaded by

hypergamer.15y
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

1. Wap to print your full Name.

Ans :- #include<stdio.h>
#include<conio.h>
int main()
{
printf(“Abhishek sharma”);
}
getch();
2. Wap to add to numbers.
Ans:-#include <stdio.h>
int main() {
int number1, number2, sum;
printf(“Enter two integers: “);
scanf(“%d %d”, &number1, &number2);
sum = number1 + number2;
printf(“%d + %d = %d”, number1, number2, sum);
return 0;
}
3. Wap to calculate Average of 5 numbers.
Ans:- #include<stdio.h>
int main() {
int a=10, b=20, c=30, d=40, e=50;
int f=(a+b+c+d+e)/5;
printf(“the average value of given number is %d\n”,f);
return 0;
}
4. Wap to multiply three numbers.
Ans:- int main()
{
int a,b,c,d;
printf(“Enter 1st no “);
scanf(“%d”,&a);
printf(“Enter 2nd no “);
scanf(“%d”,&b);
printf(“Enter 3rd no “);
scanf(“%d”,&c);
d=a*b*c;
printf(“Product = %d”,d);
return 0;
}
5.Wap to print area of circle.
Ans:- #include <stdio.h>
#include <math.h>
int main()
{
float radius, area;
printf(“Enter the radius of a circle\n”);
scanf(“%f”, &radius);
area = 3.14159*radius*radius;
printf(“Area of the circle = %.2f\n”, area);
return 0;
}
5. Wap to print the biggest of three numbers.
Ans:- #include <stdio.h>
int main()
{
int num1, num2, num3;
printf(“ Enter the number1 = “);
scanf(“%d”, &num1);
printf(“\n Enter the number2 = “);
scanf(“%d”, &num2);
printf(“\n Enter the number3 = “);
scanf(“%d”, &num3);
if (num1 >= num2 && num1 >= num3)
{
printf(“\n %d is the largest number.\n”, num1);
}
if (num2 >= num1 && num2 >= num3)
{
printf(“\n %d is the largest number.\n”, num2);
}
if (num3 >= num1 && num3 >= num2)
{
printf(“\n %d is the largest number.\n”, num3);
}
return 0;
}
7. Wap to check given no. is even or odd.
Ans:- #include <stdio.h>
int main() {
int num;
printf(“Enter an integer: “);
scanf(“%d”, &num);
if(num % 2 == 0)
printf(“%d is even.”, num);
else
printf(“%d is odd.”, num);
return 0;
}
6. Wap to check given number. Is positive or negative.
Ans:- #include <stdio.h>
int main()
{
int num = 23;
if (num> 0)
printf(“The number is positive”);
else if (num< 0)
printf(“The number is negative”);
else
printf(“Zero”);
return 0;
}
9. Wap to given year is leap or not.
Ans:- #include <stdio.h>
int main(){
int y;
printf(“Enter the year to check: “);
scanf(“%d”,&y);
if (((y % 4 == 0) && (y % 100!= 0)) || (y%400 == 0))
printf(“It is a leap year”);
else
printf(“It is not a leap year”);
return 0;
}
10. Wap to print the name of month according to user’s choice.
Ans:- #include <stdio.h>
void main()
{
int monno;
printf(“Input Month No : “);
scanf(“%d”,&monno);
Switch(monno)
{
Case 1:
printf(“January\n”);
break;
Case 2:
printf(“February\n”);
break;
Case 3:
printf(“March\n”);
break;
Case 4:
printf(“April\n”);
break;
Case 5:
printf(“May\n”);
break;
Case 6:
printf(“June\n”);
break;
Case 7:
printf(“July\n”);
break;
Case 8:
printf(“August\n”);
break;
Case 9:
printf(“September\n”);
break;
Case 10:
printf(“October\n”);
break;
Case 11:
printf(“November\n”);
break;
Case 12:
printf(“December\n”);
break;
default:
printf(“Invalid Month number. \nPlease try again ….\n”);
break;
}
}
11. Wap to print 1 to 10 no.by using while loop.
Ans:- #include <stdio.h>
int main()
{
int number;
number =1;
printf(“Numbers from 1 to 10: \n”);
while(number<=10)
{
printf(“%d “,number);
number++;
}
return 0;
}
12. Wap to print 1 to 100 no. by using Do while loop.
Ans:- #include<stdio.h>
int main() {
int a = 1;
Do {
printf(“%d“,a);
a++;
} while(a<= 100);
return 0;
}
13. Wap to print 100 to 1 no. by using for loop.
Ans= #include<stdio.h>
#include<conio.h>
void main()
{
int n;
clrscr();
printf(“\n”);
for(n=100;n>=1;n--)
{
printf(“ %d”,n);
}
getch()
}
14. Wap to swap two numbers using third variable.
Ans:- #include<stdio.h>
#include<conio.h>
void main() {
int a, b, tempvar;
printf(“enter the value of a: “);
scanf(“%d”, & a);
printf(“enter the value of b: “);
scanf(“%d”, & b);
tempvar = a;
a = b;
b = tempvar;
printf(“After swapping \n”);
printf(“value of a is : %d \n”, a);
printf(“value of b is : %d “, b);
getch();
}
15. Wap to swap two numbers without using third variable.
Ans= #include<stdio.h>
int main()
{
int a=10, b=20,A, B,C;
printf(“Before swap a=%d b=%d”,a,b);
A=a+b;
B=a-b;
C=a-b;
printf(“\nAfter swap a=%d b=%d”,a,b);
return 0;
}
16. Wap to calculate the factorial of given number.
Ans:- #include<stdio.h>
int main()
{
int i,fact=1,number;
printf(“Enter a number: “);
scanf(“%d”,&number);
for(i=1;i<=number;i++){
fact=fact*I;
}
printf(“Factorial of %d is: %d”,number,fact);
return 0;
}
17. Wap to print Fibonacci series.
Ans:- #include<stdio.h>
int main()
{
int N1=0,N2=1,N3,I,number;
printf(“Enter the number of elements:”);
scanf(“%d”,&number);
printf(“\n%d %d”,n1,n2);//printing 0 and 1
for(i=2;i<number;++i)
{
N3=n1+n2;
printf(“ %d”,n3);
N1=n2;
N2=n3;
}
return 0;
}
18. Wap to print the Table of given number.
Ans:- #include <stdio.h>
int main()
{
int num, I;
printf (“ Enter a number to generate the table in C: “);
scanf (“ %d”, &num);
printf (“\n Table of %d”, num);
for ( I = 1; I <= 10; i++)
{
printf (“\n %d * %d = %d”, num, I, (num*i));
}
return 0;
}
19. Wap to print reverse of a number.
Ans :- #include<stdio.h>
int main()
{
int n, reverse=0, rem;
printf(“Enter a number: “);
scanf(“%d”, &n);
while(n!=0)
{
rem=n%10;
reverse=reverse*10+rem;
n/=10;
}
printf(“Reversed Number: %d”,reverse);
return 0;
}
20. Wap to print given no. Is Armstrong or not.
Ans:- #include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf(“enter the number=”);
scanf(“%d”,&n);
temp=n;
while(n>0)
{
r=n%10;
sum=sum+(r*r*r);
n=n/10;
}
if(temp==sum)
printf(“armstrong number “);
else
printf(“not armstrong number”);
return 0;
}
21. Wap to print odd number. Between 1 to 50.
Ans:- #include <stdio.h>
int main(){
int I;
printf(“Odd Numbers Between 1 To 50 are: \n”);
for (I = 1; I <= 50; ++i){
if (I % 2 != 0){
printf(“%d\n”, i);
}
}
return 0;
}
22. Wap to check given number is prime or not.
Ans:- #include <stdio.h>
#include <math.h>
int main() {
int n, I, c = 0;
printf(“Enter any number: “);
scanf(“%d”, &n);
if (n <= 1) {
printf(“%d is not a Prime number.\n”, n);
return 0;
}
for (I = 2; I <= sqrt(n); i++) {
if (n % I == 0) {
c++;
break;
}
}
if (c == 0) {
printf(“%d is a Prime number.\n”, n);
} else {
printf(“%d is not a Prime number.\n”, n);
}
return 0;
}
23. Wap to check number is palindrome or not.
Ans:- #include<stdio.h>
int main()
{
int n,r,sum=0,temp;
printf(“enter the number=”);
scanf(“%d”,&n);
temp=n;
while(n>0)
{
r=n%10;
sum=(sum*10)+r;
n=n/10;
}
if(temp==sum)
printf(“palindrome number “);
else
printf(“not palindrome”);
return 0;
}
24. Wap to calculate simple intrest.
Ans:- # include <conio.h>
# include <stdio.h>
int main(){
int principal, rate, time, interest;
printf(“Enter the principal: “);
scanf(“%d”, &principal);
printf(“Enter the rate: “);
scanf(“%d”, &rate);
printf(“Enter the time: “);
scanf(“%d”, &time);
interest = principal * rate * time / 100;
printf(“The Simple interest is %d”, interest);
return 0;
}
25. Wap to find ASCII Value.
Ans:- #include <stdio.h>
int main()
{
char c;
printf(“Enter any character “);
scanf(“%c”,&c);
printf(“\nThe ASCII value of the entered character is: %d”, c);
return 0;
}
26. Wap to print area of rectangle.
Ans:- #include <stdio.h>
int main(){
int length, breadth, area;
printf(“Enter the length of the rectangle: “);
scanf(“%d”, &length);
printf(“Enter the breadth of the rectangle: “);
scanf(“%d”, &breadth);
area = length * breadth;
printf(“Area of the Rectangle: %d”, area);
return 0;
}
27. Wap to check whether a person is eligible to vote or not.
Ans:- #include <stdio.h>
int main(){
int age;
printf(“Enter age : “);
scanf(“%d”, &age);
if (age >= 18)
printf(“You can Vote!”);
else
printf(“You can’t Vote!”);
return 0;
}
28. Wap to check division of students.
Ans:- #include<stdio.h>
#include<conio.h>
void main()
{
int per;
printf(“Enter the per”);
scanf(“%d”,&per);
if(per<33)
{
printf(“fail”);
}
else if(per>=33&&per<45)
{
printf(“passed third division”);
}
else if(per>45&&per<60)
{
printf(“passed second division”);
}
else if(per>60&&per<75)
{
printf(“passed first division”);
}
else if(per>75&&per<100)
{
printf(“first division with honors”);
}
else
{
printf(“invalid input”);
}
getch();
}
29. Wap to create a calculator using switch case.
Ans:- #include<stdio.h>
int main ()
{
int num1, num2;
float result;
char ch;
printf (“Enter first number = “);
scanf (“%d”, &num1);
printf (“Enter second number = “);
scanf (“%d”, &num2);
printf (“Choose operator to perform operations = “);
scanf (“ %c”, &ch);
result = 0;
Switch (ch)
{
Case ‘+’:
result = num1 + num2;
break;
Case ‘-‘:
result = num1 – num2;
break;
Case ‘*’:
result = num1 * num2;
break;
Case ‘/’:
result = num1 / num2;
break;
default:
printf (“Invalid operation\n”);
}
printf (“Result: %d %c %d = %f\n”, num1, ch, num2, result);
return 0;
}
30. Wap to add two numbers using function.
Ans:-#include <stdio.h>
int add(int a, int b);
int add(int a, int b) {
return a + b;
}
int main() {
int result = add(2, 3);
printf(“The result is %d\n”, result);
return 0;
}

You might also like