Posts

Showing posts from October, 2019

Ques WAP for exception handling to check user age is eligible to vote or not in java?

Image
import java.util.Scanner;   class AgeException extends Exception {     public AgeException(String str) {   System.out.println(str);   } } public class AgeExcDemo {   public static void main(String[] args) { Scanner s = new Scanner(System.in); System.out.print("Enter Your Age :: "); int age = s.nextInt();   try { if(age < 18)  throw new AgeException("You Are Not Eligible To Vote"); else System.out.println("You Are Eligible  To Vote");   }   catch (AgeException a) { System.out.println(a);   }  } } Download Code  //Output :

C Program For Memory Allocation With Calloc And Free

Image
#include<stdio.h> #include<stdlib.h> #include<conio.h> #include<windows.h> void main(){ int* ptr; int n,i; system("cls"); printf("\n\t\tProgram Of Calloc With Free "); printf("\n\t\tEnter Number of Elements : "); scanf("%d",&n); ptr=(int*) calloc(n,sizeof(int)); if(ptr==NULL){ printf("\n\t\tMemory Not Allocated "); exit(0); }else{ printf("\n\t\tMemory Is Allocated"); printf("\n\t\tGetting elements....."); for (i=0;i<n;i++){ printf("\n\t\t%d : ",i+1); scanf("%d",&ptr[i]); } printf("\n\t\tPrinting Elements\n"); for(i=0;i<n;i++){ printf("\n\t\t%d",ptr[i]); } } free(ptr); printf("\n\n\t\tMemory Free In Calloc\n"); getch(); } //Output: