diff --git a/README.md b/README.md index 49ef854c..c01ca966 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,36 @@ # C-basicprograms -This repo contains basics programs in c programming language +## This repo contains basics programs in c programming language. +| Program No.| Question | +| ------- | ------ | +| Program-01 | Program to print pattern | +| Program-02 | Program to check whether the given number is prime or not | +| Program-03 | Program to find largest of three number using simple if condition | +| Program-04 | Program to find largest of three number using if-else condition | +| Program-05 | Program to find largest of three number using nested if condition | +| Program-06 | Program to find largest of three number using ternary operator | +| Program-07 | Program to check whether the given year is leap or not | +| Program-08 | Program to convert number into year, months and days | +| Program-09 | Program to check two number are equal without logical operator | +| Program-10 | Program to find square and half of given number without using built-in function and arithmetic operator| +| Program-11 | Program on arithmetic operators | +| Program-12 | Program on relational operators | +| Program-13 | Program on bit-wise operator. | +| Program-14 | Program on increment and decrement operator. | +| Program-15 | Program to find sum of digits between given range which are divisible by 3 | +| Program-16 | Program to check whether the given number is neon or not | +| Program-17 | Program to check whether the given number is prefect or not | +| Program-18 | Program to check given number is Armstrong or not | +| Program-19 | Program to find power of a given number | +| Program-20 | Program to convert datatype explicitly | +| Program-21 | Program to check whether the given number is prime or not | +| Program-22 | Program to find GCD and LCM of given two number | +| Program-23 | Program to find number of digits in a given number | +| Program-24 | Program to print the pattern | +| Program-25 | Program to print the pattern | +| Program-26 | Program to print the pattern | +| Program-27 | Program to print the pattern | +| Program-28 | Program to print the pattern | +| Program-29 | Program to print the pattern | +| Program-30 | Program to print the pattern | +| Program-31 | Program to take the details of student and print the details of students using array and to add details of new students into the existing array | +| Program-32 | Program to take the details of student and print the details | diff --git a/program-20/program.c b/program-20/program.c index bfe8670d..ed865cda 100644 --- a/program-20/program.c +++ b/program-20/program.c @@ -1,8 +1,20 @@ -#include -void main() -{ -if(printf("hello world\n")) -{ +#include +#include -} +int main() +{ int a=7,b=2; + // printf("enter two number !\n"); + //scanf("%d%d",&a,&b); + printf("%d",a/b); + + printf("%d\n",(float)a/b); + printf("%d\n",(float)a/(float)b); + printf("%d\n",a/(float)b); + + printf("%f\n",a/b); + printf("%f\n",(float)(a/b)); + printf("%f\n",(float) a/b); + printf("%f\n",(float)a/(float)b); + printf("%f\n",a/(float)b); + return 0; } diff --git a/program-31/a.out b/program-31/a.out new file mode 100755 index 00000000..22b5b248 Binary files /dev/null and b/program-31/a.out differ diff --git a/program-31/program.c b/program-31/program.c index f43964bc..43a5fffb 100644 --- a/program-31/program.c +++ b/program-31/program.c @@ -12,7 +12,7 @@ int main() scanf("%d",&n); for(i=1;i<=n;i++) { - printf("Enter the details of student-%d\n",i); + printf("Enter the details of student - %d\n",i); printf("Enter the name of the student\n"); scanf("%s",&stud[i].n); printf("Enter USN\n"); @@ -20,13 +20,13 @@ int main() printf("Enter total marks\n"); scanf("%d",&stud[i].m); } - printf("|\tSl.no\t|\tName\t|\tUSN\t\t|\tMark\t|\n"); + printf("|\tSl.no\t|\tName\t\t|\tUSN\t\t|\tMark\t|\n"); for(i=1;i<=n;i++) { - printf("|\t%d\t|\t%s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); + printf("|\t%d\t|\t%-10s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); } printf("Enter the details of new student\n"); - printf("Enter the name\n"); + printf("Enter the name\n"); //preferred to enter equal length of name scanf("%s",&stud2.n); printf("Enter the USN\n"); scanf("%s",&stud2.u); @@ -40,10 +40,10 @@ int main() stud[i+1]=stud[i]; } stud[p]=stud2; - printf("|\tSl.no\t|\tName\t|\tUSN\t\t |\tMark\t|\n"); + printf("|\tSl.no\t|\tName\t\t|\tUSN\t\t |\tMark\t|\n"); for(i=1;i<=n+1;i++) { - printf("|\t%d\t|\t%s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); + printf("|\t%d\t|\t%-10s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); } diff --git a/program-32/program.c b/program-32/program.c new file mode 100644 index 00000000..26b3f3e9 --- /dev/null +++ b/program-32/program.c @@ -0,0 +1,29 @@ +#include +struct student +{ +char n[100]; +char u[100]; +int m; +}stud[10],stud2; +int main() +{ + int n,i,p=0; + printf("Enter the number of student\n"); + scanf("%d",&n); + for(i=1;i<=n;i++) + { + printf("Enter the details of student - %d\n",i); + printf("Enter the name of the student\n"); + scanf("%s",&stud[i].n); + printf("Enter USN\n"); + scanf("%s",&stud[i].u); + printf("Enter total marks\n"); + scanf("%d",&stud[i].m); + } + printf("|\tSl.no\t|\tName\t\t|\tUSN\t\t|\tMark\t|\n"); + for(i=1;i<=n;i++) + { + printf("|\t%d\t|\t%-10s\t|\t%s\t|\t%d\t|\n",i,stud[i].n,stud[i].u,stud[i].m); + } + return 0; +}