1. Write a program to print your name on the screen ?
#include<stdio.h>
int main(){
printf("Suresh Yadav");
return 0;
}
2. WAP to display a number from user ?
#include<stdio.h>
int main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);
printf("The entered number is %d",a);
return 0;
}
3. WAP to display name and address from user ?
#include<stdio.h>
int main()
{
char name[20];
char address[10];
printf("Enter your first name: ");
scanf("%s",&name);
printf("Enter your address: ");
scanf("%s",&address);
printf("Name = %s\n",name);
printf("Address = %s",address);
return 0;
}
4. WAP to convert kilometer into meter ?
#include<stdio.h>
int main()
{
int km,result;
printf("Enter the length in kilometer: ");
scanf("%d",&km);
result=km*1000;
printf("%d kilometer = %d meter",km,result);
return 0;
}
5. WAP to print multiplication table ?
#include<stdio.h>
int main()
{
int a,i,result;
printf("Enter any number:");
scanf("%d",&a);
printf("The multiplication table of %d is given below:",a);
for(i=1;i<=10;i++)
{
result=a*i;
printf("\n%d * %d = %d",a,i,result);
}
return 0;
}
6. WAP using If else statement ?
#include<stdio.h>
int main()
{
int age;
printf("Enter your age: ");
scanf("%d",&age);
if(age<18)
{
printf("You are not eligible to cast vote.");
}
else
{
printf("You are eligible to cast vote.");
}
return 0;
}
7. WAP to calculate percentage ?
#include<stdio.h>
int main()
{
float obt,tot,percentage;
printf("Enter the total marks: ");
scanf("%f",&tot);
printf("Enter your obtained marks: ");
scanf("%f",&obt);
percentage=(obt/tot)*100;
printf("Congratulation, you have obtained %f\%",percentage);
return 0;
}
8. Input total marks and obtained marks from user then find his/her percentage and print the information if s/he has obtained percentage : Above 90 - Outstanding 80-90 - Distinction 60 - 80 - First Division 45-60 - Second Division 32-45 - Third Division Below 32 - Better for next time
#include<stdio.h>
int main()
{
float obt,tot,percentage;
float GPA;
printf("Enter total marks: ");
scanf("%f",&tot);
printf("Enter your obtained marks: ");
scanf("%f",&obt);
percentage=(obt/tot)*100;
printf("You have got %f percent\n",percentage);
if(percentage>=90)
{
printf("Outstanding");
}
else if(percentage>80 && percentage<=90)
{
printf("Distinction");
}
else if(percentage<80 && percentage>=60)
{
printf("First Division");
}
else if(percentage<60 && percentage>40)
{
printf("Second Division");
}
else if(percentage<45 && percentage>=32)
{
printf("Third Division");
}
else
{
printf("You have got a chance to give exam again");
}
GPA=percentage/25;
printf("\nGPA = %f",GPA);
return 0;
}
9. WAP to find area of rectangle, circle, cube and sphere ?
#include<stdio.h>
#include<conio.h>
int main()
{
int length,breadth,area,ch;
float result,radius;
do{
printf("1.Rectangle\n2.Circle\n3.Cube\n4.Sphere\n");
printf("Enter your choice: ");
scanf("%d",&ch);
if(ch==1)
{
printf("Enter length: ");
scanf("%d",&length);
printf("Enter breadth: ");
scanf("%d",&breadth);
area=length*breadth;
printf("The area is %d",area);
}
else if(ch==2)
{
printf("Enter the radius of circle: ");
scanf("%f",&radius);
result=3.14*radius*radius;
printf("The area of circle is %f",result);
}
else if(ch==3)
{
printf("Enter the length of cube: ");
scanf("%d",&length);
area=6*length*length;
printf("The area of cube is %d",area);
}
else if(ch==4)
{
printf("Enter the radius of sphere: ");
scanf("%f",&radius);
result=4*3.14*radius*radius;
printf("The area of sphere is %f",result);
}
else
{
printf("Invalid choice...");
}
getch();
system("cls");
}
while(1!=0);
return 0;
}
10. WAP to calculate simple interest ?
#include<stdio.h>
int main()
{
float p,t,r,sI;
printf("Enter the principle: ");
scanf("%f",&p);
printf("Enter the time: ");
scanf("%f",&t);
printf("Enter the rate: ");
scanf("%f",&r);
sI=(p*t*r)/100;
printf("Simple Interest is %f",sI);
return 0;
}
11. WAP to find odd or even number ?
#include<stdio.h>
int main()
{
int a;
do{
printf("Enter a number: ");
scanf("%d",&a);
if(a%2==0)
{
printf("%d is even number.",a);
}
else
{
printf("%d is odd number.",a);
}
printf("\n\n");
}
while(0!=1);
return 0;
}
12. WAP to find positive or negative number ?
#include<stdio.h>
int main()
{
int a;
printf("Enter a number: ");
scanf("%d",&a);
if(a<0)
{
printf("%d is negetive number.",a);
}
else if(a>0)
{
printf("%d is positive number.",a);
}
else
{
printf("The given number is O");
}
return 0;
}
13. WAP to print the sum of n numbers ?
#include<stdio.h>
int main()
{
int n,i,sum=0;
printf("Enter a number to findout the sum of its N number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
sum=sum+i;
}
printf("The sum of first Nth term is %d",sum);
return 0;
}
14. WAP to make calculator ?
#include<stdio.h>
int main()
{
int num1,num2,result;
char op;
printf("Enter first number: ");
scanf("%d",&num1);
printf("Enter the operation: ");
scanf(" %c",&op);
printf("Enter the second number: ");
scanf("%d",&num2);
switch(op)
{
case '+':result=num1+num2;
break;
case '-':result=num1-num2;
break;
case '*':result=num1*num2;
break;
case '/':result=num1/num2;
break;
default:
printf("Invalid operator");
break;
}
printf("The result is %d",result);
return 0;
}
15. WAP to print reverse number ?
#include<stdio.h>
int main()
{
int n,sum=0,a,b;
printf("Enter the number to reverse: ");
scanf("%d",&n);
while(n!=0)
{
a=n%10;
sum=sum*10+a;
n=n/10;
}
printf("The reverse of %d is %d",n,sum);
return 0;
}
16. WAP to find armstrong number ?
#include<stdio.h>
int main()
{
int n,temp,result=0,cube,a;
printf("Enter a number: ");
scanf("%d",&n);
temp=n;
while(n!=0)
{
a=n%10;
cube=a*a*a;
result=result+cube;
n=n/10;
}
if(result==temp)
{
printf("The number %d is armstrong number.",temp);
}
else
{
printf("The number %d is not armstrong number.",temp);
}
return 0;
}
17. WAP to find pallindrome number ?
#include<stdio.h>
int main()
{
int n,temp,sum=0,a;
printf("Enter a number: ");
scanf("%d",&n);
temp=n;
while(n!=0)
{
a=n%10;
sum=sum*10+a;
n=n/10;
}
if(sum==temp)
{
printf("The number %d is pallindrome number.",temp);
}
else
{
printf("The number %d is not pallindrome number.",temp);
}
return 0;
}
18. WAP to show factorial number ?
#include<stdio.h>
int main()
{
int n,i,result=1;
printf("Enter a number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
result=result*i;
}
printf("The factorial number of %d is %d",n,result);
return 0;
}
19. WAP to show whether the given number is prime or composite ?
#include<stdio.h>
int main()
{
int n,count=0,i;
printf("Enter a number: ");
scanf("%d",&n);
for(i=1;i<=n;i++)
{
if(n%i==0)
{
count++;
}
}
if(count==2)
{
printf("%d is prime number.",n);
}
else
{
printf("%d is composite number.",n);
}
return 0;
}
20. WAP to print all odd numbers upto n number ?
#include<stdio.h>
int main()
{
int a,i,ch;
printf("1. Odd number\n2. Even number\n");
printf("Enter your choice: ");
scanf("%d",&ch);
if(ch==1)
{
printf("Enter a number to show odd numbers till: ");
scanf("%d",&a);
for(i=1;i<=a;i=i+2)
{
printf("%d\t",i);
}
}
else if(ch==2)
{
printf("Enter a number to show odd numbers till: ");
scanf("%d",&a);
for(i=2;i<=a;i=i+2)
{
printf("%d\t",i);
}
}
else
{
printf("Invalid choice.");
}
return 0;
}
21. WAP to find the day of entered number ? For eg: 1 - Sunday 2 - Monday …….. …….. 7 - Saturday
#include<stdio.h>
int main()
{
int a;
printf("Enter the number of day: ");
scanf("%d",&a);
switch(a)
{
case 1:printf("Sunday");
break;
case 2:printf("Monday");
break;
case 3:printf("Tuesday");
break;
case 4:printf("Wednesday");
break;
case 5:printf("Thursday");
break;
case 6:printf("Friday");
break;
case 7:printf("Saturday");
break;
default:printf("Invalid choice");
break;
}
return 0;
}
22. WAP to print given pattern using loop ? 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
23. 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5
#include<stdio.h>
int main()
{
int i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
24. 5 5 5 5 5 4 4 4 4 3 3 3 2 2 1
#include<stdio.h>
int main()
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf("%d",i);
}
printf("\n");
}
return 0;
}
25. 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1
#include<stdio.h>
int main()
{
int i,j;
for(i=5;i>=1;i--)
{
for(j=1;j<=i;j++)
{
printf("%d",j);
}
printf("\n");
}
return 0;
}
26. 1 3 5 7 9 11 13 15 17 19 21 23 25 27 29
#include<stdio.h>
int main()
{
int a=1,i,j;
for(i=1;i<=5;i++)
{
for(j=1;j<=i;j++)
{
printf("%d\t",a);
a=a+2;
}
printf("\n");
}
return 0;
}
27. * * * * * * * * * *
#include<stdio.h>
int main()
{
int i,j,k;
for(i=3;i>=1;i--)
{
for(j=i;j>=1;j--)
{
printf(" ");
}
for(k=i+2;k<=5;k++)
{
printf("*");
}
printf("\n");
}
}
28. WAP to add 10 numbers from user using array ?
#include<stdio.h>
int main()
{
int i,j,n[11],sum=0;
printf("Enter 10 numbers to add them:\n");
for(i=1;i<=10;i++)
{
scanf("%d",&n[i]);
}
for(i=1;i<=10;i++)
{
printf("%d\t",n[i]);
}
for(i=1;i<=10;i++)
{
sum=sum+n[i];
}
printf("The result is %d",sum);
return 0;
}
29. Input 10 numbers randomly from user and arrange them in ascending order ?
#include<stdio.h>
int main()
{
int i,a[10],j,temp;
printf("Enter 10 numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("The numbers are in descending order:");
for(i=0;i<10;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
30. Input 10 numbers randomly from user and arrange them in descending order ?
#include<stdio.h>
int main()
{
int i,a[10],j,temp;
printf("Enter 10 numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
for(i=0;i<10;i++)
{
for(j=0;j<10;j++)
{
if(a[i]<a[j])
{
temp=a[i];
a[i]=a[j];
a[j]=temp;
}
}
}
printf("The numbers are in descending order:");
for(i=0;i<10;i++)
{
printf("%d\t",a[i]);
}
return 0;
}
31. WAP to find largest number from 10 numbers ?
#include<stdio.h>
int main()
{
int i,a[10],j,largest;
printf("Enter 10 numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
largest=a[0];
for(i=0;i<10;i++)
{
if(largest<a[i])
{
largest=a[i];
}
}
printf("The largest number is %d",largest);
return 0;
}
32. WAP to find smallest number from 10 numbers ?
#include<stdio.h>
int main()
{
int i,a[10],j,temp,largest;
printf("Enter 10 numbers:\n");
for(i=0;i<10;i++)
{
scanf("%d",&a[i]);
}
largest=a[0];
for(i=0;i<10;i++)
{
if(largest>a[i])
{
largest=a[i];
}
}
printf("The smallest number is %d",largest);
return 0;
}
33. WAP to add two matrix ?
#include<stdio.h>
int main()
{
int i,j,row,column;
printf("Enter row: ");
scanf("%d",&row);
printf("Enter column: ");
scanf("%d",&column);
int matrix1[row][column],matrix2[row][column],sum[row][column];
if(row==column)
{
printf("Enter first matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
scanf("%d",&matrix1[i][j]);
}
}
printf("Enter second matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
scanf("%d",&matrix2[i][j]);
}
}
printf("First matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
printf("%d\t",matrix1[i][j]);
}
printf("\n");
}
printf("Second matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
printf("%d\t",matrix2[i][j]);
}
printf("\n");
}
// sum of matrix
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
sum[i][j]=matrix1[i][j]+matrix2[i][j];
}
}
printf("The sum of matrices is given below:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
printf("%d\t",sum[i][j]);
}
printf("\n");
}
}
else
{
printf("Addition is not possible.");
}
return 0;
}
34. WAP to subtract two matrix ?
#include<stdio.h>
int main()
{
int i,j,row,column;
printf("Enter row: ");
scanf("%d",&row);
printf("Enter column: ");
scanf("%d",&column);
int matrix1[row][column],matrix2[row][column],sub[row][column];
if(row==column)
{
printf("Enter first matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
scanf("%d",&matrix1[i][j]);
}
}
printf("Enter second matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
scanf("%d",&matrix2[i][j]);
}
}
printf("First matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
printf("%d\t",matrix1[i][j]);
}
printf("\n");
}
printf("Second matrix:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
printf("%d\t",matrix2[i][j]);
}
printf("\n");
}
// sub of matrix
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
sub[i][j]=matrix1[i][j]-matrix2[i][j];
}
}
printf("The difference of matrices is given below:\n");
for(i=1;i<=row;i++)
{
for(j=1;j<=column;j++)
{
printf("%d\t",sub[i][j]);
}
printf("\n");
}
}
else
{
printf("Subtraction is not possible.");
}
return 0;
}
35. WAP to find the length of the string ?
#include<stdio.h>
#include<string.h>
int main()
{
char name[20];
int len;
printf("Enter your first name: ");
scanf(" %s",name);
len=strlen(name);
printf("Your name contains %d letter",len);
return 0;
}
36. WAP to compare two string using (strcmp) function which is already defined in (string.h) header file ?
#include<stdio.h>
int main()
{
char name[20],rename[20];
printf("Enter your first name: ");
scanf(" %s",name);
printf("Re-enter your first name: ");
scanf(" %s",rename);
if(strcmp(name,rename)==0)
{
printf("Congratulation, your name is matched.");
}
else
{
printf("Sorry, name does not match.");
}
return 0;
}
37. WAP to reverse a string using (strrev) ?
#include<stdio.h>
int main()
{
char name[20];
printf("Enter your first name: ");
scanf(" %s",name);
strrev(name);
printf("The reverse of your name is %s",name);
return 0;
}
38. WAP to show whether the entered string is pallindrome or not ?
#include<stdio.h>
int main()
{
char name[20],temp[20];
printf("madam is pallindrome word. \n");
printf("Enter any word to check whether it is pallindrome or not: ");
scanf(" %s",name);
strcpy(temp,name);
if(strcmp(temp,strrev(name))==0)
{
printf("The entered word is pallindrome.");
}
else
{
printf("The entered word is not pallindrome.");
}
return 0;
}
39. WAP to print name in alphabetical order ?
#include<stdio.h>
int main()
{
char name[20] [20],temp[20];
int i,j;
printf("Enter name of 10 students:\n");
for(i=0;i<10;i++)
{
scanf("%s",name[i]);
}
for(i=0;i<10;i++)
{
for(j=i+1;j<10;j++)
{
if(strcmp(name[i],name[j])>0)
{
strcpy(temp,name[i]);
strcpy(name[i],name[j]);
strcpy(name[j],temp);
}
}
}
printf("The name of students in alphabetical order is given below:\n");
for(i=0;i<10;i++)
{
printf("%s\n",name[i]);
}
return 0;
}
40. WAP to print year, month, day in a given number ?
#include<stdio.h>
#include<conio.h>
main()
{
int end,numdays,year=0,month=0,day=0,remmonth=0,remday=0;
do
{
system("cls");
printf("Enter a number to find year,month,day in that number:\n");
printf("If you want to exit then press '0' :\n\n");
printf("Enter a number:");
scanf("%d",&numdays);
if(numdays==0)
exit(0);
if(numdays>=365)
{
year=numdays/365;
remmonth=numdays-(year*365);
month=remmonth/30;
remday=numdays-(year*365)-(month*30);
day=remday;
}
else if(numdays<365)
{
year=numdays/365;
month=numdays/30;
day=numdays-(month*30);
}
printf("The year is %d\n",year);
printf("The month is %d\n",month);
printf("The day is %d\n\n",day);
printf("Press Enter,");
getch();
}
while(1!=0);
return 0;
}
41. Bank management
#include<stdio.h>
#include<conio.h>
main()
//main start
{
int year,month,day,result=-1,Day=5,dividedyear,twodigit,yearcode,exit1;
//converting B.S into A.D
do
//loop start
{
printf("Enter any date in A.D to findout the day:\n");
printf("Enter year:");
scanf("%d",&year);
printf("Enter month:");
scanf("%d",&month);
printf("Enter day:");
scanf("%d",&day);
twodigit=year%100;
dividedyear=twodigit/4;
if(month<=12 && day<=32)
//if statement start
{
if(year<=3000 && year>=2000)
{
yearcode=(-1);
}
else if(year<=1999 && year>=1900)
{
yearcode=(0);
}
else if(year<=1899 && year>=1800)
{
yearcode=(+2);
}
else if(year<=1799 && year>=1700)
{
yearcode=(+4);
}
else
{
printf("ERROR.......\n");
}
if(year>=1700 && year<=3000)
{
switch(month)
{
case 1:
if(year%4==0 || year%400==0)
{
result= (day%7)+0+(year%100)+(yearcode)+(dividedyear);
}
else
{
result= (day%7)+1+(year%100)+(yearcode)+(dividedyear);
}
break;
case 2:
if(day<=28 || day<=29)
{
if(year%4==0 || year%400==0)
{
result=(day%7)+3+(year%100)+(yearcode)+dividedyear;
}
else
{
result=(day%7)+4+(year%100)+(yearcode)+dividedyear;
}
}
else
{
printf("ERROR........INVALID DATE\n\n");
}
break;
case 3:result=(day%7)+4+(year%100)+(yearcode)+dividedyear;
break;
case 4:result=(day%7)+0+(year%100)+(yearcode)+dividedyear;
break;
case 5:result=(day%7)+2+(year%100)+(yearcode)+dividedyear;
break;
case 6:result=(day%7)+5+(year%100)+(yearcode)+dividedyear;
break;
case 7:result=(day%7)+0+(year%100)+(yearcode)+dividedyear;
break;
case 8:result=(day%7)+3+(year%100)+(yearcode)+dividedyear;
break;
case 9:result=(day%7)+6+(year%100)+(yearcode)+dividedyear;
break;
case 10:result=(day%7)+1+(year%100)+(yearcode)+dividedyear;
break;
case 11:result=(day%7)+4+(year%100)+(yearcode)+dividedyear;
break;
case 12:result=(day%7)+6+(year%100)+(yearcode)+dividedyear;
break;
}
}
else
{
printf("Sorry out of range.\n\n");
}
if(result>=7)
{
Day=result%7;
}
else
{
Day=result;
}
switch(Day)
//switch statement start
{
case 1:printf("The day is Sunday.\n\n");
break;
case 2:printf("The day is Monday.\n\n");
break;
case 3:printf("The day is Tuesday.\n\n");
break;
case 4:printf("The day is Wednesday.\n\n");
break;
case 5:printf("The day is Thursday.\n\n");
break;
case 6:printf("The day is Friday.\n\n");
break;
case 0:printf("The day is Saturday.\n\n");
break;
case -1:printf(" ");
break;
//switch statement close
}
//if statement close
}
else
{
printf("ERROR.....\n\n");
}
getch();
system("cls");
//loop close
}
while(year!=0);
//main close
return 0;
}
This question is so imp so i will try to do this
ReplyDeleteThis comment has been removed by the author.
ReplyDelete