Sie sind auf Seite 1von 30

/*

Name : Shrish Kumar


Roll No. : 13
Section : F
Problem Statement
Write a program to input an alphabet and convert it's case
*/
#include <stdio.h>
void main()
{
char c;
printf("Enter Character : ");
scanf("%c",&c);
printf("\n");
if(c>=97)
{

c=c-32;

}
else
{
c=c+32;
}
printf("New Character : %c",c);
}
INPUT
Enter Character : p

OUTPUT
New Character : P
Process returned 17 (0x11) execution time :
4.577 s
Press any key to continue.
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to print the minimum of three numbers

*/

#include <stdio.h>

void main()

int a,b,c;

printf("\t INPUT \n");

printf("Enter first number :");

scanf("%d",&a);

printf("Enter second number :");

scanf("%d",&b);

printf("Enter third number :");

scanf("%d",&c);

printf("\t OUTPUT \n");

if(a<b && a<c)

printf("Minimum among %d,%d,%d is : %d",a,b,c,a);

else if(b<a && b<c)

printf("Minimum among %d,%d,%d is : %d",a,b,c,b);

else

printf("Minimum among %d,%d,%d is : %d",a,b,c,c);

}
/*
INPUT
Enter first number :1580
Enter second number :3082
Enter third number :2497
OUTPUT
Minimum among 1580,3082,2497 is : 1580
Process returned 38 (0x26) execution time :
13.381 s
Press any key to continue.

*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to display grades of a student

*/

# include<stdio.h>

void main()

int m;

printf("\t INPUT \n");

printf("Enter marks of student :");

scanf("%d",&m);

printf("\t OUTPUT \n");

if(m>80)

printf("Grade : A");

else if(m>61 && m<=80)

printf("Grade : B");

else if(m>51 && m<=60)

printf("Grade : C");

else if(m>41 && m<=50)

printf("Grade : D");

else if(m>35 && m<=40)

printf("Grade : E");

else

printf("Grade : F");}}
/*
INPUT
Enter marks of student :60
OUTPUT
Grade : C
Process returned 9 (0x9) execution time : 6.143 s
Press any key to continue.

*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to design a calculator to perform basic arithmetic

/#include <stdio.h>

void main() { int a,b,c,d;

printf("\t INPUT \n");

printf("Enter first number : ");

scanf("%d",&a);

printf("Enter second number : ");

scanf("%d",&b);

printf("Press :\n");

printf("1 for modulus\n");

printf("2 for division\n");

printf("3 for multiplication\n");

printf("4 for addition\n");

printf("5 for subtraction\n");

scanf("%d",&c);

printf("\t OUTPUT \n");

switch(c) { case 1 :

d = a%b;

printf("Modulus of %d and %d gives : %d ",a,b,d);

break; case 2 :

d = a/b;

printf("Division of %d and %d gives : %d ",a,b,d);

break; case 3 :

d = a*b;

printf("Multiplication of %d and %d gives : %d ",a,b,d);

break; case 4 :

d= a+b;

printf("Addition of %d and %d gives : %d ",a,b,d);

break; case 5 :

d = a-b;

printf("Subtraction of %d and %d gives : %d ",a,b,d);

break; default : printf("Wrong Input"); } }


/*
INPUT
Enter first number : 76
Enter second number : 31
Press :
1 for modulus
2 for division
3 for multiplication
4 for addition
5 for subtraction
4
OUTPUT
Addition of 76 and 31 gives : 107
Process returned 34 (0x22) execution time :
23.710 s
Press any key to continue.

*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to display a pattern

*/#include <stdio.h>

void main()

int n;

printf("\t INPUT \n");

printf("Enter value of n :");

scanf("%d",&n);

printf("\t OUTPUT \n\n");

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

for(int j=1;j<=n-i;j++)

printf(" ");

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

printf("%d",k);

for(int l=i-1;l>=1;l--)

printf("%d",l);

printf("\n");

}
/*
INPUT
Enter value of n :5
OUTPUT

1
121
12321
1234321
123454321

Process returned 5 (0x5) execution time :


2.462 s
Press any key to continue.

*/
/*
Name : Shrish Kumar
Roll No. : 13
Section : F
Problem Statement
Write a program to display reverse and number of digits of a number
*/#include <stdio.h>
void main()
{
int n,rev=0,sum=0,c=0;
printf("\t INPUT \n");
printf("Enter number :");
scanf("%d",&n);
while(n!=0)
{
int l = n%10;
rev = (rev*10)+l;
n=n/10;
c++;
}
printf("\t OUTPUT \n");
printf("Reverse of the number : %d\n",rev);
printf("Number of digits : %d",c);
}
/*
INPUT
Enter number :13542
OUTPUT
Reverse of the number : 24531
Number of digits : 5
Process returned 20 (0x14) execution time :
6.902 s
Press any key to continue.

*/
/*
Name : Shrish Kumar
Roll No. : 13
Section : F
Problem Statement
Write a program to print fibonacci series upto n terms
*/#include <stdio.h>
void main()
{
int n;
printf("\t INPUT \n");
printf("Enter limit : ");
scanf("%d",&n);
printf("\t OUTPUT \n");
printf("0,1");
int a=0,b=1;
for(int i=3;i<=n;i++)
{
int c = a+b;
printf(",%d",c);
a=b;
b=c;
}
}
/*
INPUT
Enter limit : 10
OUTPUT
0,1,1,2,3,5,8,13,21,34
Process returned 10 (0xA) execution time :
7.380 s
Press any key to continue.
*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to print whether inputted number is prime or not

*/# include<stdio.h>

void main()

int n,c=0;

printf("\t INPUT \n");

printf("Enter number : ");

scanf("%d",&n);

for(int i=1;i<=n/2;i++)

if(n%i==0)

c++;

printf("\t OUTPUT \n");

if(c==1)

printf(" YES ");

else

printf("NO");

}
/*
INPUT
Enter number : 23
OUTPUT
YES
Process returned 5 (0x5) execution time : 4.929 s
Press any key to continue.

*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to add two 1-D arrays of different sizes

*/

#include<stdio.h>

void main()

{ int a,b;

printf("\t Input \n");

printf("Enter array 1 size : ");

scanf("%d",&a);

printf("Enter array 2 size : ");

scanf("%d",&b);

int arr[a],brr[b];

for(int i=0;i<a;i++)

{ printf("Enter array 1 elements :"); scanf("%d",&arr[i]); }

for(int i=0;i<b;i++)

{ printf("Enter array 2 element :");

scanf("%d",&brr[i]); }

printf("\t Output \n");

if(a>b) { int crr[a];

for(int i=0;i<b;i++)

{ crr[i]=arr[i]+brr[i]; }

for(int i=b;i<=a;i++)

{ crr[i]=arr[i]; }

printf("Final array :\n");

for(int i=0;i<a;i++)

{ printf("%d\n",crr[i]); } }

else { int crr[b];

for(int i=0;i<a;i++)

{ crr[i]=arr[i]+brr[i]; }

for(int i=a;i<=b;i++)

{ crr[i]=brr[i]; }

printf("Final array :\n");

for(int i=0;i<b;i++)

{ printf("%d ",crr[i]); }}
/*
Input
Enter array 1 size : 5
Enter array 2 size : 8
Enter array 1 elements :1
Enter array 1 elements :2
Enter array 1 elements :3
Enter array 1 elements :4
Enter array 1 elements :5
Enter array 2 element :1
Enter array 2 element :3
Enter array 2 element :5
Enter array 2 element :7
Enter array 2 element :9
Enter array 2 element :4
Enter array 2 element :6
Enter array 2 element :2
Output
Final array :
2 5 8 11 14 4 6 2
Process returned 8 (0x8) execution time : 21.789 s
Press any key to continue.

*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to check frequency of a number in an array

*/#include <stdio.h>

void main()

int k,n,c=0;

printf("\t INPUT \n");

printf("Enter element to be found :");

scanf("%d",&k);

printf("Enter limit of array :");

scanf("%d",&n);

int A[n];

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

printf("Enter array element : ");

scanf("%d",&A[i]);

if(A[i]==k)

c++;

printf("\t OUTPUT \n");

if(c>0)

printf("Yes , number exists in array \n");

printf("Frequency of %d is : %d ",k,c);

else

printf("No , number does not exist in array ");

}
/*
INPUT
Enter element to be found :2
Enter limit of array :10
Enter array element : 9
Enter array element : 2
Enter array element : 3
Enter array element : 2
Enter array element : 4
Enter array element : 5
Enter array element : 2
Enter array element : 6
Enter array element : 2
Enter array element : 7
OUTPUT
Yes , number exists in array
Frequency of 2 is : 4
Process returned 22 (0x16) execution time : 26.729 s
Press any key to continue.

*/
/*
Name : Shrish Kumar
Roll No. : 13
Section : F
Problem Statement
Write a program to calculate nCr for a number
*/#include<stdio.h>
int n,c;
int f;
int fact(int x)
{
f=1;
for(int i=1;i<=x;i++)
{
f=f*i;
}
return f;
}
void main()
{
printf("\t INPUT \n");
printf("Enter n :");
scanf("%d",&n);
printf("Enter r :");
scanf("%d",&c);
printf("\t OUTPUT \n");
double result = fact(n)/(fact(c)*fact(n-c));
printf("Result : %f",result);
}
/*
INPUT
Enter n :4
Enter r :3
OUTPUT
Result : 4.000000
Process returned 17 (0x11) execution time :
5.888 s
Press any key to continue.

*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to display sum of elements of an array

*/

#include <stdio.h>

int sum,n;

int sumo(int x)

sum = 0;

while(x!=0)

int l=x%10;

sum = sum+l;

x=x/10;

return sum;

void main()

printf("\t INPUT \n");

printf("Enter size of array :");

scanf("%d",&n);

int a[n];

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

printf("Enter array elements :");

scanf("%d",&a[i]);

printf("\t OUTPUT \n");

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

int y = sumo(a[i]);

printf("%d ",y);

}
/*
INPUT
Enter size of array :10
Enter array elements :19
Enter array elements :22
Enter array elements :32
Enter array elements :43
Enter array elements :554
Enter array elements :65
Enter array elements :728
Enter array elements :768
Enter array elements :62
Enter array elements :7
OUTPUT
10 4 5 7 14 11 17 21 8 7
Process returned 10 (0xA) execution time :
20.400 s
Press any key to continue.
*/
#include <stdio.h>
void main()
{
int n;
printf("\t INPUT \n");
printf("Enter number of rows or columns :");
scanf("%d",&n);
int a[n][n];
for(int i=0;i<n;i++)
{
for(int j=0;j<n;j++)
{
printf("Enter array element : ");
scanf("%d",&a[i][j]);
}
}
printf("\t OUTPUT \n");
for(int i=0;i<n;i++)
{
int k=n-i-1;
printf("%d ",a[i][k]);
}
}
/*
INPUT
Enter number of rows or columns :3
Enter array element : 2
Enter array element : 2
Enter array element : 4
Enter array element : 1
Enter array element : 2
Enter array element : 5
Enter array element : 3
Enter array element : 4
Enter array element : 6
OUTPUT
423
Process returned 3 (0x3) execution time : 15.120 s
Press any key to continue.

*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to calculate sum of series using recursion

*/

#include <stdio.h>

int n,sums;

int sum(int y)

if(y==1)

return 1;

else

return (pow(n,2)+sum(n--));

void main()

printf("\t INPUT \n");

printf("Enter number :");

scanf("%d",&n);

int x = sum(n)-1;

printf("\t OUTPUT \n");

printf("%d",x);

}
/*
INPUT
Enter number :4
OUTPUT
30
Process returned 2 (0x2) execution time :
0.905 s
Press any key to continue.
*/
/*

Name : Shrish Kumar

Roll No. : 13

Section : F

Problem Statement

Write a program to print multiply two matrices

*/

#include <stdio.h>

int main()

{ int m, n, p, q, c, d, k, sum = 0;

int first[10][10], second[10][10], multiply[10][10];

printf("\t INPUT \n");

printf("Enter number of rows and columns of first matrix\n");

scanf("%d%d", &m, &n);

printf("Enter elements of first matrix\n");

for (c = 0; c < m; c++)

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

scanf("%d", &first[c][d]);

printf("Enter number of rows and columns of second matrix\n");

scanf("%d%d", &p, &q);

if (n != p)

printf("The matrices can't be multiplied with each other.\n");

else

{ printf("Enter elements of second matrix\n");

for (c = 0; c < p; c++)

for (d = 0; d < q; d++)

scanf("%d", &second[c][d]);

for (c = 0; c < m; c++) {

for (d = 0; d < q; d++) {

for (k = 0; k < p; k++) {

sum = sum + first[c][k]*second[k][d]; }

multiply[c][d] = sum; sum = 0; } }

printf("\t OUTPUT \n");

printf("Product of the matrices:\n");

for (c = 0; c < m; c++) {

for (d = 0; d < q; d++)

printf("%d\t", multiply[c][d]);

printf("\n"); } } return 0; }
/*

INPUT

Enter number of rows and columns of first matrix

Enter elements of first matrix

Enter number of rows and columns of second matrix

Enter elements of second matrix

OUTPUT

Product of the matrices:

19 22

43 50

Process returned 0 (0x0) execution time : 26.875 s

Press any key to continue.

*/

Das könnte Ihnen auch gefallen