Skip to content

Yogaprasadmk/Prepinsta_Top_100_Codes

Repository files navigation

Below You will find some of the most important codes in languages like C, C++ and Java,Python. These codes are of prime importance for college semester exams and also for various online tests and interviews of the companies offering placements within varying range in LPA.These codes are very important since these will help you clear your basic concepts in various languages.


Getting Started

Introduction to Top 100 codes



Question 1: Positive or Negative Numbers

#include <stdio.h>
int main()
{
    int a;
    printf("Enter a:");
    scanf("%d",&a);
    if(a>0){
        printf("positive");
    }
    else if(a < 0){
        printf("negative");
    }
    else {
        printf("zero");
    }
    return 0;
}

Question 2: Even or odd numbers

#include <stdio.h>

int main()
{
    int n;
    printf("Enter n:");
    scanf("%d",&n);
    if(n%2==0){
        printf("even");
    }
    else{
        printf("odd");
    }
return 0;
}

Question 3: Sum of first natural numbers

#include<stdio.h>
int main(){
    int n;
    printf("Enter n:");
    scanf("%d",&n);
    int s;
    s = n * (n + 1) / 2;
    printf("The Sum of Natural Number: %d",s);
    return 0;
}

Question 4: Sum of Natural numbers

#include<stdio.h>
int main(){
    int n;
    printf("Enter n:");
    scanf("%d",&n);
    int a;
    a = n * (n + 1) / 2;
    printf("The Sum of Natural Number: %d",a);
    return 0;
}

Question:5 Sum of given range number

print("Enter N:")
N = int(input())
print("Enter S:")
S = int(input())
sum = 0;
for i in range(N,S):
    sum = sum + i

print(sum)

Question 6:Greatest of two numbers

print("enter a:")
a= int(input())
print("Enter b:")
b = int(input())
if(a>b):
print("a is greater")
else:
print("b is greater")

Question 7: Greatest of three number

#include <stdio.h>

int main()
{
    int a,b,c;
    printf("Enter A:");
    scanf("%d",&a);
    printf("Enter B:");
    scanf("%d",&b);
    printf("Enter C:");
    scanf("%d",&c);
    if(b<a && c<a){
        printf("A is greater");
    }
    else if(a<b && c<b){
        printf("B is greater");
    }
    else{
        printf("C is greater");
    }
    return 0;
}

Question 8: LeapYear or not

leap = int(input("Enter Leap Year"))
if(leap%4==0):
    print("Leap Year")
else:
    print("Not a leap year")

Question 9: Prime Numbers

#include <stdio.h>

int main()
{
    int n;
    printf("Enter N:");
    scanf("%d",&n);
    int divide;
    printf("Enter Div:");
    scanf("%d",&divide);
    while(divide<n)
    {
        if(n%divide==0)
        {
            printf("Not Prime");
            break;
        }
        else{
            divide = divide + 1;
            printf("Prime");
            break;
        }
    }
    return 0;
}

🌟FLowchart and Pseudocode for Primenumbers

Questio 10:Sum of Digits

public class Main{
    public static void main (String[] args) {
         int a = 123;
         int count = 0;
         int lastdigit = 0;
        while(a>0){
             
            lastdigit = a % 10;
            
            count = lastdigit + count;
            
            a = a/ 10;
        }
        System.out.println(count);
         
    }
}

🌟Pseudocode:

Question 11: Reverse Number

public class ReverseNumber
{
	public static void main(String[] args) {
	    
	    int a = 6789;
	    int dup = 0;  // duplicate
	    int lastdigit = 0;
	    while(a>0){
	        lastdigit = a % 10;
	        dup = (dup * 10) + lastdigit;
	        a = a / 10;
      }
	    if(dup != a){
	        System.out.println("Reverse Number: "+ dup);
	    }
	    else{
	        System.out.println("Not a Reverse Number: "+ dup);
	    }
	}
}

Question 12: Palindrome Number

public class Palindrome
{
	public static void main(String[] args) {
		int number = 1221;
		int dup = 0;
		int lastdigit = 0;
		int temp = number;
		while(temp > 0){
		    lastdigit = temp % 10;
		    dup = (dup * 10) + lastdigit;
		    temp = temp / 10;
		}
		if(number == dup){
		    System.out.println(dup + " is Palindrome");
		}
		else{
		    System.out.println(dup + "Is not Palindrome");
		}
	}
}

Question 13: Armstrong Number

public class Main
{
	public static void main(String[] args) {
		int a = 153;
		int dup = a;
		int sum = 0;
		int lastdigit = 0;
		while (a>0){
		    lastdigit = a % 10;
		    sum = sum + (lastdigit* lastdigit * lastdigit);
		    a = a / 10;
		}
		if(sum == dup){
		    System.out.println("Armstrong nUmber");
		}
		else{
		    System.out.println("NOt Armstrong number");
		}
	}
}

Pseudocode

About

The PrepInsta Top 100 codes solutions will be available here.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published