Apply for Zend Framework Certification Training

c



< How to print in c in different ways Last >



1. Adding Two Numbers
#include <stdio.h>
void main(){
    int a,b,c;
    printf("Enter First number :");
    scanf("%d",&a);
    printf("Enter Second number :");
    scanf("%d",&b);
    c = a + b;
    printf("The sum of two Numbers is : %d ",c);
}
Sample Output
Enter First number :10
Enter Second number :20
The sum of two Numbers is : 30

2. Input a Character
#include <stdio.h>
int main(){
    char grade;
    printf("Enter Student Grade :");
    scanf("%c",&grade);
    printf("Grade of the student is %c ",grade);
    return 0;
}
Sample Output
Enter Student Grade :A
Grade of the student is A

3. Input a Sentence
Your program is:
#include <stdio.h>
int main(){
    char myself[100];
    printf("Enter a sentence :");
    scanf("%[^\n]",myself);
    printf("About myself : %s\n",myself);
    return 0;
}

Sample Output
Enter a sentence :My name is Rajesh Kumar Mandal
About myself : My name is Rajesh Kumar Mandal
What does %[^\n] mean?
This is a scanset.
%[^\n]
means:
Read characters until a newline (\n) is encountered.
can store up to 99 characters of text, followed by '\0'.

4. Input and Display Array Elements
#include <stdio.h>
int main(){
    int arr[5];
    int i;
    printf("Enter 5 elements of an array : \n");
    for(i=0;i<5;i++){
        printf("Enter %d element :",i+1);
        scanf("%d",&arr[i]);
    }
    printf("Entered elements of an array is : \n");
    for(i=0;i<5;i++){
        printf("Value of %d elements is %d \n",i+1,arr[i]);
    }
}
Sample Output
Enter 5 elements of an array :
Enter 1 element :10
Enter 2 element :20
Enter 3 element :30
Enter 4 element :40
Enter 5 element :50

Entered elements of an array is :
Value of 1 elements is 10
Value of 2 elements is 20
Value of 3 elements is 30
Value of 4 elements is 40
Value of 5 elements is 50

< How to print in c in different ways Last >



Ask a question



  • Question:
    {{questionlistdata.blog_question_description}}
    • Answer:
      {{answer.blog_answer_description  }}
    Replay to Question


Back to Top