245 subscribers
6 photos
3 files
4 links
This group will help beginners to learn programming in C language.

Discussion: @c_coding_discussion
Download Telegram
|Quiz. #5| what is the output?
#include <stdio.h>
int main() { int a=0*10+0110+10; printf("%d",a); return 0; }
Final Results
8%
130
54%
120
19%
82
19%
Error!
#Explanation |Quiz. #5|
The correct option is 82 because when a number starts from 0, it is considered as octal number, the octal value of 0110 is 82 ((0*8^3 + 1*8^2 + 1*8^1 + 0*8^0) + 10).
#pattern's
47. C program to print this pattern :-
* *
* *
*
* *
* *
* *
* *
*
* *
* *
* *
* *
*
* *
* *
* *
* *
*
* *
* *
* *
* *
*
* *
* *
______
#include <stdio.h>

int main()
{
for(int k=1; k<=5; k++){
for(int i=1; i<=5; i++){
for(int j=1; j<=5; j++){
if(j>=6-i && j<=6-i || i*i == j*j){
printf("*");

}
else{
printf(" ");
}
}
printf("\n");
}

}
return 0;
}
48. C program to sum of entered digit's (using recursion).
#include <stdio.h>

int sum(int n){
int s;
if(n <= 0){
return 0;
}
else{
return n%10 + sum(n/10);
}
}
int main()
{
printf("Enter some numbers in sequence: ");
int n;
scanf("%d", &n);
int res = sum(n);
printf("sum of these all numbers is: %d ", res);
return 0;
}
C Coding pinned «Here you will get codes of DSUS (DSA) and all basic to advanced code of C language #notice: Do not copy paste these codes try to understand the concept of the code. #If you have any query or doubt in c programming you can ask me directly. Thanks to all…»
#DSA_Series
49. C Program to insert an element in array on the given index.
#include <stdio.h>

void display(int *arr, int size){
for(int i=0; i<=size; i++){
printf("%d ", arr[i]);
}
printf("\n");
}
int insert_arr(int *arr, int val, int size, int capacity, int ind){
if(size>capacity){
printf("Overflow!");
return -1;
}
else{
for(int i=size; i>=ind-1; i--){
arr[i+1] = arr[i];
}
arr[ind] = val;
return 1;
}
}

int main()
{
int arr[100] = {1,2,6,7};
int size = 4, element = 9, index = 1;
printf("Before insertion\n");
display(arr, size);
insert_arr(arr,234, size, 100, index);
size += 1;
printf("After insertion\n");
display(arr, size);

return 0;
}
|Quiz. #6| |Basic|
what is the output of this code?
#include<stdio.h> int main() { int var=5; int *ptr =&var; printf("%d",*ptr++); }
Final Results
25%
Address of var
13%
6
25%
5
38%
Error!
# Explanation |Quiz. #6|
Here ,ptr is a pointer,and it'll take the address of variable var i.e it'll store 5, then in printf statement, the value will be print first and then would be increment, so the correct answer is 5.
#DSA_Series
50. C program to delete an element in array from a given index.

#include <stdio.h>

void display(int *arr, int size){
for(int i=0; i<=size; i++){
printf("%d ", arr[i]);
}
printf("\n");
}
int delInd_arr(int *arr,int size, int ind){
if(size==-1){
printf("Underflow!");
return -1;
}
else{
for(int i=ind; i<=size; i++){
arr[i] = arr[i+1];
}
return 1;
}
}

int main()
{
int arr[100] = {11,22,65,72};
int size = 3, index = 1;
printf("Before deletion\n");
display(arr, size);
delInd_arr(arr,size, index);
size -= 1;
printf("After deletion\n");
display(arr, size);
return 0;
}
51. C program to swap three integers
#include<stdio.h>

int main()
{
int a,b,c;
int temp1, temp2;
scanf("%d %d %d",&a,&b,&c);
temp1=a;
a=b;
b=temp1;
temp2=a;
a=c;
c=temp2;
printf("%d %d %d",a,b,c);
return 0;
}
53. C program to swap three interes without using external variable.
#include<stdio.h>

int main()
{
int a,b,c;
scanf("%d %d %d",&a,&b,&c);
a=a+b;
b=a-b;
a=a-b;

a=a+c;
c=a-c;
a=a-c;
printf("%d %d %d",a,b,c);
return 0;
}
54. C program to find sum of first five prime numbers.
#include <stdio.h>
int isprime(int j){
int p=0;
for(int i = 2 ; i <= j/2; i++){
if(j%i == 0){
p = 1;
}
}
if(p == 0){
return 1;
}
else
return 0;
}
int main(void) {
int num = 1;
int i=0, j= 1;
int sum = 0;
while(num<=5){
j++;
if(isprime(j)){
sum += j;
num++;
}
}
printf("sum =%d",sum);
return 0;
}
|Quiz. #7|
What will be the output?
Anonymous Quiz
12%
5
43%
7
27%
1
18%
Error!
Do you want another group for doubts or queries about these programs and C language?
Anonymous Poll
87%
Yes
13%
No
55. C program to print Fibonacci series of n terms.
#include <stdio.h>

int main(){
int n,n1=0,n3,n2=1;
scanf("%d",&n);
for(int k=0; k<n; k++){
if(k<=1)
n3=k;
else{
n3=n1+n2;
n1=n2;
n2=n3;
}
printf("%d ",n3);
}
return 0;
}
56. C program to find the term of Fibonacci series on a given index.
#include <stdio.h>
//0 1 1 2 3 5 8 13......n
int fib(int n){
if(n==1 || n==0)
{
return 1;
}
else{
return fib(n-2) + fib(n-1);
}
}

int main(){
int n, fTerm;
scanf("%d",&n);

fTerm=fib(n-1);
printf("%d",fTerm);
return 0;
}
57. C program to check whether a character is a Vowel / Constant / Number / Spacial symbol / space of a given string.
#include<stdio.h>
#include<string.h>
int main()
{
char s[200];
int len;
printf("enter a string: ");
scanf("%[^\n]%*c",&s);
len=strlen(s);

for(int p=0; p< len; p++)
{
if(s[p]==97 s[p]==101 s[p]==105 s[p]==111 s[p]==117)
{
printf("%c is a vowel\n",s[p]);
continue;
}

else if(s[p]==' '){
printf("space\n");
}
else if(s[p] >= 48 && s[p] <= 57)
{
printf("%c is a number\n", s[p]);
}
else if((s[p]>=33 && s[p]<= 47) (s[p]>= 58 && s[p]<= 64) (s[p]>= 91 && s[p]<= 96) || (s[p] >= 123 && s[p] <= 126))
{
printf("%c is a special symbol\n",s[p]);
}
else{
printf("%c is a constent\n",s[p]);
}
}
return 0;
}
58. C program to print sparse matrix of a given matrix.

#include<stdio.h>

int main()
{
int a[10][10],spmt[10][3],m,n,temp=0,i,j;
printf("Enter the range of matix: ");
scanf("%d%d",&n,&m);
printf("enter the elements of the matrix:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
scanf("%d",&a[i][j]);
}
}
printf("your matrix matrix is:\n");
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
printf("%d ",a[i][j]);
}
printf("\n");
}
for(i=0;i<n;i++)
{
for(j=0;j<m;j++)
{
if(a[i][j]!=0)
{
spmt[temp][0]=a[i][j];
spmt[temp][1]=i;
spmt[temp][2]=j;
temp++;
}
}
}
printf("\nThe sparse matrix:\n");
for(i=0;i<temp;i++)
{
for(j=0;j<3;j++)
{
printf("%d ",spmt[i][j]);
}
printf("\n");
}
return 0;
}