Sie sind auf Seite 1von 11

Q1. Write a C code to display the following text on the screen. MCA 103:Programming in C Ans #include<stdio.

h> int main() { printf("\n MCA 103: Programming in C\n"); return 0; }

Q2.To input one integer from the user and display it . Ans #include<stdio.h> int main() { int num; printf("\nenter the number\n"); scanf("%d",&num); printf(" \nyou enter the number %d\n",num); return 0; }

Q3. to input age from the user and display voting eligibility criteria. Ans #include<stdio.h> void main() { int age; printf("sir \n please enter your age:"); scanf("%d",&age); if(age>=18) { printf("\nyou are eligible to vote\n"); } else printf("\nsorry you are not eligible to vote\n"); }

Q4.To display natural number from 1 to 10. Ans. #include<stdio.h> void main() { char temp; int i =1; printf("\nDo you want to print natural no : y/n\n"); scanf("%c",&temp); if(temp=='y') { printf("\nprinting natural no :"); while(i<=10) { printf("\n%d",i++); } } else printf("\nhave a gud day"); }

Q5.To input lower limit and final limit from user and display natural numbers between them. Ans. #include<stdio.h> void main() { char temp; int l,f; printf("\nenter the lower limit"); scanf("%d",&l); printf("\nenter the final limit"); scanf("%d",&f); printf("\n-----printing natural no------"); while(l<=f) { printf("\n%d",l++); } }

Q6.To input three number from the user and display the largest no among them. Ans #include<stdio.h> main() { int num1,num2,num3; printf("enter the three numbers"); scanf("%d%d%d",&num1,&num2,&num3); if(num1>num2&&num1>num3) printf("\n%dis the largest",num1); else if(num2>num1&&num2>num3) printf("\n%d is largest",num2); else printf("\n%d is largest",num3); }

Q7.To input one number from the user and display the corresponding day of the week. Ans #include<stdio.h> main() { int num,day; printf("enter the number"); scanf("%d",&num); switch(num) { case 1:printf("\nthis is sunday"); break; case 2:printf("\nthis is monday"); break; case 3:printf("\nthis is tuesday"); break; case 4:printf("\nthis is wednesday"); break; case 5:printf("\nthis is thursday"); break; case 6:printf("\nthis is friday"); break; case 7:printf("\nthis is saturday"); break; default:printf("\ninvalid no."); break; } }

Q8.To input lower limit and final from the user and display all even number between them. Ans #include<stdio.h> void evenum(int intial,int limit) { int i; i= intial; printf("the even no among all are:"); do { if(i%2==0) { printf("\n %d",i); } i++; }while(i<=limit); } void main() { int intial; int limit ; printf("Enter the initial limit for the number series"); scanf("%d",&intial); printf("Enter the final limit for the number series"); scanf("%d",&limit); evenum(intial,limit); }

Q9.To input lower limit and final limit from the user and display all odd numbers b/w them. Ans #include<stdio.h> void oddnum(int intial,int limit) { int i; i=intial; while(i<=limit) { if(i%2!=0) { printf("\n %d",i); } i++; } } void main() { int intial; int limit ; printf("Enter the lower limit for the odd number series"); scanf("%d",&intial); printf("Enter the final limit for the odd number series"); scanf("%d",&limit); oddnum(intial,limit); }

Q10. Any iteration program to show the usage of Break and Continue Keywords. Ans _________ __Program using Break keyword___________________ #include<stdio.h> main() { int num,i,flag=0; printf("\n enter the number"); scanf("%d",&num); for(i=2;i<=num-1;i++) { if(num%i==0) { flag=0; printf("\n%d is not a prime number",num); break; } else flag=1; } if(flag==1) printf("\n%d is a prime number",num); }

--------------------------Program using Continue Keyword----------------------#include<stdio.h> main() { int i,j,k; printf("all combination of 123 are"); for(i=1;i<=3;i++) { for(j=1;j<=3;j++) { for(k=1;k<=3;k++) { if(i==j||j==k||k==i) continue; else printf("\n%d%d%d",i,j,k); } } } }