0% found this document useful (0 votes)
23 views16 pages

Practice Codes

Uploaded by

Yash Kamble
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)
23 views16 pages

Practice Codes

Uploaded by

Yash Kamble
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/ 16

EFEST CODES

1 .#include<iostream.h>

#include<conio.h>

#include<stdio.h>

void main()

cout<<"\n print a welcome text in a seperate line:\n";

cout<<"--------------------------------------------\n";

cout<<"welcome to \n";

cout<<"efest compitition"<<endl;

getch();

2.

#include<stdio.h>

#include<conio.h>

void main()

int a, b, c, s
clrscr();

printf("Enter a number:\t");

scanf("%d", &a);

c = a;

// the number is reversed inside the while loop.

while(a > 0)

b = a%10;

s = (s*10)+b;

a = a/10;

// here the reversed number is compared with the given number.

if(s == c)

printf("The number %d is a palindrome", c);

else

printf("The number %d is not a palindrome", c);

getch();

}
3.

// C++ implementation of above approach

#include <bits/stdc++.h>

using namespace std;

/* Function to print product array

for a given array arr[] of size n */

void productArray(int arr[], int n)

// Base case

if (n == 1) {

cout << 0;

return;

/* Allocate memory for temporary

arrays left[] and right[] */

int* left = new int[sizeof(int) * n];

int* right = new int[sizeof(int) * n];

/* Allocate memory for the product array */

int* prod = new int[sizeof(int) * n];

int i, j;
/* Left most element of left

array is always 1 */

left[0] = 1;

/* Right most element of right

array is always 1 */

right[n - 1] = 1;

/* Construct the left array */

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

left[i] = arr[i - 1] * left[i - 1];

/* Construct the right array */

for (j = n - 2; j >= 0; j--)

right[j] = arr[j + 1] * right[j + 1];

/* Construct the product array using

left[] and right[] */

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

prod[i] = left[i] * right[i];

/* print the constructed prod array */

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

cout << prod[i] << " ";


return;

/* Driver code*/

int main()

int arr[] = { 10, 3, 5, 6, 2 };

int n = sizeof(arr) / sizeof(arr[0]);

cout << "The product array is: \n";

productArray(arr, n);

}
4.

#include <iostream>

using namespace std;

int main() {

int n;

cout << "Enter a positive integer: ";

cin >> n;

// run a loop from 1 to 10

// print the multiplication table

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

cout << n << " * " << i << " = " << n * i << endl;

return 0;

}
5
#include <stdio.h>

void pattern_fun(int row)

// To iterate through the rows

for (int j = 1; j <= row; j++)

// To print the beginning spaces

for (int sp = 1; sp <= j - 1; sp++)

printf(" ");

// Iterating from jth column to

// last column (row*2 - (2*j - 1))

int last_col = (row * 2 - (2 * j - 1));

// To iterate through column

for (int k = 1; k <= last_col; k++)

// To Print all star for first

// row (j==1) jth column (k==1)

// and for last column

// (row*2 - (2*j - 1))

if (j == 1 || k == 1)

printf("*");

else if (k == last_col)

printf("*");

else

printf(" ");

// Proceeding to next row.


printf("\n");

// Driver code

int main()

// Number of rows

int row = 7;

// Calling the function to

// print the pattern.

pattern_fun(row);

return 0;

6.

#include <stdio.h>
// C function to find maximum

// in arr[] of size n

int largest(int arr[], int n)

int i;

// Initialize maximum element

int max = arr[0];

// Traverse array elements from

// second and compare every

// element with current max

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

if (arr[i] > max)

max = arr[i];

return max;

// Driver code

int main()

int arr[] = { 10, 324, 45, 90, 9808 };

int n = sizeof(arr) / sizeof(arr[0]);

printf("Largest in given array is %d", largest(arr, n));

return 0;

}
7.

#include <stdio.h>

int main()

int month;

int days;

printf("Enter month: ");

scanf("%d",&month);

switch(month)

case 4:

case 6:

case 9:

case 11:

days=30;

break;

case 1:

case 3:

case 5:

case 7:

case 8:

case 10:

case 12:

days=31;

break;

case 2:
days=28;

break;

default:

days=0;

break;

if(days)

printf("Number of days in %d month is: %d\n",month,days);

else

printf("You have entered an invalid month!!!\n");

return 0;

8.

#include<stdio.h>

int main()

//declare the variable

int count;
char name[50];

//input value of name

printf("Enter the name: ");

scanf("%s",name);

//counter initialization with 1

count=1;

//defining lable

start:

printf("%s, ",name);

count++;

if(count<=10)

goto start;

return 0;

9.

#include <stdio.h>

int main() {
//loop counter or a variable that

//will store initial alphabet,

//from where we will print the alphabets

char alphabet;

//assigning 'A' as initial alphabet

alphabet = 'A';

//print statement

printf("Uppercase alphabets:\n");

//loop statement, that will check the condition

//and print the alphabets from 'A' to 'Z'

while (alphabet <= 'Z') {

//printing the alphabets

printf("%c ", alphabet);

//increasing the value by 1

alphabet++;

return 0;

10.
// C++ program to find sum of series

#include <iostream>

using namespace std;

// Function to return sum of

// 1/1 + 1/2 + 1/3 + ..+ 1/n

class gfg

public : double sum(int n)

double i, s = 0.0;

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

s = s + 1/i;

return s;

};

// Driver code

int main()

gfg g;

int n = 5;

cout << "Sum is " << g.sum(n);

return 0;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy